Skip to content

Commit debb9de

Browse files
mergify[bot]mauri870swiatekm
authored
otel: support system/metrics input with experimental otel runtime (#8148) (#8327)
* otel: support system/metrics input with experimental otel runtime * use EventuallyWithTf * add tests comparing final documents * trim test * remove TestSystemMetricsInput * remove unused vars * ignore host.network.ingress fields * fix typo in expectation message * don't compare system metrics directly, only compare the keys are present * ignore host.network.* fields * remove dot from prefix * ignore network activity fields * ignore flaky fields from network * stop ignoring elastic_agent.{snapshot,version} * reestructure test to use a single config * Revert "reestructure test to use a single config" Windows throws errors about named pipes. I suspect system/metrics input tries to register monitoring on the same socket. This reverts commit aa6b4c6. * remove agent.version from ignore list * reorder stripNondeterminism call * print documents in case of failure * compare host-wide and normal network events separately * simplify code * Add Sudo to define.Require * match for host metrics * filter network interface events * use tt.metricset, add note about network events * add metricsets to template * Update testing/integration/beat_receivers_test.go * use AssertMapstrEqual --------- (cherry picked from commit 5648918) Co-authored-by: Mauri de Souza Meneguzzo <[email protected]> Co-authored-by: Mikołaj Świątek <[email protected]>
1 parent 0d70eba commit debb9de

File tree

3 files changed

+422
-1
lines changed

3 files changed

+422
-1
lines changed

internal/pkg/otel/configtranslate/otelconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type exporterConfigTranslationFunc func(*config.C) (map[string]any, error)
3939

4040
var (
4141
OtelSupportedOutputTypes = []string{"elasticsearch"}
42-
OtelSupportedInputTypes = []string{"filestream", "http/metrics", "beat/metrics"}
42+
OtelSupportedInputTypes = []string{"filestream", "http/metrics", "beat/metrics", "system/metrics"}
4343
configTranslationFuncForExporter = map[otelcomponent.Type]exporterConfigTranslationFunc{
4444
otelcomponent.MustNewType("elasticsearch"): translateEsOutputToExporter,
4545
}

internal/pkg/otel/configtranslate/otelconfig_test.go

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,33 @@ func TestGetOtelConfig(t *testing.T) {
179179
},
180180
},
181181
}
182+
systemMetricsConfig := map[string]any{
183+
"id": "test",
184+
"use_output": "default",
185+
"type": "system/metrics",
186+
"streams": []any{
187+
map[string]any{
188+
"id": "test-1",
189+
"data_stream": map[string]any{
190+
"dataset": "generic-1",
191+
},
192+
"metricsets": map[string]any{
193+
"cpu": map[string]any{
194+
"data_stream.dataset": "system.cpu",
195+
},
196+
"memory": map[string]any{
197+
"data_stream.dataset": "system.memory",
198+
},
199+
"network": map[string]any{
200+
"data_stream.dataset": "system.network",
201+
},
202+
"filesystem": map[string]any{
203+
"data_stream.dataset": "system.filesystem",
204+
},
205+
},
206+
},
207+
},
208+
}
182209
esOutputConfig := map[string]any{
183210
"type": "elasticsearch",
184211
"hosts": []any{"localhost:9200"},
@@ -505,6 +532,110 @@ func TestGetOtelConfig(t *testing.T) {
505532
},
506533
}),
507534
},
535+
{
536+
name: "system/metrics",
537+
model: &component.Model{
538+
Components: []component.Component{
539+
{
540+
ID: "system-metrics",
541+
InputType: "system/metrics",
542+
OutputType: "elasticsearch",
543+
InputSpec: &component.InputRuntimeSpec{
544+
BinaryName: "agentbeat",
545+
Spec: component.InputSpec{
546+
Command: &component.CommandSpec{
547+
Args: []string{"metricbeat"},
548+
},
549+
},
550+
},
551+
Units: []component.Unit{
552+
{
553+
ID: "system/metrics",
554+
Type: client.UnitTypeInput,
555+
Config: component.MustExpectedConfig(systemMetricsConfig),
556+
},
557+
{
558+
ID: "system/metrics-default",
559+
Type: client.UnitTypeOutput,
560+
Config: component.MustExpectedConfig(esOutputConfig),
561+
},
562+
},
563+
},
564+
},
565+
},
566+
expectedConfig: confmap.NewFromStringMap(map[string]any{
567+
"exporters": expectedESConfig,
568+
"receivers": map[string]any{
569+
"metricbeatreceiver/_agent-component/system-metrics": map[string]any{
570+
"metricbeat": map[string]any{
571+
"modules": []map[string]any{
572+
{
573+
"module": "system",
574+
"data_stream": map[string]any{"dataset": "generic-1"},
575+
"id": "test-1",
576+
"index": "metrics-generic-1-default",
577+
"metricsets": map[string]any{
578+
"cpu": map[string]any{
579+
"data_stream.dataset": "system.cpu",
580+
},
581+
"memory": map[string]any{
582+
"data_stream.dataset": "system.memory",
583+
},
584+
"network": map[string]any{
585+
"data_stream.dataset": "system.network",
586+
},
587+
"filesystem": map[string]any{
588+
"data_stream.dataset": "system.filesystem",
589+
},
590+
},
591+
"processors": defaultProcessors("test-1", "generic-1", "metrics"),
592+
},
593+
},
594+
},
595+
"output": map[string]any{
596+
"otelconsumer": map[string]any{},
597+
},
598+
"path": map[string]any{
599+
"data": filepath.Join(paths.Run(), "system-metrics"),
600+
},
601+
"queue": map[string]any{
602+
"mem": map[string]any{
603+
"events": uint64(3200),
604+
"flush": map[string]any{
605+
"min_events": uint64(1600),
606+
"timeout": "10s",
607+
},
608+
},
609+
},
610+
"logging": map[string]any{
611+
"with_fields": map[string]any{
612+
"component": map[string]any{
613+
"binary": "metricbeat",
614+
"dataset": "elastic_agent.metricbeat",
615+
"type": "system/metrics",
616+
"id": "system-metrics",
617+
},
618+
"log": map[string]any{
619+
"source": "system-metrics",
620+
},
621+
},
622+
},
623+
"http": map[string]any{
624+
"enabled": true,
625+
"host": "localhost",
626+
},
627+
},
628+
},
629+
"service": map[string]any{
630+
"pipelines": map[string]any{
631+
"logs/_agent-component/system-metrics": map[string][]string{
632+
"exporters": []string{"elasticsearch/_agent-component/default"},
633+
"receivers": []string{"metricbeatreceiver/_agent-component/system-metrics"},
634+
},
635+
},
636+
},
637+
}),
638+
},
508639
}
509640
for _, tt := range tests {
510641
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)