-
Notifications
You must be signed in to change notification settings - Fork 135
Add multiple service deployer to benchmarks #3304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
40583d0
e6fcd1e
183b527
450db85
f1b98f8
06d6007
0cfd434
e7ce611
333ef9a
25b37d3
9339ea1
2165b08
b4a1019
b3b83cf
b2f9968
fbc2071
0e44737
6f4f602
6210301
cab532b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ import ( | |
|
|
||
| "github.com/elastic/elastic-package/internal/benchrunner/reporters" | ||
| "github.com/elastic/elastic-package/internal/elasticsearch/ingest" | ||
| "github.com/elastic/elastic-package/internal/packages" | ||
| ) | ||
|
|
||
| type report struct { | ||
|
|
@@ -31,6 +32,7 @@ type report struct { | |
| } | ||
| Parameters struct { | ||
| PackageVersion string | ||
| Deployer string | ||
| Input string | ||
| Vars map[string]interface{} | ||
| DataStream dataStream | ||
|
|
@@ -47,8 +49,8 @@ type report struct { | |
| TotalHits int | ||
| } | ||
|
|
||
| func createReport(benchName, corporaFile string, s *scenario, sum *metricsSummary) (reporters.Reportable, error) { | ||
| r := newReport(benchName, corporaFile, s, sum) | ||
| func createReport(benchName, corporaFile string, s *scenario, sum *metricsSummary, secretVarNames map[string]bool) (reporters.Reportable, error) { | ||
| r := newReport(benchName, corporaFile, s, sum, secretVarNames) | ||
| human := reporters.NewReport(s.Package, reportHumanFormat(r)) | ||
|
|
||
| jsonBytes, err := reportJSONFormat(r) | ||
|
|
@@ -63,7 +65,7 @@ func createReport(benchName, corporaFile string, s *scenario, sum *metricsSummar | |
| return mr, nil | ||
| } | ||
|
|
||
| func newReport(benchName, corporaFile string, s *scenario, sum *metricsSummary) *report { | ||
| func newReport(benchName, corporaFile string, s *scenario, sum *metricsSummary, secretVarNames map[string]bool) *report { | ||
| var report report | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be interesting or worthy to add the deployer used to run the benchmark in the report too ?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 6210301 ╭─────────────────────────────────────────────────────────────────────────────────────╮
│ parameters │
├──────────────────────────────────────────┬──────────────────────────────────────────┤
│ package version │ 3.12.0 │
+ │ deployer │ docker │
│ input │ cel │
│ vars.client_id │ xxxx │
│ vars.client_secret │ xxxx │
│ vars.token_url │ http://svc-crowdstrike:8080/oauth2/token │
│ vars.url │ http://svc-crowdstrike:8080 │
│ data_stream.name │ alert │
│ data_stream.vars.enable_request_tracer │ true │
│ data_stream.vars.preserve_original_event │ true │
│ warmup time period │ 2s │
│ benchmark time period │ 0s │
│ wait for data timeout │ 10m0s │
│ corpora.generator.total_events │ 1000 │
│ corpora.generator.template.path │ ./alert-benchmark/template.ndjson │
│ corpora.generator.template.raw │ │
│ corpora.generator.template.type │ gotext │
│ corpora.generator.config.path │ ./alert-benchmark/config.yml │
│ corpora.generator.config.raw │ map[] │
│ corpora.generator.fields.path │ ./alert-benchmark/fields.yml │
│ corpora.generator.fields.raw │ map[] │
│ corpora.input_service.name │ crowdstrike │
│ corpora.input_service.signal │ │
╰──────────────────────────────────────────┴──────────────────────────────────────────╯
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works in those packages that define multiple deployers, but in the ones that just use the only deployer defined, that field is shown as empty: https://buildkite.com/elastic/elastic-package/builds/7576#019d29de-e5d8-49c8-9f5f-94b89e96ce1f/L1092 |
||
| report.Info.Benchmark = benchName | ||
| report.Info.Description = s.Description | ||
|
|
@@ -74,9 +76,13 @@ func newReport(benchName, corporaFile string, s *scenario, sum *metricsSummary) | |
| report.Info.Duration = time.Duration(sum.CollectionEndTs-sum.CollectionStartTs) * time.Second | ||
| report.Info.GeneratedCorporaFile = corporaFile | ||
| report.Parameters.PackageVersion = s.Version | ||
| report.Parameters.Deployer = s.Deployer | ||
| report.Parameters.Input = s.Input | ||
| report.Parameters.Vars = s.Vars | ||
| report.Parameters.DataStream = s.DataStream | ||
| report.Parameters.Vars = maskSecretVars(s.Vars, secretVarNames) | ||
| report.Parameters.DataStream = dataStream{ | ||
| Name: s.DataStream.Name, | ||
| Vars: maskSecretVars(s.DataStream.Vars, secretVarNames), | ||
| } | ||
| report.Parameters.WarmupTimePeriod = s.WarmupTimePeriod | ||
| report.Parameters.BenchmarkTimePeriod = s.BenchmarkTimePeriod | ||
| report.Parameters.WaitForDataTimeout = *s.WaitForDataTimeout | ||
|
|
@@ -114,6 +120,7 @@ func reportHumanFormat(r *report) []byte { | |
|
|
||
| pkvs := []interface{}{ | ||
| "package version", r.Parameters.PackageVersion, | ||
| "deployer", r.Parameters.Deployer, | ||
| "input", r.Parameters.Input, | ||
| } | ||
|
|
||
|
|
@@ -218,6 +225,52 @@ func reportHumanFormat(r *report) []byte { | |
| return []byte(report.String()) | ||
| } | ||
|
|
||
| func collectSecretVarNames(pkgManifest *packages.PackageManifest, dsManifest *packages.DataStreamManifest) map[string]bool { | ||
| secrets := make(map[string]bool) | ||
| for _, v := range pkgManifest.Vars { | ||
| if v.Secret { | ||
| secrets[v.Name] = true | ||
| } | ||
| } | ||
| for _, pt := range pkgManifest.PolicyTemplates { | ||
| for _, input := range pt.Inputs { | ||
| for _, v := range input.Vars { | ||
| if v.Secret { | ||
| secrets[v.Name] = true | ||
| } | ||
| } | ||
| } | ||
| for _, v := range pt.Vars { | ||
| if v.Secret { | ||
| secrets[v.Name] = true | ||
| } | ||
| } | ||
| } | ||
| for _, stream := range dsManifest.Streams { | ||
| for _, v := range stream.Vars { | ||
| if v.Secret { | ||
| secrets[v.Name] = true | ||
| } | ||
| } | ||
| } | ||
| return secrets | ||
| } | ||
|
|
||
| func maskSecretVars(vars map[string]interface{}, secretNames map[string]bool) map[string]interface{} { | ||
| if len(vars) == 0 || len(secretNames) == 0 { | ||
| return vars | ||
| } | ||
| masked := make(map[string]interface{}, len(vars)) | ||
| for k, v := range vars { | ||
| if secretNames[k] { | ||
| masked[k] = "xxxx" | ||
| } else { | ||
| masked[k] = v | ||
| } | ||
| } | ||
| return masked | ||
| } | ||
|
|
||
| func renderBenchmarkTable(title string, kv ...interface{}) string { | ||
| t := table.NewWriter() | ||
| t.SetStyle(table.StyleRounded) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
|
|
||
| package system | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestMaskSecretVars(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| testCases := []struct { | ||
| name string | ||
| vars map[string]interface{} | ||
| secretNames map[string]bool | ||
| expected map[string]interface{} | ||
| }{ | ||
| { | ||
| name: "masks secret vars and preserves non-secret vars", | ||
| vars: map[string]interface{}{ | ||
| "api_key": "super-secret-value", | ||
| "host": "localhost", | ||
| "retries": 3, | ||
| "tls": true, | ||
| "namespace": "default", | ||
| }, | ||
| secretNames: map[string]bool{ | ||
| "api_key": true, | ||
| }, | ||
| expected: map[string]interface{}{ | ||
| "api_key": "xxxx", | ||
| "host": "localhost", | ||
| "retries": 3, | ||
| "tls": true, | ||
| "namespace": "default", | ||
| }, | ||
| }, | ||
| { | ||
| name: "returns vars unchanged when there are no secret names", | ||
| vars: map[string]interface{}{ | ||
| "host": "localhost", | ||
| }, | ||
| secretNames: map[string]bool{}, | ||
| expected: map[string]interface{}{ | ||
| "host": "localhost", | ||
| }, | ||
| }, | ||
| { | ||
| name: "returns empty vars map when vars are empty", | ||
| vars: map[string]interface{}{}, | ||
| secretNames: map[string]bool{ | ||
| "api_key": true, | ||
| }, | ||
| expected: map[string]interface{}{}, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| tc := tc | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| original := make(map[string]interface{}, len(tc.vars)) | ||
| for k, v := range tc.vars { | ||
| original[k] = v | ||
| } | ||
|
|
||
| actual := maskSecretVars(tc.vars, tc.secretNames) | ||
|
|
||
| assert.Equal(t, tc.expected, actual) | ||
| assert.Equal(t, original, tc.vars) | ||
| }) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.