Skip to content

Commit 6a690bf

Browse files
authored
add support for kibana policy overrides (#3094)
1 parent 0bb4a82 commit 6a690bf

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

docs/howto/system_testing.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,23 @@ In this case, `elastic-package test system` will fail with an error and print a
977977
skip_ignored_fields:
978978
- field.to.ignore
979979
```
980+
### Kibana policy overrides
981+
982+
If you need to test a system test with a Kibana policy override you can do that by setting the environment variable `ELASTIC_PACKAGE_KIBANA_POLICY_OVERRIDES` to be a path to a yaml file that contains the policy override. For example:
983+
984+
```shell
985+
ELASTIC_PACKAGE_KIBANA_POLICY_OVERRIDES=/tmp/overrides.yml elastic-package test system
986+
```
987+
988+
and the `/tmp/overrides.yml` file has the following contents:
989+
990+
```yaml
991+
agent:
992+
monitoring:
993+
_runtime_experimental: otel
994+
```
995+
996+
Will result in the system test running with the agent monitoring using the `otel` runtime.
980997

981998
## Continuous Integration
982999

internal/kibana/policies.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@ import (
1616

1717
// Policy represents an Agent Policy in Fleet.
1818
type Policy struct {
19-
ID string `json:"id,omitempty"`
20-
Name string `json:"name"`
21-
Description string `json:"description"`
22-
Namespace string `json:"namespace"`
23-
Revision int `json:"revision,omitempty"`
24-
MonitoringEnabled []string `json:"monitoring_enabled,omitempty"`
25-
MonitoringOutputID string `json:"monitoring_output_id,omitempty"`
26-
DataOutputID string `json:"data_output_id,omitempty"`
27-
IsDefaultFleetServer bool `json:"is_default_fleet_server,omitempty"`
19+
ID string `json:"id,omitempty"`
20+
Name string `json:"name"`
21+
Description string `json:"description"`
22+
Namespace string `json:"namespace"`
23+
Revision int `json:"revision,omitempty"`
24+
MonitoringEnabled []string `json:"monitoring_enabled,omitempty"`
25+
MonitoringOutputID string `json:"monitoring_output_id,omitempty"`
26+
DataOutputID string `json:"data_output_id,omitempty"`
27+
IsDefaultFleetServer bool `json:"is_default_fleet_server,omitempty"`
28+
Overrides map[string]any `json:"overrides,omitempty"`
2829
}
2930

3031
// DownloadedPolicy represents a policy as returned by the download policy API.

internal/testrunner/runners/system/tester.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ var (
178178
dumpScenarioDocsEnv = environment.WithElasticPackagePrefix("TEST_DUMP_SCENARIO_DOCS")
179179
fieldValidationTestMethodEnv = environment.WithElasticPackagePrefix("FIELD_VALIDATION_TEST_METHOD")
180180
prefixServiceTestRunIDEnv = environment.WithElasticPackagePrefix("PREFIX_SERVICE_TEST_RUN_ID")
181+
kibanaPolicyOverridesEnv = environment.WithElasticPackagePrefix("KIBANA_POLICY_OVERRIDES")
181182
)
182183

183184
type fieldValidationMethod int
@@ -230,6 +231,8 @@ type tester struct {
230231

231232
globalTestConfig testrunner.GlobalRunnerTestConfig
232233

234+
kibanaPolicyOverrides map[string]any
235+
233236
// Execution order of following handlers is defined in runner.TearDown() method.
234237
removeAgentHandler func(context.Context) error
235238
deleteTestPolicyHandler func(context.Context) error
@@ -348,6 +351,20 @@ func NewSystemTester(options SystemTesterOptions) (*tester, error) {
348351
r.fieldValidationMethod = method
349352
}
350353

354+
// kibana policy overrides
355+
v, ok = os.LookupEnv(kibanaPolicyOverridesEnv)
356+
if ok {
357+
data, err := os.ReadFile(v)
358+
if err != nil {
359+
return nil, fmt.Errorf("error reading file %q specified in %s: %w", v, kibanaPolicyOverridesEnv, err)
360+
}
361+
overrides := make(map[string]any)
362+
if err = yaml.Unmarshal(data, &overrides); err != nil {
363+
return nil, fmt.Errorf("error reading yaml from %s: %w", v, err)
364+
}
365+
r.kibanaPolicyOverrides = overrides
366+
}
367+
351368
return &r, nil
352369
}
353370

@@ -1374,6 +1391,7 @@ func (r *tester) createOrGetKibanaPolicies(ctx context.Context, serviceStateData
13741391
Name: fmt.Sprintf("ep-test-system-%s-%s-%s-%s-%s", r.testFolder.Package, r.testFolder.DataStream, r.serviceVariant, r.configFileName, testTime),
13751392
Description: fmt.Sprintf("test policy created by elastic-package test system for data stream %s/%s", r.testFolder.Package, r.testFolder.DataStream),
13761393
Namespace: common.CreateTestRunID(),
1394+
Overrides: r.kibanaPolicyOverrides,
13771395
}
13781396
// Assign the data_output_id to the agent policy to configure the output to logstash. The value is inferred from stack/_static/kibana.yml.tmpl
13791397
// TODO: Migrate from stack.logstash_enabled to the stack config.

0 commit comments

Comments
 (0)