Skip to content

Commit

Permalink
Merge pull request #57 from PureStorage-OpenConnect/extend-uagent
Browse files Browse the repository at this point in the history
Extend user-agent string
  • Loading branch information
sdodsley authored Mar 8, 2024
2 parents 4a03164 + 70121a0 commit ef2acad
Show file tree
Hide file tree
Showing 25 changed files with 36 additions and 35 deletions.
3 changes: 2 additions & 1 deletion cmd/fb-om-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ func metricsHandler(w http.ResponseWriter, r *http.Request) {
return
}

uagent := r.Header.Get("User-Agent")
registry := prometheus.NewRegistry()
fbclient := client.NewRestClient(address, apitoken, apiver, debug)
fbclient := client.NewRestClient(address, apitoken, apiver, uagent, debug)
if fbclient.Error != nil {
http.Error(w, "Error connecting to FlashBlade. Check your management endpoint and/or api token are correct.", http.StatusBadRequest)
return
Expand Down
2 changes: 1 addition & 1 deletion internal/openmetrics-exporter/alerts_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestAlertsCollector(t *testing.T) {
alert := strings.Split(a, "\n")
want[fmt.Sprintf("label:{name:\"action\" value:\"%s\"} label:{name:\"code\" value:\"%s\"} label:{name:\"component_name\" value:\"%s\"} label:{name:\"component_type\" value:\"%s\"} label:{name:\"created\" value:\"%s\"} label:{name:\"kburl\" value:\"%s\"} label:{name:\"severity\" value:\"%s\"} label:{name:\"summary\" value:\"%s\"} gauge:{value:%g}", alert[0], alert[1], alert[2], alert[3], alert[4], alert[5], alert[6], alert[7], n)] = true
}
c := client.NewRestClient(e, "fake-api-token", "latest", false)
c := client.NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
ac := NewAlertsCollector(c)
metricsCheck(t, ac, want)
server.Close()
Expand Down
2 changes: 1 addition & 1 deletion internal/openmetrics-exporter/arrays_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestArraysCollector(t *testing.T) {
endp := strings.Split(server.URL, "/")
e := endp[len(endp)-1]
want := make(map[string]bool)
c := client.NewRestClient(e, "fake-api-token", "latest", false)
c := client.NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
for _, a := range arrs.Items {
want[fmt.Sprintf("label:{name:\"array_name\" value:\"%s\"} label:{name:\"os\" value:\"%s\"} label:{name:\"system_id\" value:\"%s\"} label:{name:\"version\" value:\"%s\"} gauge:{value:1}", a.Name, a.Os, a.Id, a.Version)] = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestArraysHttpPerfCollector(t *testing.T) {
endp := strings.Split(server.URL, "/")
e := endp[len(endp)-1]
want := make(map[string]bool)
c := client.NewRestClient(e, "fake-api-token", "latest", false)
c := client.NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
for _, p := range arrs.Items {
want[fmt.Sprintf("label:{name:\"dimension\" value:\"others_per_sec\"} gauge:{value:%g}", p.OthersPerSec)] = true
want[fmt.Sprintf("label:{name:\"dimension\" value:\"read_dirs_per_sec\"} gauge:{value:%g}", p.ReadDirsPerSec)] = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestArraysNfsPerfCollector(t *testing.T) {
endp := strings.Split(server.URL, "/")
e := endp[len(endp)-1]
want := make(map[string]bool)
c := client.NewRestClient(e, "fake-api-token", "latest", false)
c := client.NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
for _, p := range arrs.Items {
want[fmt.Sprintf("label:{name:\"dimension\" value:\"fsinfos_per_sec\"} gauge:{value:%g}", p.FsinfosPerSec)] = true
want[fmt.Sprintf("label:{name:\"dimension\" value:\"fsstats_per_sec\"} gauge:{value:%g}", p.FsstatsPerSec)] = true
Expand Down
4 changes: 2 additions & 2 deletions internal/rest-client/alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ func TestAlerts(t *testing.T) {
endp := strings.Split(server.URL, "/")
e := endp[len(endp)-1]
t.Run("alerts_open", func(t *testing.T) {
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
al := c.GetAlerts("state='open'")
if diff := cmp.Diff(al.Items, aopen.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
server.Close()
}
})
t.Run("alerts_all", func(t *testing.T) {
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
al := c.GetAlerts("")
if diff := cmp.Diff(al.Items, aall.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/arrays_http_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestArraysHttpPerformance(t *testing.T) {
e := endp[len(endp)-1]
t.Run("arrays_http_performance_1", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
ahpl := c.GetArraysHttpPerformance()
if diff := cmp.Diff(ahpl.Items[0], arrhp.Items[0]); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/arrays_nfs_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestArraysNfsPerformance(t *testing.T) {
e := endp[len(endp)-1]
t.Run("arrays_http_performance_1", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
apl := c.GetArraysNfsPerformance()
if diff := cmp.Diff(apl.Items[0], arrsp.Items[0]); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/arrays_perf_replication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestArraysPerformanceReplication(t *testing.T) {
e := endp[len(endp)-1]
t.Run("array_performance_replication_1", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
aprl := c.GetArraysPerformanceReplication()
if diff := cmp.Diff(aprl.Items, arrpr.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down
10 changes: 5 additions & 5 deletions internal/rest-client/arrays_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,39 +71,39 @@ func TestArraysPerformance(t *testing.T) {
endp := strings.Split(server.URL, "/")
e := endp[len(endp)-1]
t.Run("array_perf_all", func(t *testing.T) {
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
pl := c.GetArraysPerformance("all")
if diff := cmp.Diff(pl.Items, aall.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
server.Close()
}
})
t.Run("array_perf_http", func(t *testing.T) {
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
pl := c.GetArraysPerformance("HTTP")
if diff := cmp.Diff(pl.Items, ahttp.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
server.Close()
}
})
t.Run("array_perf_nfs", func(t *testing.T) {
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
pl := c.GetArraysPerformance("NFS")
if diff := cmp.Diff(pl.Items, anfs.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
server.Close()
}
})
t.Run("array_perf_smb", func(t *testing.T) {
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
pl := c.GetArraysPerformance("SMB")
if diff := cmp.Diff(pl.Items, asmb.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
server.Close()
}
})
t.Run("array_perf_s3", func(t *testing.T) {
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
pl := c.GetArraysPerformance("S3")
if diff := cmp.Diff(pl.Items, as3.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/arrays_s3_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestArraysS3Performance(t *testing.T) {
e := endp[len(endp)-1]
t.Run("array_s3_specific_1", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
pl := c.GetArraysS3Performance()
if diff := cmp.Diff(pl.Items, as3.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down
6 changes: 3 additions & 3 deletions internal/rest-client/arrays_space_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ func TestArraysSpace(t *testing.T) {
endp := strings.Split(server.URL, "/")
e := endp[len(endp)-1]
t.Run("arrays_space_1", func(t *testing.T) {
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
asl := c.GetArraysSpace("array")
if diff := cmp.Diff(asl.Items, arrsa.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
server.Close()
}
})
t.Run("arrays_space_2", func(t *testing.T) {
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
asfs := c.GetArraysSpace("file-system")
if diff := cmp.Diff(asfs.Items, arrsfs.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
server.Close()
}
})
t.Run("arrays_space_3", func(t *testing.T) {
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
aso := c.GetArraysSpace("object-store")
if diff := cmp.Diff(aso.Items, arrso.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/arrays_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestArraysInfo(t *testing.T) {
e := endp[len(endp)-1]
t.Run("arrays_1", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
al := c.GetArrays()
if diff := cmp.Diff(al.Items, arr.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/blades_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestBlades(t *testing.T) {
e := endp[len(endp)-1]
t.Run("blades_1", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
bl := c.GetBlades()
if diff := cmp.Diff(bl.Items, abl.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/buckets_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestBucketsPerformance(t *testing.T) {
e := endp[len(endp)-1]
t.Run("buckets_performance_1", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
b := c.GetBuckets()
pl := c.GetBucketsPerformance(b)
if diff := cmp.Diff(pl.Items, bpl.Items); diff != "" {
Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/buckets_s3_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestBucketsS3Performance(t *testing.T) {
e := endp[len(endp)-1]
t.Run("buckets_s3_performance_1", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
b := c.GetBuckets()
pl := c.GetBucketsS3Performance(b)
if diff := cmp.Diff(pl.Items, bpl.Items); diff != "" {
Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/buckets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestBuckets(t *testing.T) {
e := endp[len(endp)-1]
t.Run("buckets_1", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
bl := c.GetBuckets()
if diff := cmp.Diff(bl.Items, ab.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/clients_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestClientsPerformance(t *testing.T) {
e := endp[len(endp)-1]
t.Run("clients_performance_1", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
cp := c.GetClientsPerformance()
if diff := cmp.Diff(cp.Items, cpl.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down
6 changes: 3 additions & 3 deletions internal/rest-client/filesystems_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestFileSystemsPerformance(t *testing.T) {
endp := strings.Split(server.URL, "/")
e := endp[len(endp)-1]
t.Run("filesystems_performance_all", func(t *testing.T) {
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
f := c.GetFileSystems()
fl := c.GetFileSystemsPerformance(f, "all")
if diff := cmp.Diff(fl.Items, fpl.Items); diff != "" {
Expand All @@ -51,7 +51,7 @@ func TestFileSystemsPerformance(t *testing.T) {
}
})
t.Run("filesystems_performance_nfs", func(t *testing.T) {
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
f := c.GetFileSystems()
fl := c.GetFileSystemsPerformance(f, "NFS")
if diff := cmp.Diff(fl.Items, fpl.Items); diff != "" {
Expand All @@ -60,7 +60,7 @@ func TestFileSystemsPerformance(t *testing.T) {
}
})
t.Run("filesystems_performance_smb", func(t *testing.T) {
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
f := c.GetFileSystems()
fl := c.GetFileSystemsPerformance(f, "SMB")
if diff := cmp.Diff(fl.Items, fpl.Items); diff != "" {
Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/filesystems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestFileSystems(t *testing.T) {
e := endp[len(endp)-1]
t.Run("filesystems_1", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
fsl := c.GetFileSystems()
if diff := cmp.Diff(fsl.Items, fs.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down
4 changes: 2 additions & 2 deletions internal/rest-client/flashblade_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type FBClient struct {
Error error
}

func NewRestClient(endpoint string, apitoken string, apiversion string, debug bool) *FBClient {
func NewRestClient(endpoint string, apitoken string, apiversion string, uagent string, debug bool) *FBClient {
type ApiVersions struct {
Versions []string `json:"versions"`
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func NewRestClient(endpoint string, apitoken string, apiversion string, debug bo
fb.XAuthToken = res.Header().Get("x-auth-token")
fb.RestClient.SetBaseURL("https://" + endpoint + "/api/" + fb.ApiVersion)
fb.RestClient.SetHeader("x-auth-token", fb.XAuthToken)
fb.RestClient.SetHeader("User-Agent", FBRestUserAgent)
fb.RestClient.SetHeader("User-Agent", FBRestUserAgent + " (" + uagent + ")")
return fb
}

Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/flashblade_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestNewRestClient(t *testing.T) {
e := endp[len(endp)-1]
t.Run("login", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
if c.EndPoint != e || c.ApiToken != "fake-api-token" || c.XAuthToken != "faketoken" {
t.Errorf("expected (%s, fake-api-token, faketoken), got (%s %s %s)", e, c.EndPoint, c.ApiToken, c.XAuthToken)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/hardware_connectors_perf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestHwConnectorsPerformance(t *testing.T) {
e := endp[len(endp)-1]
t.Run("hardware_1", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
hl := c.GetHwConnectorsPerformance()
if diff := cmp.Diff(hl.Items, hw.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/hardware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestHardware(t *testing.T) {
e := endp[len(endp)-1]
t.Run("hardware_1", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
hl := c.GetHardware()
if diff := cmp.Diff(hl.Items, hw.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down
2 changes: 1 addition & 1 deletion internal/rest-client/nfs_export_policies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestNFSExportPolicies(t *testing.T) {
e := endp[len(endp)-1]
t.Run("nfs_policies_1", func(t *testing.T) {
defer server.Close()
c := NewRestClient(e, "fake-api-token", "latest", false)
c := NewRestClient(e, "fake-api-token", "latest", "test-user-agent-string", false)
pl := c.GetNFSExportPolicies()
if diff := cmp.Diff(pl.Items, nfsp.Items); diff != "" {
t.Errorf("Mismatch (-want +got):\n%s", diff)
Expand Down

0 comments on commit ef2acad

Please sign in to comment.