- 
                Notifications
    You must be signed in to change notification settings 
- Fork 128
Allow to run system benchmarks with more than one input #3019
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
bf7816d
              3dcbab5
              67e8191
              7faec54
              32cc30a
              f0fa83e
              409db65
              fde61a6
              6ebbade
              6aadd00
              8d1dea6
              e5bc43b
              258a835
              b7f9d5a
              d2e5303
              0c282fa
              8e5c1b5
              b42d76e
              ed610d4
              b20b0e5
              34c86ed
              cedd774
              f7419dd
              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 | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|  | @@ -42,6 +42,8 @@ const ( | |||||||||||||||
|  | ||||||||||||||||
| // BenchType defining system benchmark | ||||||||||||||||
| BenchType benchrunner.Type = "system" | ||||||||||||||||
|  | ||||||||||||||||
| defaultNamespace = "ep" | ||||||||||||||||
| ) | ||||||||||||||||
|  | ||||||||||||||||
| type runner struct { | ||||||||||||||||
|  | @@ -169,14 +171,25 @@ func (r *runner) setUp(ctx context.Context) error { | |||||||||||||||
| return fmt.Errorf("reading package manifest failed: %w", err) | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| policy, err := r.createBenchmarkPolicy(ctx, pkgManifest) | ||||||||||||||||
| // Set default values for scenario fields from package manifest if not set | ||||||||||||||||
| if r.scenario.Version == "" { | ||||||||||||||||
| r.scenario.Version = pkgManifest.Version | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| if r.scenario.Package == "" { | ||||||||||||||||
| r.scenario.Package = pkgManifest.Name | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| if r.scenario.PolicyTemplate == "" { | ||||||||||||||||
| r.scenario.PolicyTemplate = pkgManifest.PolicyTemplates[0].Name | ||||||||||||||||
| } | ||||||||||||||||
| 
      Comment on lines
    
      +174
     to 
      +185
    
   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. These checks/assignments were previously inside  | ||||||||||||||||
|  | ||||||||||||||||
| policy, err := r.createBenchmarkPolicy(ctx, pkgManifest, defaultNamespace) | ||||||||||||||||
| if err != nil { | ||||||||||||||||
| return err | ||||||||||||||||
| } | ||||||||||||||||
| r.benchPolicy = policy | ||||||||||||||||
|  | ||||||||||||||||
| // Delete old data | ||||||||||||||||
| logger.Debug("deleting old data in data stream...") | ||||||||||||||||
| dataStreamManifest, err := packages.ReadDataStreamManifest( | ||||||||||||||||
| filepath.Join( | ||||||||||||||||
| common.DataStreamPath(r.options.PackageRootPath, r.scenario.DataStream.Name), | ||||||||||||||||
|  | @@ -210,6 +223,7 @@ func (r *runner) setUp(ctx context.Context) error { | |||||||||||||||
| return nil | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| logger.Debug("deleting old data in data stream...") | ||||||||||||||||
| if err := r.deleteDataStreamDocs(ctx, r.runtimeDataStream); err != nil { | ||||||||||||||||
| return fmt.Errorf("error deleting old data in data stream: %s: %w", r.runtimeDataStream, err) | ||||||||||||||||
| } | ||||||||||||||||
|  | @@ -367,14 +381,14 @@ func (r *runner) deleteDataStreamDocs(ctx context.Context, dataStream string) er | |||||||||||||||
| return nil | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| func (r *runner) createBenchmarkPolicy(ctx context.Context, pkgManifest *packages.PackageManifest) (*kibana.Policy, error) { | ||||||||||||||||
| func (r *runner) createBenchmarkPolicy(ctx context.Context, pkgManifest *packages.PackageManifest, namespace string) (*kibana.Policy, error) { | ||||||||||||||||
| // Configure package (single data stream) via Ingest Manager APIs. | ||||||||||||||||
| logger.Debug("creating benchmark policy...") | ||||||||||||||||
| benchTime := time.Now().Format("20060102T15:04:05Z") | ||||||||||||||||
| p := kibana.Policy{ | ||||||||||||||||
| Name: fmt.Sprintf("ep-bench-%s-%s", r.options.BenchName, benchTime), | ||||||||||||||||
| Description: fmt.Sprintf("policy created by elastic-package for benchmark %s", r.options.BenchName), | ||||||||||||||||
| Namespace: "ep", | ||||||||||||||||
| Namespace: namespace, | ||||||||||||||||
| MonitoringEnabled: []string{"logs", "metrics"}, | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
|  | @@ -388,67 +402,64 @@ func (r *runner) createBenchmarkPolicy(ctx context.Context, pkgManifest *package | |||||||||||||||
| return nil, err | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| packagePolicy, err := r.createPackagePolicy(ctx, pkgManifest, policy) | ||||||||||||||||
| if err != nil { | ||||||||||||||||
| return nil, err | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| r.deletePolicyHandler = func(ctx context.Context) error { | ||||||||||||||||
| var merr multierror.Error | ||||||||||||||||
|  | ||||||||||||||||
| logger.Debug("deleting benchmark package policy...") | ||||||||||||||||
| if err := r.options.KibanaClient.DeletePackagePolicy(ctx, *packagePolicy); err != nil { | ||||||||||||||||
| merr = append(merr, fmt.Errorf("error cleaning up benchmark package policy: %w", err)) | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| // Package policy deletion is handled when deleting this policy. | ||||||||||||||||
| // Setting here the deletion handler ensures that if package policy creation fails, | ||||||||||||||||
| // no orphaned package policies are left behind. | ||||||||||||||||
| logger.Debug("deleting benchmark policy...") | ||||||||||||||||
| if err := r.options.KibanaClient.DeletePolicy(ctx, policy.ID); err != nil { | ||||||||||||||||
| merr = append(merr, fmt.Errorf("error cleaning up benchmark policy: %w", err)) | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| if len(merr) > 0 { | ||||||||||||||||
| return merr | ||||||||||||||||
| return fmt.Errorf("error cleaning up benchmark policy: %w", err) | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| return nil | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| _, err = r.createPackagePolicy(ctx, pkgManifest, policy) | ||||||||||||||||
| if err != nil { | ||||||||||||||||
| return nil, err | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| return policy, nil | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| func (r *runner) createPackagePolicy(ctx context.Context, pkgManifest *packages.PackageManifest, p *kibana.Policy) (*kibana.PackagePolicy, error) { | ||||||||||||||||
| logger.Debug("creating package policy...") | ||||||||||||||||
|  | ||||||||||||||||
| if r.scenario.Version == "" { | ||||||||||||||||
| r.scenario.Version = pkgManifest.Version | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| if r.scenario.Package == "" { | ||||||||||||||||
| r.scenario.Package = pkgManifest.Name | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| if r.scenario.PolicyTemplate == "" { | ||||||||||||||||
| r.scenario.PolicyTemplate = pkgManifest.PolicyTemplates[0].Name | ||||||||||||||||
| } | ||||||||||||||||
|  | ||||||||||||||||
| pp := kibana.PackagePolicy{ | ||||||||||||||||
| Namespace: "ep", | ||||||||||||||||
| Namespace: p.Namespace, | ||||||||||||||||
| PolicyID: p.ID, | ||||||||||||||||
| Force: true, | ||||||||||||||||
| Inputs: map[string]kibana.PackagePolicyInput{ | ||||||||||||||||
| fmt.Sprintf("%s-%s", r.scenario.PolicyTemplate, r.scenario.Input): { | ||||||||||||||||
| Enabled: true, | ||||||||||||||||
| Vars: r.scenario.Vars, | ||||||||||||||||
| Streams: map[string]kibana.PackagePolicyStream{ | ||||||||||||||||
| fmt.Sprintf("%s.%s", pkgManifest.Name, r.scenario.DataStream.Name): { | ||||||||||||||||
| fmt.Sprintf("%s.%s", r.scenario.Package, r.scenario.DataStream.Name): { | ||||||||||||||||
| 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. Previously, this was using directly  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. It should be the same value, right? 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. Yes, since  Looking at the current system benchmarks defined in the integrations repository that setting to set the package name is not used. But, IIUC if the package name is set in the system benchmark configuration, I'd say that this value should be the one from the configuration... | ||||||||||||||||
| Enabled: true, | ||||||||||||||||
| Vars: r.scenario.DataStream.Vars, | ||||||||||||||||
| }, | ||||||||||||||||
| }, | ||||||||||||||||
| }, | ||||||||||||||||
| }, | ||||||||||||||||
| } | ||||||||||||||||
| pp.Package.Name = pkgManifest.Name | ||||||||||||||||
|  | ||||||||||||||||
| // By default, all policy templates are enabled when creating a package policy. | ||||||||||||||||
| // This could lead to errors if other policy templates have required variables. | ||||||||||||||||
| // Therefore, all other policy templates and inputs must be disabled since here | ||||||||||||||||
| // just the variables for the current input are set. | ||||||||||||||||
| // NOTE: This data is retrieved from the local package manifest. | ||||||||||||||||
| for _, policyTemplate := range pkgManifest.PolicyTemplates { | ||||||||||||||||
| for _, input := range policyTemplate.Inputs { | ||||||||||||||||
| if policyTemplate.Name == r.scenario.PolicyTemplate && input.Type == r.scenario.Input { | ||||||||||||||||
| continue | ||||||||||||||||
| } | ||||||||||||||||
| pp.Inputs[fmt.Sprintf("%s-%s", policyTemplate.Name, input.Type)] = kibana.PackagePolicyInput{ | ||||||||||||||||
| Enabled: false, | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| 
      Comment on lines
    
      +446
     to 
      +460
    
   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. Screenshots with examples of the explanation explained in the comment are posted in the description of the PR. As mentioned in the comment, setting this policy templates as disabled is based on the manifests read from the files found in the package locally. elastic-package/internal/benchrunner/runners/system/runner.go Lines 430 to 432 in d5f73ab 
 This would be something to check if it is required to use other package or versions as mentioned in the documentation: elastic-package/docs/howto/system_benchmarking.md Lines 231 to 234 in d5f73ab 
 | ||||||||||||||||
|  | ||||||||||||||||
| pp.Package.Name = r.scenario.Package | ||||||||||||||||
| 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. Previously, this was using directly  | ||||||||||||||||
| pp.Package.Version = r.scenario.Version | ||||||||||||||||
|  | ||||||||||||||||
| policy, err := r.options.KibanaClient.CreatePackagePolicy(ctx, pp) | ||||||||||||||||
|  | ||||||||||||||||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| --- | ||
| description: Benchmark 100000 alert events ingested | ||
| input: httpjson | ||
| # This field was not available, fixed in https://github.com/elastic/package-spec/pull/1004 | ||
| # policy_template: sentinel_one | ||
| vars: | ||
| url: "http://svc-sentinel_one:8080/" | ||
| api_token: xxxx | ||
| enable_request_tracer: true | ||
| data_stream: | ||
| name: alert | ||
| vars: | ||
| preserve_original_event: true | ||
| warmup_time_period: 2s | ||
| corpora: | ||
| input_service: | ||
| name: sentinel_one | ||
| generator: | ||
| total_events: 100000 | ||
| template: | ||
| path: ./alert-benchmark/template.ndjson | ||
| type: gotext | ||
| config: | ||
| path: ./alert-benchmark/config.yml | ||
| fields: | ||
| path: ./alert-benchmark/fields.yml | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly added notes in this documentation file in case developers are running system benchmark with local changes.