Skip to content

Commit

Permalink
Add support for signalFxRealm field (open-telemetry#498)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Collins authored Jun 22, 2021
1 parent 567a748 commit 1571616
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
15 changes: 12 additions & 3 deletions cmd/translatesfx/translatesfx/otel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,20 @@ func testvSphereMonitorCfg() map[interface{}]interface{} {
}

func TestAPIURLToRealm(t *testing.T) {
us1, _ := apiURLToRealm("https://api.us1.signalfx.com")
us0, _ := apiURLToRealm(map[interface{}]interface{}{
"apiUrl": "https://api.signalfx.com",
})
assert.Equal(t, "us0", us0)

us1, _ := apiURLToRealm(map[interface{}]interface{}{
"apiUrl": "https://api.us1.signalfx.com",
})
assert.Equal(t, "us1", us1)

us0, _ := apiURLToRealm("https://api.signalfx.com")
assert.Equal(t, "us0", us0)
us2, _ := apiURLToRealm(map[interface{}]interface{}{
"signalFxRealm": "us2",
})
assert.Equal(t, "us2", us2)
}

func TestMTOperations(t *testing.T) {
Expand Down
4 changes: 1 addition & 3 deletions cmd/translatesfx/translatesfx/testdata/sa-simple.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
---
signalFxAccessToken: "abc123"
ingestUrl: "https://ingest.lab0.signalfx.com"
apiUrl: "https://api.signalfx.com"
traceEndpointUrl: "https://ingest.signalfx.com/v2/trace"
signalFxRealm: us1

intervalSeconds: 10

Expand Down
18 changes: 16 additions & 2 deletions cmd/translatesfx/translatesfx/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type saCfgInfo struct {
}

func saExpandedToCfgInfo(saExpanded map[interface{}]interface{}) (saCfgInfo, error) {
realm, err := apiURLToRealm(saExpanded["apiUrl"].(string))
realm, err := apiURLToRealm(saExpanded)
if err != nil {
return saCfgInfo{}, err
}
Expand All @@ -42,7 +42,21 @@ func saExpandedToCfgInfo(saExpanded map[interface{}]interface{}) (saCfgInfo, err
}, nil
}

func apiURLToRealm(apiURL string) (string, error) {
func apiURLToRealm(saExpanded map[interface{}]interface{}) (string, error) {
if v, ok := saExpanded["signalFxRealm"]; ok {
if realm, ok := v.(string); ok {
return realm, nil
}
return "", fmt.Errorf("unexpected signalFxRealm type: %v", v)
}
v, ok := saExpanded["apiUrl"]
if !ok {
return "", fmt.Errorf("unable to get realm from SA config %v", saExpanded)
}
apiURL, ok := v.(string)
if !ok {
return "", fmt.Errorf("unexpected apiURL type: %v", v)
}
u, err := url.Parse(apiURL)
if err != nil {
return "", fmt.Errorf("failed to parse apiURL %v: %v", apiURL, err)
Expand Down

0 comments on commit 1571616

Please sign in to comment.