Skip to content

Commit

Permalink
[receiver/purefa] Add initial full complete base test for the scrapers
Browse files Browse the repository at this point in the history
  • Loading branch information
dgoscn committed Jun 11, 2023
1 parent 8b10209 commit 6a251e1
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 4 deletions.
17 changes: 15 additions & 2 deletions receiver/purefareceiver/internal/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func (h *scraper) ToPrometheusReceiverConfig(host component.Host, _ receiver.Fac
return nil, err
}

bearerToken, err := RetrieveBearerToken(arr.Auth, host.GetExtensions())
if err != nil {
httpConfig, err := getHTTPConfig(arr, host)
if err != nil {
return nil, err
}

Expand Down Expand Up @@ -101,3 +101,16 @@ func (h *scraper) ToPrometheusReceiverConfig(host component.Host, _ receiver.Fac

return scrapeCfgs, nil
}

func getHTTPConfig(scCfgs ScraperConfig, host component.Host) (configutil.HTTPClientConfig, error){
ret := configutil.HTTPClientConfig{}
if scCfgs.Auth != nil {
bearerToken, err := RetrieveBearerToken(*scCfgs.Auth, host.GetExtensions())
if err != nil {
return ret, err
}

ret.BearerToken = configutil.Secret(bearerToken)
}
return ret, nil
}
2 changes: 1 addition & 1 deletion receiver/purefareceiver/internal/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func TestToPrometheusConfig(t *testing.T) {
cfgs := []ScraperConfig{
{
Address: "array01",
Auth: configauth.Authentication{
Auth: &configauth.Authentication{
AuthenticatorID: component.NewIDWithName("bearertokenauth", "array01"),
},
},
Expand Down
2 changes: 1 addition & 1 deletion receiver/purefareceiver/internal/scraperconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import "go.opentelemetry.io/collector/config/configauth"

type ScraperConfig struct {
Address string `mapstructure:"address"`
Auth configauth.Authentication `mapstructure:"auth"`
Auth *configauth.Authentication `mapstructure:"auth"`
}
46 changes: 46 additions & 0 deletions receiver/purefareceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,52 @@ import (
"go.opentelemetry.io/collector/receiver/receivertest"
)

func TestReceiverArray(t *testing.T) {
// prepare
wg := &sync.WaitGroup()

once := &sync.Once{}
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var data []byte
var err error

once.Do(func(){
data, err := os.ReadFile("testdata/array.txt")
require.NoError(t, err)
wg.Done()
})

_, err = w.Write(data)
require.NoError(t, err)
}))
defer ts.Close()

cfg, ok := createDefaultConfig().(*Config)
require.True(t, ok)

cfg.Endpoint = ts.URL
cfg.Array = []internal.ScraperConfig{{
Address: "array01",
}}
cfg.Settings = &Settings{
ReloadIntervals: &ReloadIntervals{
Array: 10 * time.Millisecond,
},
}

sink := &consumertest.MetricsSink{}
recv := newReceiver(cfg, receivertest.NewNopCreateSettings(), sink)
wg.Add(1)

// test
rr := recv.Start(context.Background(), componenttest.NewNopHost())
wg.Wait()

// verify
assert.NoError(t, err)
assert.Greater(t, len(sink.AllMetrics()), 0, "expected to have received more than 0 metrics")
}

func TestStart(t *testing.T) {
// prepare
cfg, ok := createDefaultConfig().(*Config)
Expand Down
15 changes: 15 additions & 0 deletions receiver/purefareceiver/testdata/array.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 3.7743e-05
go_gc_duration_seconds{quantile="0.25"} 6.0311e-05
go_gc_duration_seconds{quantile="0.5"} 8.5667e-05
go_gc_duration_seconds{quantile="0.75"} 0.000104831
go_gc_duration_seconds{quantile="1"} 0.000112094
go_gc_duration_seconds_sum 0.000486284
go_gc_duration_seconds_count 6
# HELP purefa_array_performance_average_bytes FlashArray array average operations size
# TYPE purefa_array_performance_average_bytes gauge
purefa_array_performance_average_bytes{dimension="bytes_per_mirrored_write"} 0
purefa_array_performance_average_bytes{dimension="bytes_per_op"} 88064
purefa_array_performance_average_bytes{dimension="bytes_per_read"} 0
purefa_array_performance_average_bytes{dimension="bytes_per_mirrored_write}

0 comments on commit 6a251e1

Please sign in to comment.