Skip to content

Commit

Permalink
refine sigv4
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Lewin <[email protected]>
  • Loading branch information
lewinkedrs committed Jan 23, 2023
1 parent b183d17 commit 34f5875
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/client_model v0.3.0
github.com/prometheus/common v0.39.0
github.com/prometheus/common/sigv4 v0.1.0
github.com/servicemeshinterface/smi-sdk-go v0.5.0
github.com/sirupsen/logrus v1.9.0
github.com/soheilhy/cmux v0.1.5
Expand Down Expand Up @@ -142,7 +143,6 @@ require (
github.com/opsgenie/opsgenie-go-sdk-v2 v1.2.13 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/common/sigv4 v0.1.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/russross/blackfriday v1.6.0 // indirect
github.com/slack-go/slack v0.11.0 // indirect
Expand Down
27 changes: 15 additions & 12 deletions metricproviders/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
"fmt"
"net/http"
"net/url"
"strings"
"os"
"strings"
"time"

"github.com/prometheus/client_golang/api"
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"
log "github.com/sirupsen/logrus"
"github.com/prometheus/common/sigv4"
log "github.com/sirupsen/logrus"

"github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1"
"github.com/argoproj/argo-rollouts/utils/evaluate"
Expand Down Expand Up @@ -168,10 +168,10 @@ func NewPrometheusAPI(metric v1alpha1.Metric) (v1.API, error) {

//Check if using Amazon Managed Prometheus if true build sigv4 client
promUrl := metric.Provider.Prometheus.Address
amznUrlSubstring := "aps-workspaces"
amznUrlSubstring := "aps-workspaces.region.amazonaws.com"

if strings.Contains(promUrl, amznUrlSubstring) {
client, err := CreateSigV4Client(promUrl)
client, err := createSigV4Client(promUrl)
if err != nil {
log.Errorf("Error in getting prometheus client: %v", err)
return nil, err
Expand All @@ -189,7 +189,7 @@ func NewPrometheusAPI(metric v1alpha1.Metric) (v1.API, error) {
}
}

func IsUrl (str string) bool {
func IsUrl(str string) bool {
u, err := url.Parse(str)
if err != nil {
log.Errorf("Error in parsing url: %v", err)
Expand All @@ -198,13 +198,16 @@ func IsUrl (str string) bool {
return err == nil && u.Scheme != "" && u.Host != ""
}

//Create a new sigv4Client that uses GO default provider chain
func CreateSigV4Client (address string) (api.Client, error) {
var cfg *sigv4.SigV4Config
var next http.RoundTripper
sigv4RoundTripper, err := sigv4.NewSigV4RoundTripper(cfg,next)
client, err := api.NewClient(api.Config{
Address: address,
// Create a new sigv4Client that uses GO default provider chain
func createSigV4Client(address string) (api.Client, error) {
var cfg *sigv4.SigV4Config
var next http.RoundTripper
sigv4RoundTripper, err := sigv4.NewSigV4RoundTripper(cfg, next)
if err != nil {
log.Errorf("Error creating SigV4RoundTripper: %v", err)
}
client, err := api.NewClient(api.Config{
Address: address,
RoundTripper: sigv4RoundTripper,
})
return client, err
Expand Down

0 comments on commit 34f5875

Please sign in to comment.