diff --git a/receiver/telemetrygeneratorreceiver/config.go b/receiver/telemetrygeneratorreceiver/config.go index af8f384e1..596e5f9ae 100644 --- a/receiver/telemetrygeneratorreceiver/config.go +++ b/receiver/telemetrygeneratorreceiver/config.go @@ -19,8 +19,11 @@ import ( "errors" "fmt" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/plog" + "go.opentelemetry.io/collector/pdata/pmetric" + "go.opentelemetry.io/collector/pdata/ptrace" ) // Config is the configuration for the telemetry generator receiver @@ -70,18 +73,25 @@ func (g *GeneratorConfig) Validate() error { return validateHostMetricsGeneratorConfig(g) case generatorTypeWindowsEvents: return validateWindowsEventsGeneratorConfig(g) - + case generatorTypeOTLP: + return validateOTLPGenerator(g) default: return fmt.Errorf("invalid generator type: %s", g.Type) } } func validateLogGeneratorConfig(g *GeneratorConfig) error { + err := pcommon.NewMap().FromRaw(g.Attributes) if err != nil { return fmt.Errorf("error in attributes config: %s", err) } + err = pcommon.NewMap().FromRaw(g.ResourceAttributes) + if err != nil { + return fmt.Errorf("error in resource_attributes config: %s", err) + } + // severity and body validation if body, ok := g.AdditionalConfig["body"]; ok { // check if body is a valid string, if not, return an error @@ -105,6 +115,71 @@ func validateLogGeneratorConfig(g *GeneratorConfig) error { return nil } +func validateOTLPGenerator(cfg *GeneratorConfig) error { + + telemetryType, ok := cfg.AdditionalConfig["telemetry_type"] + if !ok { + return errors.New("telemetry_type must be set") + } + + // validate the telemetry type + telemetryTypeStr, ok := telemetryType.(string) + if !ok { + return fmt.Errorf("invalid telemetry type: %v", telemetryType) + } + dataType := component.DataType(telemetryTypeStr) + switch dataType { + case component.DataTypeLogs, component.DataTypeMetrics, component.DataTypeTraces: + default: + return fmt.Errorf("invalid telemetry type: %s", telemetryType) + } + + // validate the otlp json + otlpJSON, ok := cfg.AdditionalConfig["otlp_json"] + if !ok { + return errors.New("otlp_json must be set") + } + + otlpJSONStr, ok := otlpJSON.(string) + if !ok { + return fmt.Errorf("otlp_json must be a string, got: %v", otlpJSON) + } + + jsonBytes := []byte(otlpJSONStr) + + switch dataType { + case component.DataTypeLogs: + marshaler := plog.JSONUnmarshaler{} + logs, err := marshaler.UnmarshalLogs(jsonBytes) + if err != nil { + return fmt.Errorf("error unmarshalling logs from otlp_json: %w", err) + } + if logs.LogRecordCount() == 0 { + return errors.New("no log records found in otlp_json") + } + case component.DataTypeMetrics: + marshaler := pmetric.JSONUnmarshaler{} + metrics, err := marshaler.UnmarshalMetrics(jsonBytes) + if err != nil { + return fmt.Errorf("error unmarshalling metrics from otlp_json: %w", err) + } + if metrics.DataPointCount() == 0 { + return errors.New("no metric data points found in otlp_json") + } + case component.DataTypeTraces: + marshaler := ptrace.JSONUnmarshaler{} + traces, err := marshaler.UnmarshalTraces(jsonBytes) + if err != nil { + return fmt.Errorf("error unmarshalling traces from otlp_json: %w", err) + } + if traces.SpanCount() == 0 { + return errors.New("no trace spans found in otlp_json") + } + + } + return nil +} + func validateHostMetricsGeneratorConfig(_ *GeneratorConfig) error { return nil } diff --git a/receiver/telemetrygeneratorreceiver/config_test.go b/receiver/telemetrygeneratorreceiver/config_test.go index 3eccfffd2..7ae13fb53 100644 --- a/receiver/telemetrygeneratorreceiver/config_test.go +++ b/receiver/telemetrygeneratorreceiver/config_test.go @@ -202,6 +202,213 @@ func TestValidate(t *testing.T) { }, }, }, + { + desc: "invalid attributes", + payloads: 1, + errExpected: true, + errText: "error in attributes config: ", + generators: []GeneratorConfig{ + { + Type: "logs", + Attributes: map[string]any{ + "attr_key1": struct{}{}, + }, + }, + }, + }, + { + desc: "invalid resource_attributes", + payloads: 1, + errExpected: true, + errText: "error in resource_attributes config: ", + generators: []GeneratorConfig{ + { + Type: "logs", + ResourceAttributes: map[string]any{ + "attr_key1": struct{}{}, + }, + }, + }, + }, + { + desc: "otlp - no type", + payloads: 10, + errExpected: true, + errText: "telemetry_type must be set", + generators: []GeneratorConfig{ + { + Type: "otlp", + AdditionalConfig: map[string]any{ + "otlp_json": "json", + }, + }, + }, + }, + { + desc: "otlp - telemetry_type not string", + payloads: 10, + errExpected: true, + errText: "invalid telemetry type: 1", + generators: []GeneratorConfig{ + { + Type: "otlp", + AdditionalConfig: map[string]any{ + "otlp_json": "json", + "telemetry_type": 1, + }, + }, + }, + }, + { + desc: "otlp - bad telemetry_type ", + payloads: 10, + errExpected: true, + errText: "invalid telemetry type: bad", + generators: []GeneratorConfig{ + { + Type: "otlp", + AdditionalConfig: map[string]any{ + "otlp_json": "json", + "telemetry_type": "bad", + }, + }, + }, + }, + { + desc: "otlp - no otlp_json", + payloads: 10, + errExpected: true, + errText: "otlp_json must be set", + generators: []GeneratorConfig{ + { + Type: "otlp", + AdditionalConfig: map[string]any{ + "telemetry_type": "logs", + }, + }, + }, + }, + { + desc: "otlp - otlp_json not string", + payloads: 10, + errExpected: true, + errText: "otlp_json must be a string, got: 1", + generators: []GeneratorConfig{ + { + Type: "otlp", + AdditionalConfig: map[string]any{ + "telemetry_type": "logs", + "otlp_json": 1, + }, + }, + }, + }, + { + desc: "otlp - malformed otlp_json logs", + payloads: 10, + errExpected: true, + errText: "error unmarshalling logs from otlp_json: skipThreeBytes: expect ull, error found in #2 byte of ...|not json|..., bigger context ...|not json|...", + generators: []GeneratorConfig{ + { + Type: "otlp", + AdditionalConfig: map[string]any{ + "telemetry_type": "logs", + "otlp_json": "not json", + }, + }, + }, + }, + { + desc: "otlp - malformed otlp_json metrics", + payloads: 10, + errExpected: true, + errText: "error unmarshalling metrics from otlp_json: ReadObjectCB: expect \" after {, but found n, error found in #2 byte of ...|{not json}|..., bigger context ...|{not json}|...", + generators: []GeneratorConfig{ + { + Type: "otlp", + AdditionalConfig: map[string]any{ + "telemetry_type": "metrics", + "otlp_json": "{not json}", + }, + }, + }, + }, + { + desc: "otlp - malformed otlp_json traces", + payloads: 10, + errExpected: true, + errText: "error unmarshalling traces from otlp_json: ReadObjectCB: expect { or n, but found ?, error found in #1 byte of ...|?(not json)|..., bigger context ...|?(not json)|...", + generators: []GeneratorConfig{ + { + Type: "otlp", + AdditionalConfig: map[string]any{ + "telemetry_type": "traces", + "otlp_json": "?(not json)", + }, + }, + }, + }, + { + desc: "otlp - otlp_json logs, telemetry_type traces", + payloads: 10, + errExpected: true, + errText: "no trace spans found in otlp_json", + generators: []GeneratorConfig{ + { + Type: "otlp", + AdditionalConfig: map[string]any{ + "telemetry_type": "traces", + "otlp_json": `{"resourceLogs":[{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677536097000000","observedTimeUnixNano":"1709677536223996000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.097 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.097 EST"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536111000000","observedTimeUnixNano":"1709677536224110000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.111 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.111 EST"}},{"key":"role","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536113000000","observedTimeUnixNano":"1709677536224164000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.113 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.113 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"role","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536126000000","observedTimeUnixNano":"1709677536224300000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.126 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"role","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.126 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"user","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536149000000","observedTimeUnixNano":"1709677536224359000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.149 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.149 EST"}},{"key":"role","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"tid","value":{"stringValue":"8334"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536151000000","observedTimeUnixNano":"1709677536224466000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.151 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"role","value":{"stringValue":""}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"duration","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.151 EST"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536154000000","observedTimeUnixNano":"1709677536224517000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.154 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"role","value":{"stringValue":""}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.154 EST"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536157000000","observedTimeUnixNano":"1709677536224635000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.157 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"duration","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.157 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536159000000","observedTimeUnixNano":"1709677536224688000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.159 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.159 EST"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"user","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}}],"traceId":"","spanId":""}]}]},{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677536097000000","observedTimeUnixNano":"1709677536223996000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.097 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.097 EST"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536111000000","observedTimeUnixNano":"1709677536224110000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.111 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.111 EST"}},{"key":"role","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536113000000","observedTimeUnixNano":"1709677536224164000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.113 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.113 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"role","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536126000000","observedTimeUnixNano":"1709677536224300000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.126 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"role","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.126 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"user","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536149000000","observedTimeUnixNano":"1709677536224359000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.149 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.149 EST"}},{"key":"role","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"tid","value":{"stringValue":"8334"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536151000000","observedTimeUnixNano":"1709677536224466000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.151 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"role","value":{"stringValue":""}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"duration","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.151 EST"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536154000000","observedTimeUnixNano":"1709677536224517000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.154 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"role","value":{"stringValue":""}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.154 EST"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536157000000","observedTimeUnixNano":"1709677536224635000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.157 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"duration","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.157 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536159000000","observedTimeUnixNano":"1709677536224688000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.159 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.159 EST"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"user","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}}],"traceId":"","spanId":""}]}]}]}`, + }, + }, + }, + }, + { + desc: "otlp - telemetry_type metrics, otlp_json logs", + payloads: 10, + errExpected: true, + errText: "no metric data points found in otlp_json", + generators: []GeneratorConfig{ + { + Type: "otlp", + AdditionalConfig: map[string]any{ + "telemetry_type": "metrics", + "otlp_json": `{"resourceLogs":[{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677536097000000","observedTimeUnixNano":"1709677536223996000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.097 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.097 EST"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536111000000","observedTimeUnixNano":"1709677536224110000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.111 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.111 EST"}},{"key":"role","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536113000000","observedTimeUnixNano":"1709677536224164000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.113 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.113 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"role","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536126000000","observedTimeUnixNano":"1709677536224300000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.126 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"role","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.126 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"user","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536149000000","observedTimeUnixNano":"1709677536224359000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.149 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.149 EST"}},{"key":"role","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"tid","value":{"stringValue":"8334"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536151000000","observedTimeUnixNano":"1709677536224466000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.151 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"role","value":{"stringValue":""}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"duration","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.151 EST"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536154000000","observedTimeUnixNano":"1709677536224517000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.154 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"role","value":{"stringValue":""}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.154 EST"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536157000000","observedTimeUnixNano":"1709677536224635000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.157 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"duration","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.157 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536159000000","observedTimeUnixNano":"1709677536224688000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.159 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.159 EST"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"user","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}}],"traceId":"","spanId":""}]}]},{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677536097000000","observedTimeUnixNano":"1709677536223996000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.097 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.097 EST"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536111000000","observedTimeUnixNano":"1709677536224110000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.111 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.111 EST"}},{"key":"role","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536113000000","observedTimeUnixNano":"1709677536224164000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.113 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.113 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"role","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536126000000","observedTimeUnixNano":"1709677536224300000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.126 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"role","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.126 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"user","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536149000000","observedTimeUnixNano":"1709677536224359000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.149 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.149 EST"}},{"key":"role","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"tid","value":{"stringValue":"8334"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536151000000","observedTimeUnixNano":"1709677536224466000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.151 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"role","value":{"stringValue":""}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"duration","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.151 EST"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536154000000","observedTimeUnixNano":"1709677536224517000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.154 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"role","value":{"stringValue":""}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.154 EST"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536157000000","observedTimeUnixNano":"1709677536224635000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.157 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"duration","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.157 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536159000000","observedTimeUnixNano":"1709677536224688000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.159 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.159 EST"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"user","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}}],"traceId":"","spanId":""}]}]}]}`, + }, + }, + }, + }, + + { + desc: "otlp - telemetry_type traces, otlp_json metrics", + payloads: 10, + errExpected: true, + errText: "no trace spans found in otlp_json", + generators: []GeneratorConfig{ + { + Type: "otlp", + AdditionalConfig: map[string]any{ + "telemetry_type": "traces", + "otlp_json": `{"resourceMetrics":[{"resource":{},"scopeMetrics":[{"scope":{},"metrics":[{"summary":{"dataPoints":[{"attributes":[{"key":"prod-machine","value":{"stringValue":"prod-1"}}],"count":"4","sum":111}]}}]}]}]}`, + }, + }, + }, + }, + { + desc: "otlp - telemetry_type logs, otlp_json metrics", + payloads: 10, + errExpected: true, + errText: "no log records found in otlp_json", + generators: []GeneratorConfig{ + { + Type: "otlp", + AdditionalConfig: map[string]any{ + "telemetry_type": "logs", + "otlp_json": `{"resourceMetrics":[{"resource":{},"scopeMetrics":[{"scope":{},"metrics":[{"summary":{"dataPoints":[{"attributes":[{"key":"prod-machine","value":{"stringValue":"prod-1"}}],"count":"4","sum":111}]}}]}]}]}`, + }, + }, + }, + }, } for _, tc := range testCases { diff --git a/receiver/telemetrygeneratorreceiver/generators.go b/receiver/telemetrygeneratorreceiver/generators.go index 0129171c0..0bf520e0a 100644 --- a/receiver/telemetrygeneratorreceiver/generators.go +++ b/receiver/telemetrygeneratorreceiver/generators.go @@ -33,6 +33,9 @@ const ( // generatorTypeWindowsEvents is the generator type for windows events generatorTypeWindowsEvents generatorType = "windows_events" + + // generatorTypeOTLP is the generator type for OTLP + generatorTypeOTLP generatorType = "otlp" ) type metricGenerator interface { @@ -59,6 +62,9 @@ func newLogsGenerators(cfg *Config, logger *zap.Logger) []logGenerator { generators = append(generators, newLogsGenerator(gen, logger)) case generatorTypeWindowsEvents: generators = append(generators, newWindowsEventsGenerator(gen, logger)) + case generatorTypeOTLP: + generators = append(generators, newOtlpGenerator(gen, logger)) + } } return generators @@ -71,11 +77,21 @@ func newMetricsGenerators(cfg *Config, logger *zap.Logger) []metricGenerator { switch gen.Type { case generatorTypeHostMetrics: generators = append(generators, newHostMetricsGenerator(gen, logger)) + case generatorTypeOTLP: + generators = append(generators, newOtlpGenerator(gen, logger)) } + } return generators } -func newTraceGenerators(_ *Config, _ *zap.Logger) []traceGenerator { - return nil +func newTraceGenerators(cfg *Config, logger *zap.Logger) []traceGenerator { + var generators []traceGenerator + for _, gen := range cfg.Generators { + switch gen.Type { + case generatorTypeOTLP: + generators = append(generators, newOtlpGenerator(gen, logger)) + } + } + return generators } diff --git a/receiver/telemetrygeneratorreceiver/metrics_receiver.go b/receiver/telemetrygeneratorreceiver/metrics_receiver.go index bbea55d72..df43a3b25 100644 --- a/receiver/telemetrygeneratorreceiver/metrics_receiver.go +++ b/receiver/telemetrygeneratorreceiver/metrics_receiver.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/collector/consumer" + "go.opentelemetry.io/collector/pdata/pmetric" "go.uber.org/zap" ) @@ -41,7 +42,15 @@ func newMetricsReceiver(ctx context.Context, logger *zap.Logger, cfg *Config, ne return mr } -// TODO implement produce for metrics +// produce generates metrics from each generator and sends them to the next consumer func (r *metricsGeneratorReceiver) produce() error { - return nil + metrics := pmetric.NewMetrics() + for _, g := range r.generators { + m := g.generateMetrics() + for i := 0; i < m.ResourceMetrics().Len(); i++ { + src := m.ResourceMetrics().At(i) + src.CopyTo(metrics.ResourceMetrics().AppendEmpty()) + } + } + return r.nextConsumer.ConsumeMetrics(r.ctx, metrics) } diff --git a/receiver/telemetrygeneratorreceiver/otlp_generator.go b/receiver/telemetrygeneratorreceiver/otlp_generator.go new file mode 100644 index 000000000..ae6888f0a --- /dev/null +++ b/receiver/telemetrygeneratorreceiver/otlp_generator.go @@ -0,0 +1,305 @@ +// Copyright observIQ, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package telemetrygeneratorreceiver //import "github.com/observiq/bindplane-agent/receiver/telemetrygeneratorreceiver" + +import ( + "time" + + "go.opentelemetry.io/collector/component" + "go.opentelemetry.io/collector/pdata/pcommon" + "go.opentelemetry.io/collector/pdata/plog" + "go.opentelemetry.io/collector/pdata/pmetric" + "go.opentelemetry.io/collector/pdata/ptrace" + "go.uber.org/zap" +) + +// getCurrentTime is a variable that holds the current time function. It is used to mock time in tests. +var getCurrentTime = func() time.Time { return time.Now().UTC() } + +// otlpGenerator is a replay generator for logs, metrics, and traces. +// It generates a stream of telemetry based on the json embedded in the configuration, +// each record identical save for the timestamp. +type otlpGenerator struct { + cfg GeneratorConfig + logger *zap.Logger + telemetryType component.DataType + logs plog.Logs + logsStart time.Time + metrics pmetric.Metrics + metricsStart time.Time + traces ptrace.Traces + tracesStart time.Time +} + +func newOtlpGenerator(cfg GeneratorConfig, logger *zap.Logger) *otlpGenerator { + lg := &otlpGenerator{ + cfg: cfg, + logger: logger, + logs: plog.NewLogs(), + metrics: pmetric.NewMetrics(), + traces: ptrace.NewTraces(), + } + + // validation already proves this exists, is a string, and a component.DataType + lg.telemetryType = component.Type(lg.cfg.AdditionalConfig["telemetry_type"].(string)) + jsonBytes := []byte(lg.cfg.AdditionalConfig["otlp_json"].(string)) + + var err error + switch lg.telemetryType { + case component.DataTypeLogs: + marshaler := plog.JSONUnmarshaler{} + lg.logs, err = marshaler.UnmarshalLogs(jsonBytes) + // validation should catch this error + if err != nil { + logger.Warn("error unmarshalling otlp logs json", zap.Error(err)) + } + lg.adjustLogTimes() + case component.DataTypeMetrics: + marshaler := pmetric.JSONUnmarshaler{} + lg.metrics, err = marshaler.UnmarshalMetrics(jsonBytes) + // validation should catch this error + if err != nil { + logger.Warn("error unmarshalling otlp metrics json", zap.Error(err)) + } + lg.adjustMetricTimes() + case component.DataTypeTraces: + marshaler := ptrace.JSONUnmarshaler{} + lg.traces, err = marshaler.UnmarshalTraces(jsonBytes) + // validation should catch this error + if err != nil { + logger.Warn("error unmarshalling otlp traces json", zap.Error(err)) + } + lg.adjustTraceTimes() + } + + return lg +} + +// logRecordUpdater is a function that updates the timestamp of a log record +// since we need to iterate through the logs and metrics in three different places +type logRecordUpdater func(dp plog.LogRecord) + +// generic function to update the timestamps of all log records using the provided updater, +// or in the case of findLastLogTime, to find the most recent timestamp. +func (g *otlpGenerator) updateLogTimes(updater logRecordUpdater) { + for i := 0; i < g.logs.ResourceLogs().Len(); i++ { + resourceLogs := g.logs.ResourceLogs().At(i) + for k := 0; k < resourceLogs.ScopeLogs().Len(); k++ { + scopeLogs := resourceLogs.ScopeLogs().At(k) + for j := 0; j < scopeLogs.LogRecords().Len(); j++ { + log := scopeLogs.LogRecords().At(j) + updater(log) + } + } + } +} + +// findLastLogTime finds the log with the most recent timestamp +func (g *otlpGenerator) findLastLogTime() time.Time { + maxTime := time.Time{} + g.updateLogTimes(func(log plog.LogRecord) { + if t := log.Timestamp().AsTime(); t.After(maxTime) { + maxTime = t + } + }) + return maxTime +} + +// adjustTraceTimes changes the log timestamp to be relative to the current time, placing +// the log with timestamp maxTime at the current time. +func (g *otlpGenerator) adjustLogTimes() { + now := getCurrentTime() + maxTime := g.findLastLogTime() + + g.updateLogTimes(func(log plog.LogRecord) { + delta := maxTime.Sub(log.Timestamp().AsTime()) + log.SetTimestamp(pcommon.NewTimestampFromTime(now.Add(-delta))) + }) + g.logsStart = now +} + +// generateLogs generates a new set of logs with updated timestamps, adding the time +// since the last set of logs was generated to the timestamps. +func (g *otlpGenerator) generateLogs() plog.Logs { + now := getCurrentTime() + timeSince := now.Sub(g.logsStart) + g.updateLogTimes(func(log plog.LogRecord) { + timeStamp := log.Timestamp().AsTime().Add(timeSince) + log.SetTimestamp(pcommon.NewTimestampFromTime(timeStamp)) + }) + g.logsStart = now + return g.logs +} + +// timeStamped is convenience interface for updating the timestamps of metric datapoints in a generic way, +// since all metric datapoint types duck-type to this interface. +type timeStamped interface { + Timestamp() pcommon.Timestamp + SetTimestamp(pcommon.Timestamp) +} + +type dataPointUpdater func(dp timeStamped) + +// updateMetricTimes updates the timestamps of all metrics using the provided updater +func (g *otlpGenerator) updateMetricTimes(updater dataPointUpdater) { + for i := 0; i < g.metrics.ResourceMetrics().Len(); i++ { + resourceMetrics := g.metrics.ResourceMetrics().At(i) + for k := 0; k < resourceMetrics.ScopeMetrics().Len(); k++ { + scopeMetrics := resourceMetrics.ScopeMetrics().At(k) + for j := 0; j < scopeMetrics.Metrics().Len(); j++ { + metric := scopeMetrics.Metrics().At(j) + switch metric.Type() { + case pmetric.MetricTypeSum: + dps := metric.Sum().DataPoints() + for l := 0; l < dps.Len(); l++ { + updater(dps.At(l)) + } + case pmetric.MetricTypeGauge: + dps := metric.Gauge().DataPoints() + for l := 0; l < dps.Len(); l++ { + updater(dps.At(l)) + } + case pmetric.MetricTypeSummary: + dps := metric.Summary().DataPoints() + for l := 0; l < dps.Len(); l++ { + updater(dps.At(l)) + } + case pmetric.MetricTypeHistogram: + dps := metric.Histogram().DataPoints() + for l := 0; l < dps.Len(); l++ { + updater(dps.At(l)) + } + case pmetric.MetricTypeExponentialHistogram: + dps := metric.ExponentialHistogram().DataPoints() + for l := 0; l < dps.Len(); l++ { + updater(dps.At(l)) + } + } + } + } + } +} + +// findLastMetricTime finds the datapoint with the most recent timestamp +func (g *otlpGenerator) findLastMetricTime() time.Time { + maxTime := time.Time{} + g.updateMetricTimes(func(ts timeStamped) { + if t := ts.Timestamp().AsTime(); t.After(maxTime) { + maxTime = t + } + }) + return maxTime +} + +// adjustMetricTimes changes the metric timestamps to be relative to the current time, placing +// the metric with timestamp maxTime at the current time. +func (g *otlpGenerator) adjustMetricTimes() { + now := getCurrentTime() + maxTime := g.findLastMetricTime() + g.updateMetricTimes(func(ts timeStamped) { + delta := maxTime.Sub(ts.Timestamp().AsTime()) + ts.SetTimestamp(pcommon.NewTimestampFromTime(now.Add(-delta))) + }) + g.metricsStart = now +} + +// generateMetrics generates a new set of metrics with updated timestamps, adding the time +// since the last set of metrics was generated to the timestamps. +func (g *otlpGenerator) generateMetrics() pmetric.Metrics { + // calculate the time since the last baseline time we used to adjust the metrics + now := getCurrentTime() + timeSince := now.Sub(g.metricsStart) + g.updateMetricTimes(func(ts timeStamped) { + timeStamp := ts.Timestamp().AsTime().Add(timeSince) + ts.SetTimestamp(pcommon.NewTimestampFromTime(timeStamp)) + }) + // update the baseline time to the current time + g.metricsStart = now + + return g.metrics +} + +// Since we need to iterate through the traces in three different places, we define a function type +// to update the timestamps of spans. +type spanUpdater func(dp ptrace.Span) + +// updateTraceTimes updates the timestamps of all spans using the provided updater +func (g *otlpGenerator) updateTraceTimes(updater spanUpdater) { + for i := 0; i < g.traces.ResourceSpans().Len(); i++ { + resourceSpans := g.traces.ResourceSpans().At(i) + for k := 0; k < resourceSpans.ScopeSpans().Len(); k++ { + scopeSpans := resourceSpans.ScopeSpans().At(k) + for j := 0; j < scopeSpans.Spans().Len(); j++ { + span := scopeSpans.Spans().At(j) + updater(span) + } + } + } +} + +// findLastTraceEndTime finds the span with the last end time +func (g *otlpGenerator) findLastTraceEndTime() time.Time { + maxTime := time.Time{} + + g.updateTraceTimes(func(span ptrace.Span) { + end := span.EndTimestamp().AsTime() + if end.After(maxTime) { + maxTime = end + } + }) + + return maxTime +} + +// adjustTraceTimes changes the start and end times of all spans to be relative to the current time, placing +// the span that ends at maxTime at the current time. +func (g *otlpGenerator) adjustTraceTimes() { + now := getCurrentTime() + maxTime := g.findLastTraceEndTime() + + g.updateTraceTimes(func(span ptrace.Span) { + // delta is the duration in the past this span's end time is before the maxTime + delta := maxTime.Sub(span.EndTimestamp().AsTime()) + // spanDuration is the length of the span + spanDuration := span.EndTimestamp().AsTime().Sub(span.StartTimestamp().AsTime()) + // move each span's end time by delta + endTime := now.Add(-delta) + span.SetEndTimestamp(pcommon.NewTimestampFromTime(endTime)) + // set the start time to be the end time minus the original span duration + span.SetStartTimestamp(pcommon.NewTimestampFromTime(endTime.Add(-spanDuration))) + }) + + // save the current time we used as a baseline to adjust the spans + g.tracesStart = now +} + +func (g *otlpGenerator) generateTraces() ptrace.Traces { + // calculate the time since the last baseline time we used to adjust the spans + now := getCurrentTime() + timeSince := now.Sub(g.tracesStart) + // add the time since to the start and end times of all spans + g.updateTraceTimes(func(span ptrace.Span) { + startTime := span.StartTimestamp().AsTime().Add(timeSince) + span.SetStartTimestamp(pcommon.NewTimestampFromTime(startTime)) + + endTime := span.EndTimestamp().AsTime().Add(timeSince) + span.SetEndTimestamp(pcommon.NewTimestampFromTime(endTime)) + }) + + // update the baseline time to the current time + g.tracesStart = now + + return g.traces +} diff --git a/receiver/telemetrygeneratorreceiver/otlp_generator_test.go b/receiver/telemetrygeneratorreceiver/otlp_generator_test.go new file mode 100644 index 000000000..d0b05bc30 --- /dev/null +++ b/receiver/telemetrygeneratorreceiver/otlp_generator_test.go @@ -0,0 +1,1076 @@ +// Copyright observIQ, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package telemetrygeneratorreceiver + +import ( + "path/filepath" + "testing" + "time" + + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/plogtest" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/ptracetest" + "github.com/stretchr/testify/require" + "go.uber.org/zap" +) + +var expectedOTLPDir = filepath.Join("testdata", "expected_otlp") + +func TestOTLPGenerator_Traces(t *testing.T) { + test := []struct { + name string + getCurrentTime func() time.Time + cfg GeneratorConfig + expectedFile string + }{ + { + name: "BPOP traces", + getCurrentTime: func() time.Time { + return time.Unix(0, 1706791445999459125) + }, + cfg: GeneratorConfig{ + Type: generatorTypeOTLP, + AdditionalConfig: map[string]any{ + "telemetry_type": "traces", + "otlp_json": `{ + "resourceSpans": [ + { + "resource": { + "attributes": [ + { + "key": "host.arch", + "value": { + "stringValue": "arm64" + } + }, + { + "key": "host.name", + "value": { + "stringValue": "Sams-M1-Pro.local" + } + }, + { + "key": "service.name", + "value": { + "stringValue": "bindplane" + } + }, + { + "key": "service.version", + "value": { + "stringValue": "unknown" + } + } + ] + }, + "scopeSpans": [ + { + "scope": {}, + "spans": [ + + + { + "endTimeUnixNano": "1706791445927702458", + "kind": 1, + "name": "pgstore/addTransitiveUpdates", + "parentSpanId": "b6e1d82a58e8fd61", + "spanId": "5a055056ad7713e5", + "startTimeUnixNano": "1706791445927700000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445927704250", + "kind": 1, + "name": "pgstore/notify", + "parentSpanId": "38ff7d679d77bdbd", + "spanId": "b6e1d82a58e8fd61", + "startTimeUnixNano": "1706791445927698000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + + { + "endTimeUnixNano": "1706791445973101000", + "kind": 1, + "name": "pgstore/scanPostgresResource", + "parentSpanId": "804ce3fb1b57be5d", + "spanId": "3eadb90414f2cf22", + "startTimeUnixNano": "1706791445971633000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445973109084", + "kind": 1, + "name": "pgstore/pgResourceInternal", + "parentSpanId": "5236aa938eb9341c", + "spanId": "804ce3fb1b57be5d", + "startTimeUnixNano": "1706791445962593000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445973110334", + "kind": 1, + "name": "pgstore/pgResource", + "parentSpanId": "ca3b8e53681a9e8d", + "spanId": "5236aa938eb9341c", + "startTimeUnixNano": "1706791445962592000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445973258875", + "kind": 1, + "name": "pgstore/pgEditConfiguration", + "parentSpanId": "a894c9beda2d173a", + "spanId": "ca3b8e53681a9e8d", + "startTimeUnixNano": "1706791445962589000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445973576917", + "kind": 1, + "name": "pgstore/addTransitiveUpdates", + "parentSpanId": "94557eef510d0814", + "spanId": "c3ea8f993f9009ba", + "startTimeUnixNano": "1706791445973575000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445973579333", + "kind": 1, + "name": "pgstore/notify", + "parentSpanId": "a894c9beda2d173a", + "spanId": "94557eef510d0814", + "startTimeUnixNano": "1706791445973572000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445975115042", + "kind": 1, + "name": "pgstore/releaseAdvisoryLock", + "parentSpanId": "a894c9beda2d173a", + "spanId": "8906c43abedb6bd9", + "startTimeUnixNano": "1706791445973581000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445975119416", + "kind": 1, + "name": "pgstore/UpdateRollout", + "parentSpanId": "9d5a7e824fa7ba3b", + "spanId": "a894c9beda2d173a", + "startTimeUnixNano": "1706791445937536000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445975734417", + "kind": 1, + "name": "pgstore/acquireAdvisoryLock", + "parentSpanId": "078ab0ab7eb707b2", + "spanId": "f141ff98614cfc0c", + "startTimeUnixNano": "1706791445975133000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445979767041", + "kind": 1, + "name": "pgstore/scanPostgresResource", + "parentSpanId": "f06908731ed62890", + "spanId": "e185a7e1c60473b8", + "startTimeUnixNano": "1706791445976351000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445979799208", + "kind": 1, + "name": "pgstore/pgResourceInternal", + "parentSpanId": "078ab0ab7eb707b2", + "spanId": "f06908731ed62890", + "startTimeUnixNano": "1706791445975818000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + + { + "endTimeUnixNano": "1706791445999459125", + "kind": 1, + "name": "pgstore/UpdateAllRollouts", + "parentSpanId": "", + "spanId": "aeb2a416b8796cba", + "startTimeUnixNano": "1706791445908223000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + } + ] + }, + { + "scope": {}, + "spans": [ + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "GetConfiguration" + } + } + ], + "endTimeUnixNano": "1706791445376564375", + "kind": 1, + "name": "graphql/GetConfiguration/response", + "parentSpanId": "723c3f6eb4457b5c", + "spanId": "fd55f461239efdfc", + "startTimeUnixNano": "1706791445359466000", + "status": {}, + "traceId": "a3fbd5dc5db5e1734cb54419ca540b66" + }, + { + "attributes": [ + { + "key": "operation", + "value": { + "stringValue": "GetConfiguration" + } + } + ], + "endTimeUnixNano": "1706791445376589750", + "kind": 1, + "name": "graphql/GetConfiguration/response", + "parentSpanId": "3e7909bbebcae0ba", + "spanId": "01f07757e7bb6612", + "startTimeUnixNano": "1706791445359560000", + "status": {}, + "traceId": "d70c2b5eea8977bb8a0712f8c2a1fcb4" + } + ] + }, + { + "scope": {}, + "spans": [ + { + "attributes": [ + { + "key": "http.method", + "value": { + "stringValue": "POST" + } + }, + { + "key": "http.scheme", + "value": { + "stringValue": "http" + } + }, + { + "key": "net.host.name", + "value": { + "stringValue": "bindplane" + } + }, + { + "key": "net.host.port", + "value": { + "intValue": "3001" + } + }, + { + "key": "net.sock.peer.addr", + "value": { + "stringValue": "127.0.0.1" + } + }, + { + "key": "net.sock.peer.port", + "value": { + "intValue": "50141" + } + }, + { + "key": "user_agent.original", + "value": { + "stringValue": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0" + } + }, + { + "key": "http.client_ip", + "value": { + "stringValue": "127.0.0.1" + } + }, + { + "key": "http.target", + "value": { + "stringValue": "/v1/graphql" + } + }, + { + "key": "net.protocol.version", + "value": { + "stringValue": "1.1" + } + }, + { + "key": "http.route", + "value": { + "stringValue": "/v1/graphql" + } + }, + { + "key": "http.status_code", + "value": { + "intValue": "200" + } + } + ], + "endTimeUnixNano": "1706791445376694750", + "kind": 2, + "name": "/v1/graphql", + "parentSpanId": "", + "spanId": "723c3f6eb4457b5c", + "startTimeUnixNano": "1706791445332980000", + "status": {}, + "traceId": "a3fbd5dc5db5e1734cb54419ca540b66" + }, + { + "attributes": [ + { + "key": "http.method", + "value": { + "stringValue": "POST" + } + }, + { + "key": "http.scheme", + "value": { + "stringValue": "http" + } + }, + { + "key": "net.host.name", + "value": { + "stringValue": "bindplane" + } + }, + { + "key": "net.host.port", + "value": { + "intValue": "3001" + } + }, + { + "key": "net.sock.peer.addr", + "value": { + "stringValue": "127.0.0.1" + } + }, + { + "key": "net.sock.peer.port", + "value": { + "intValue": "50140" + } + }, + { + "key": "user_agent.original", + "value": { + "stringValue": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0" + } + }, + { + "key": "http.client_ip", + "value": { + "stringValue": "127.0.0.1" + } + }, + { + "key": "http.target", + "value": { + "stringValue": "/v1/graphql" + } + }, + { + "key": "net.protocol.version", + "value": { + "stringValue": "1.1" + } + }, + { + "key": "http.route", + "value": { + "stringValue": "/v1/graphql" + } + }, + { + "key": "http.status_code", + "value": { + "intValue": "200" + } + } + ], + "endTimeUnixNano": "1706791445376708291", + "kind": 2, + "name": "/v1/graphql", + "parentSpanId": "", + "spanId": "3e7909bbebcae0ba", + "startTimeUnixNano": "1706791445332972000", + "status": {}, + "traceId": "d70c2b5eea8977bb8a0712f8c2a1fcb4" + } + ] + }, + { + "scope": {}, + "spans": [ + { + "endTimeUnixNano": "1706791445913878000", + "kind": 1, + "name": "pgindex/Suggestions", + "parentSpanId": "9d5a7e824fa7ba3b", + "spanId": "4c2049c4cd14c987", + "startTimeUnixNano": "1706791445912675000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445997017791", + "kind": 1, + "name": "pgindex/Suggestions", + "parentSpanId": "96ae55c03e5146b3", + "spanId": "aa69c45bc0970c2f", + "startTimeUnixNano": "1706791445996229000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + } + ] + } + ] + } + ] + }`, + }, + }, + expectedFile: filepath.Join(expectedOTLPDir, "traces", "bpop_traces.yaml"), + }, + { + name: "BPOP traces 2", + getCurrentTime: func() time.Time { + return time.Unix(0, 1706791445999459839) + }, + cfg: GeneratorConfig{ + Type: generatorTypeOTLP, + AdditionalConfig: map[string]any{ + "telemetry_type": "traces", + "otlp_json": `{ + "resourceSpans": [ + { + "resource": { + "attributes": [ + { + "key": "host.arch", + "value": { + "stringValue": "arm64" + } + }, + { + "key": "host.name", + "value": { + "stringValue": "Sams-M1-Pro.local" + } + }, + { + "key": "service.name", + "value": { + "stringValue": "bindplane" + } + }, + { + "key": "service.version", + "value": { + "stringValue": "unknown" + } + } + ] + }, + "scopeSpans": [ + { + "scope": {}, + "spans": [ + + + { + "endTimeUnixNano": "1706791445927702458", + "kind": 1, + "name": "pgstore/addTransitiveUpdates", + "parentSpanId": "b6e1d82a58e8fd61", + "spanId": "5a055056ad7713e5", + "startTimeUnixNano": "1706791445927700000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445927704250", + "kind": 1, + "name": "pgstore/notify", + "parentSpanId": "38ff7d679d77bdbd", + "spanId": "b6e1d82a58e8fd61", + "startTimeUnixNano": "1706791445927698000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + + { + "endTimeUnixNano": "1706791445973101000", + "kind": 1, + "name": "pgstore/scanPostgresResource", + "parentSpanId": "804ce3fb1b57be5d", + "spanId": "3eadb90414f2cf22", + "startTimeUnixNano": "1706791445971633000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445973109084", + "kind": 1, + "name": "pgstore/pgResourceInternal", + "parentSpanId": "5236aa938eb9341c", + "spanId": "804ce3fb1b57be5d", + "startTimeUnixNano": "1706791445962593000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445973110334", + "kind": 1, + "name": "pgstore/pgResource", + "parentSpanId": "ca3b8e53681a9e8d", + "spanId": "5236aa938eb9341c", + "startTimeUnixNano": "1706791445962592000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445973258875", + "kind": 1, + "name": "pgstore/pgEditConfiguration", + "parentSpanId": "a894c9beda2d173a", + "spanId": "ca3b8e53681a9e8d", + "startTimeUnixNano": "1706791445962589000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445973576917", + "kind": 1, + "name": "pgstore/addTransitiveUpdates", + "parentSpanId": "94557eef510d0814", + "spanId": "c3ea8f993f9009ba", + "startTimeUnixNano": "1706791445973575000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445973579333", + "kind": 1, + "name": "pgstore/notify", + "parentSpanId": "a894c9beda2d173a", + "spanId": "94557eef510d0814", + "startTimeUnixNano": "1706791445973572000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445975115042", + "kind": 1, + "name": "pgstore/releaseAdvisoryLock", + "parentSpanId": "a894c9beda2d173a", + "spanId": "8906c43abedb6bd9", + "startTimeUnixNano": "1706791445973581000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445975119416", + "kind": 1, + "name": "pgstore/UpdateRollout", + "parentSpanId": "9d5a7e824fa7ba3b", + "spanId": "a894c9beda2d173a", + "startTimeUnixNano": "1706791445937536000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445975734417", + "kind": 1, + "name": "pgstore/acquireAdvisoryLock", + "parentSpanId": "078ab0ab7eb707b2", + "spanId": "f141ff98614cfc0c", + "startTimeUnixNano": "1706791445975133000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445979767041", + "kind": 1, + "name": "pgstore/scanPostgresResource", + "parentSpanId": "f06908731ed62890", + "spanId": "e185a7e1c60473b8", + "startTimeUnixNano": "1706791445976351000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445979799208", + "kind": 1, + "name": "pgstore/pgResourceInternal", + "parentSpanId": "078ab0ab7eb707b2", + "spanId": "f06908731ed62890", + "startTimeUnixNano": "1706791445975818000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + + { + "endTimeUnixNano": "1706791445999459839", + "kind": 1, + "name": "pgstore/UpdateAllRollouts", + "parentSpanId": "", + "spanId": "aeb2a416b8796cba", + "startTimeUnixNano": "1706791445908223000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + } + ] + }, + { + "scope": {}, + "spans": [ + { + "attributes": [ + { + "key": "http.method", + "value": { + "stringValue": "POST" + } + }, + { + "key": "http.scheme", + "value": { + "stringValue": "http" + } + }, + { + "key": "net.host.name", + "value": { + "stringValue": "bindplane" + } + }, + { + "key": "net.host.port", + "value": { + "intValue": "3001" + } + }, + { + "key": "net.sock.peer.addr", + "value": { + "stringValue": "127.0.0.1" + } + }, + { + "key": "net.sock.peer.port", + "value": { + "intValue": "50141" + } + }, + { + "key": "user_agent.original", + "value": { + "stringValue": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0" + } + }, + { + "key": "http.client_ip", + "value": { + "stringValue": "127.0.0.1" + } + }, + { + "key": "http.target", + "value": { + "stringValue": "/v1/graphql" + } + }, + { + "key": "net.protocol.version", + "value": { + "stringValue": "1.1" + } + }, + { + "key": "http.route", + "value": { + "stringValue": "/v1/graphql" + } + }, + { + "key": "http.status_code", + "value": { + "intValue": "200" + } + } + ], + "endTimeUnixNano": "1706791445376694750", + "kind": 2, + "name": "/v1/graphql", + "parentSpanId": "", + "spanId": "723c3f6eb4457b5c", + "startTimeUnixNano": "1706791445332980000", + "status": {}, + "traceId": "a3fbd5dc5db5e1734cb54419ca540b66" + }, + { + "attributes": [ + { + "key": "http.method", + "value": { + "stringValue": "POST" + } + }, + { + "key": "http.scheme", + "value": { + "stringValue": "http" + } + }, + { + "key": "net.host.name", + "value": { + "stringValue": "bindplane" + } + }, + { + "key": "net.host.port", + "value": { + "intValue": "3001" + } + }, + { + "key": "net.sock.peer.addr", + "value": { + "stringValue": "127.0.0.1" + } + }, + { + "key": "net.sock.peer.port", + "value": { + "intValue": "50140" + } + }, + { + "key": "user_agent.original", + "value": { + "stringValue": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0" + } + }, + { + "key": "http.client_ip", + "value": { + "stringValue": "127.0.0.1" + } + }, + { + "key": "http.target", + "value": { + "stringValue": "/v1/graphql" + } + }, + { + "key": "net.protocol.version", + "value": { + "stringValue": "1.1" + } + }, + { + "key": "http.route", + "value": { + "stringValue": "/v1/graphql" + } + }, + { + "key": "http.status_code", + "value": { + "intValue": "200" + } + } + ], + "endTimeUnixNano": "1706791445376708291", + "kind": 2, + "name": "/v1/graphql", + "parentSpanId": "", + "spanId": "3e7909bbebcae0ba", + "startTimeUnixNano": "1706791445332972000", + "status": {}, + "traceId": "d70c2b5eea8977bb8a0712f8c2a1fcb4" + } + ] + }, + { + "scope": {}, + "spans": [ + { + "endTimeUnixNano": "1706791445913878000", + "kind": 1, + "name": "pgindex/Suggestions", + "parentSpanId": "9d5a7e824fa7ba3b", + "spanId": "4c2049c4cd14c987", + "startTimeUnixNano": "1706791445912675000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + }, + { + "endTimeUnixNano": "1706791445997017791", + "kind": 1, + "name": "pgindex/Suggestions", + "parentSpanId": "96ae55c03e5146b3", + "spanId": "aa69c45bc0970c2f", + "startTimeUnixNano": "1706791445996229000", + "status": {}, + "traceId": "c7f3bb6aa9e7a7dce92d85d1566f2c31" + } + ] + } + ] + } + ] + }`, + }, + }, + expectedFile: filepath.Join(expectedOTLPDir, "traces", "bpop_traces2.yaml"), + }, + } + for _, tc := range test { + t.Run(tc.name, func(t *testing.T) { + getCurrentTime = tc.getCurrentTime + err := tc.cfg.Validate() + require.NoError(t, err) + + g := newOtlpGenerator(tc.cfg, zap.NewNop()) + traces := g.generateTraces() + // golden.WriteTraces(t, tc.expectedFile, traces) + expectedTraces, err := golden.ReadTraces(tc.expectedFile) + require.NoError(t, err) + + err = ptracetest.CompareTraces(expectedTraces, traces) + require.NoError(t, err) + }) + } +} + +func Test_findLastTraceEndTime(t *testing.T) { + tests := []struct { + name string + traceFile string + expectedTime time.Time + }{ + + { + name: "Traces 1", + traceFile: filepath.Join(expectedOTLPDir, "traces", "bpop_traces.yaml"), + expectedTime: time.Date(2024, time.February, 1, 12, 44, 5, 999459125, time.UTC), + }, + { + name: "Traces 2", + traceFile: filepath.Join(expectedOTLPDir, "traces", "bpop_traces2.yaml"), + expectedTime: time.Date(2024, time.February, 1, 12, 44, 5, 999459839, time.UTC), + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + traces, err := golden.ReadTraces(tc.traceFile) + require.NoError(t, err) + g := &otlpGenerator{ + cfg: GeneratorConfig{Type: generatorTypeOTLP, AdditionalConfig: map[string]any{"telemetry_type": "traces"}}, + logger: zap.NewNop(), + traces: traces, + } + + lastTime := g.findLastTraceEndTime() + require.Equal(t, tc.expectedTime, lastTime) + }) + } +} + +func TestOTLPGenerator_Metrics(t *testing.T) { + + tests := []struct { + name string + getCurrentTime func() time.Time + cfg GeneratorConfig + expectedFile string + }{ + { + name: "exp histogram", + getCurrentTime: func() time.Time { + return time.Unix(0, 1706791445999459839) + }, + cfg: GeneratorConfig{ + Type: generatorTypeOTLP, + AdditionalConfig: map[string]any{ + "telemetry_type": "metrics", + "otlp_json": `{"resourceMetrics":[{"resource":{},"scopeMetrics":[{"scope":{},"metrics":[{"exponentialHistogram":{"dataPoints":[{"attributes":[{"key":"prod-machine","value":{"stringValue":"prod-1"}}],"count":"4","positive":{},"negative":{},"min":0,"max":100}]}}]}]}]}`, + }, + }, + expectedFile: filepath.Join(expectedOTLPDir, "metrics", "exp_histogram.yaml"), + }, + { + name: "gauge", + getCurrentTime: func() time.Time { + return time.Unix(0, 1706791445999459839) + }, + cfg: GeneratorConfig{ + Type: generatorTypeOTLP, + AdditionalConfig: map[string]any{ + "telemetry_type": "metrics", + "otlp_json": `{"resourceMetrics":[{"resource":{"attributes":[{"key":"extra-resource-attr-key","value":{"stringValue":"extra-resource-attr-value"}},{"key":"host.name","value":{"stringValue":"Linux-Machine"}},{"key":"os.type","value":{"stringValue":"linux"}}]},"scopeMetrics":[{"scope":{},"metrics":[{"name":"system.cpu.load_average.1m","description":"Average CPU Load over 1 minute.","unit":"{thread}","gauge":{"dataPoints":[{"attributes":[{"key":"cool-attribute-key","value":{"stringValue":"cool-attribute-value"}}],"startTimeUnixNano":"1000000","timeUnixNano":"2000000","asDouble":3.71484375}]}}]}]}]}`, + }, + }, + expectedFile: filepath.Join(expectedOTLPDir, "metrics", "gauge.yaml"), + }, + { + name: "histogram", + getCurrentTime: func() time.Time { + return time.Unix(0, 1706791445999459839) + }, + cfg: GeneratorConfig{ + Type: generatorTypeOTLP, + AdditionalConfig: map[string]any{ + "telemetry_type": "metrics", + "otlp_json": `{"resourceMetrics":[{"resource":{},"scopeMetrics":[{"scope":{},"metrics":[{"histogram":{"dataPoints":[{"attributes":[{"key":"prod-machine","value":{"stringValue":"prod-1"}}],"count":"4","bucketCounts":["0","2","2"],"explicitBounds":[0,50,100],"min":0,"max":100}]}}]}]}]}`, + }, + }, + expectedFile: filepath.Join(expectedOTLPDir, "metrics", "histogram.yaml"), + }, + { + name: "sum", + getCurrentTime: func() time.Time { + return time.Unix(0, 1706791445999459839) + }, + cfg: GeneratorConfig{ + Type: generatorTypeOTLP, + AdditionalConfig: map[string]any{ + "telemetry_type": "metrics", + "otlp_json": `{"resourceMetrics":[{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-MBP"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeMetrics":[{"scope":{},"metrics":[{"name":"system.filesystem.usage","description":"Filesystem bytes used.","unit":"By","sum":{"dataPoints":[{"attributes":[{"key":"device","value":{"stringValue":"/dev/disk4s1"}},{"key":"extra-sum-attr-key","value":{"stringValue":"extra-sum-attr-value"}},{"key":"mode","value":{"stringValue":"rw"}},{"key":"mountpoint","value":{"stringValue":"/Volumes/transfer"}},{"key":"state","value":{"stringValue":"free"}},{"key":"type","value":{"stringValue":"hfs"}}],"startTimeUnixNano":"1000000","timeUnixNano":"2000000","asInt":"8717185024"}]}}]}]}]}`, + }, + }, + expectedFile: filepath.Join(expectedOTLPDir, "metrics", "sum.yaml"), + }, + { + name: "summary", + getCurrentTime: func() time.Time { + return time.Unix(0, 1706791445999459839) + }, + cfg: GeneratorConfig{ + Type: generatorTypeOTLP, + AdditionalConfig: map[string]any{ + "telemetry_type": "metrics", + "otlp_json": `{"resourceMetrics":[{"resource":{},"scopeMetrics":[{"scope":{},"metrics":[{"summary":{"dataPoints":[{"attributes":[{"key":"prod-machine","value":{"stringValue":"prod-1"}}],"count":"4","sum":111}]}}]}]}]}`, + }, + }, + expectedFile: filepath.Join(expectedOTLPDir, "metrics", "summary.yaml"), + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + getCurrentTime = tc.getCurrentTime + err := tc.cfg.Validate() + require.NoError(t, err) + + g := newOtlpGenerator(tc.cfg, zap.NewNop()) + metrics := g.generateMetrics() + + expectedMetrics, err := golden.ReadMetrics(tc.expectedFile) + require.NoError(t, err) + + err = pmetrictest.CompareMetrics(expectedMetrics, metrics) + require.NoError(t, err) + }) + } +} +func TestOTLPGenerator_Logs(t *testing.T) { + + tests := []struct { + name string + getCurrentTime func() time.Time + cfg GeneratorConfig + expectedFile string + }{ + { + name: "postgres logs", + getCurrentTime: func() time.Time { + return time.Unix(0, 1706791445999459839) + }, + cfg: GeneratorConfig{ + Type: generatorTypeOTLP, + AdditionalConfig: map[string]any{ + "telemetry_type": "logs", + "otlp_json": `{"resourceLogs":[{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677536097000000","observedTimeUnixNano":"1709677536223996000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.097 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.097 EST"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536111000000","observedTimeUnixNano":"1709677536224110000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.111 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.111 EST"}},{"key":"role","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536113000000","observedTimeUnixNano":"1709677536224164000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.113 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.113 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"role","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536126000000","observedTimeUnixNano":"1709677536224300000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.126 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"role","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.126 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"user","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536149000000","observedTimeUnixNano":"1709677536224359000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.149 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.149 EST"}},{"key":"role","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"tid","value":{"stringValue":"8334"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536151000000","observedTimeUnixNano":"1709677536224466000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.151 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"role","value":{"stringValue":""}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"duration","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.151 EST"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536154000000","observedTimeUnixNano":"1709677536224517000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.154 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"role","value":{"stringValue":""}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.154 EST"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536157000000","observedTimeUnixNano":"1709677536224635000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.157 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"duration","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.157 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536159000000","observedTimeUnixNano":"1709677536224688000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.159 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.159 EST"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"user","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}}],"traceId":"","spanId":""}]}]},{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677536097000000","observedTimeUnixNano":"1709677536223996000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.097 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.097 EST"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536111000000","observedTimeUnixNano":"1709677536224110000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.111 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.111 EST"}},{"key":"role","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536113000000","observedTimeUnixNano":"1709677536224164000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.113 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.113 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"role","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536126000000","observedTimeUnixNano":"1709677536224300000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.126 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"role","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.126 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"user","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536149000000","observedTimeUnixNano":"1709677536224359000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.149 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.149 EST"}},{"key":"role","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"tid","value":{"stringValue":"8334"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536151000000","observedTimeUnixNano":"1709677536224466000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.151 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"role","value":{"stringValue":""}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"duration","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.151 EST"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536154000000","observedTimeUnixNano":"1709677536224517000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.154 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"role","value":{"stringValue":""}},{"key":"duration","value":{"stringValue":""}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.154 EST"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"user","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log_type","value":{"stringValue":"postgresql.general"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536157000000","observedTimeUnixNano":"1709677536224635000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.157 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"log_type","value":{"stringValue":"postgresql.general"}},{"key":"duration","value":{"stringValue":""}},{"key":"user","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.157 EST"}},{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677536159000000","observedTimeUnixNano":"1709677536224688000","severityNumber":9,"severityText":"LOG","body":{"stringValue":"2024-03-05 17:25:36.159 EST [8334] LOG: statement: COMMIT"},"attributes":[{"key":"tid","value":{"stringValue":"8334"}},{"key":"role","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"LOG"}},{"key":"message","value":{"stringValue":"statement: COMMIT"}},{"key":"duration","value":{"stringValue":""}},{"key":"statement","value":{"stringValue":"COMMIT"}},{"key":"sql_command","value":{"stringValue":"COMMIT"}},{"key":"timestamp","value":{"stringValue":"2024-03-05 17:25:36.159 EST"}},{"key":"log.file.name","value":{"stringValue":"postgresql-2024-03-05_172300.log"}},{"key":"user","value":{"stringValue":""}},{"key":"log_type","value":{"stringValue":"postgresql.general"}}],"traceId":"","spanId":""}]}]}]}`, + }, + }, + expectedFile: filepath.Join(expectedOTLPDir, "logs", "postgres_logs.yaml"), + }, + { + name: "bindplane logs", + getCurrentTime: func() time.Time { + return time.Unix(0, 1706791445999459839) + }, + cfg: GeneratorConfig{ + Type: generatorTypeOTLP, + AdditionalConfig: map[string]any{ + "telemetry_type": "logs", + "otlp_json": `{"resourceLogs":[{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677842569000000","observedTimeUnixNano":"1709677842727442000","severityNumber":5,"severityText":"debug","body":{"kvlistValue":{"values":[{"key":"logger","value":{"stringValue":"opamp"}},{"key":"message","value":{"stringValue":"agent running with the correct config"}},{"key":"bindplane.agent.id","value":{"stringValue":"01HQRTG9AFXV1VCV1TS0Z0942T"}},{"key":"bindplane.configuration.name","value":{"stringValue":"test-new:31"}},{"key":"level","value":{"stringValue":"debug"}},{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:42.569-0500"}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677842581000000","observedTimeUnixNano":"1709677842746558000","severityNumber":5,"severityText":"debug","body":{"kvlistValue":{"values":[{"key":"logger","value":{"stringValue":"opamp"}},{"key":"message","value":{"stringValue":"sending response to the agent"}},{"key":"span_id","value":{"stringValue":"0000000000000000"}},{"key":"trace_id","value":{"stringValue":"00000000000000000000000000000000"}},{"key":"bindplane.agent.id","value":{"stringValue":"01HQRTG9AFXV1VCV1TS0Z0942T"}},{"key":"components","value":{"arrayValue":{}}},{"key":"level","value":{"stringValue":"debug"}},{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:42.581-0500"}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677842581000000","observedTimeUnixNano":"1709677842746572000","severityNumber":5,"severityText":"debug","body":{"kvlistValue":{"values":[{"key":"message","value":{"stringValue":"OnMessage release"}},{"key":"span_id","value":{"stringValue":"0000000000000000"}},{"key":"trace_id","value":{"stringValue":"00000000000000000000000000000000"}},{"key":"bindplane.agent.id","value":{"stringValue":"01HQRTG9AFXV1VCV1TS0Z0942T"}},{"key":"level","value":{"stringValue":"debug"}},{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:42.581-0500"}},{"key":"logger","value":{"stringValue":"opamp"}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""}]}]},{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677842569000000","observedTimeUnixNano":"1709677842727442000","severityNumber":5,"severityText":"debug","body":{"kvlistValue":{"values":[{"key":"logger","value":{"stringValue":"opamp"}},{"key":"message","value":{"stringValue":"agent running with the correct config"}},{"key":"bindplane.agent.id","value":{"stringValue":"01HQRTG9AFXV1VCV1TS0Z0942T"}},{"key":"bindplane.configuration.name","value":{"stringValue":"test-new:31"}},{"key":"level","value":{"stringValue":"debug"}},{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:42.569-0500"}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677842581000000","observedTimeUnixNano":"1709677842746558000","severityNumber":5,"severityText":"debug","body":{"kvlistValue":{"values":[{"key":"logger","value":{"stringValue":"opamp"}},{"key":"message","value":{"stringValue":"sending response to the agent"}},{"key":"span_id","value":{"stringValue":"0000000000000000"}},{"key":"trace_id","value":{"stringValue":"00000000000000000000000000000000"}},{"key":"bindplane.agent.id","value":{"stringValue":"01HQRTG9AFXV1VCV1TS0Z0942T"}},{"key":"components","value":{"arrayValue":{}}},{"key":"level","value":{"stringValue":"debug"}},{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:42.581-0500"}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677842581000000","observedTimeUnixNano":"1709677842746572000","severityNumber":5,"severityText":"debug","body":{"kvlistValue":{"values":[{"key":"message","value":{"stringValue":"OnMessage release"}},{"key":"span_id","value":{"stringValue":"0000000000000000"}},{"key":"trace_id","value":{"stringValue":"00000000000000000000000000000000"}},{"key":"bindplane.agent.id","value":{"stringValue":"01HQRTG9AFXV1VCV1TS0Z0942T"}},{"key":"level","value":{"stringValue":"debug"}},{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:42.581-0500"}},{"key":"logger","value":{"stringValue":"opamp"}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""}]}]},{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677842785000000","observedTimeUnixNano":"1709677842925856000","severityNumber":9,"severityText":"info","body":{"kvlistValue":{"values":[{"key":"latency","value":{"doubleValue":0.029674834}},{"key":"status","value":{"doubleValue":200}},{"key":"path","value":{"stringValue":"/v1/graphql"}},{"key":"level","value":{"stringValue":"info"}},{"key":"message","value":{"stringValue":"/v1/graphql"}},{"key":"ip","value":{"stringValue":"127.0.0.1"}},{"key":"user-agent","value":{"stringValue":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0"}},{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:42.785-0500"}},{"key":"method","value":{"stringValue":"POST"}},{"key":"query","value":{"stringValue":""}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677842878000000","observedTimeUnixNano":"1709677842926280000","severityNumber":9,"severityText":"info","body":{"kvlistValue":{"values":[{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:42.878-0500"}},{"key":"message","value":{"stringValue":"Rollout complete"}},{"key":"bindplane.configuration.name","value":{"stringValue":"test-new:31"}},{"key":"duration","value":{"doubleValue":1.313709}},{"key":"level","value":{"stringValue":"info"}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""}]}]},{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677842785000000","observedTimeUnixNano":"1709677842925856000","severityNumber":9,"severityText":"info","body":{"kvlistValue":{"values":[{"key":"latency","value":{"doubleValue":0.029674834}},{"key":"status","value":{"doubleValue":200}},{"key":"path","value":{"stringValue":"/v1/graphql"}},{"key":"level","value":{"stringValue":"info"}},{"key":"message","value":{"stringValue":"/v1/graphql"}},{"key":"ip","value":{"stringValue":"127.0.0.1"}},{"key":"user-agent","value":{"stringValue":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0"}},{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:42.785-0500"}},{"key":"method","value":{"stringValue":"POST"}},{"key":"query","value":{"stringValue":""}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""},{"timeUnixNano":"1709677842878000000","observedTimeUnixNano":"1709677842926280000","severityNumber":9,"severityText":"info","body":{"kvlistValue":{"values":[{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:42.878-0500"}},{"key":"message","value":{"stringValue":"Rollout complete"}},{"key":"bindplane.configuration.name","value":{"stringValue":"test-new:31"}},{"key":"duration","value":{"doubleValue":1.313709}},{"key":"level","value":{"stringValue":"info"}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""}]}]},{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677843112000000","observedTimeUnixNano":"1709677843135879000","severityNumber":9,"severityText":"info","body":{"kvlistValue":{"values":[{"key":"user-agent","value":{"stringValue":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0"}},{"key":"message","value":{"stringValue":"/v1/graphql"}},{"key":"latency","value":{"doubleValue":0.026624375}},{"key":"ip","value":{"stringValue":"127.0.0.1"}},{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:43.112-0500"}},{"key":"method","value":{"stringValue":"POST"}},{"key":"query","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"info"}},{"key":"status","value":{"doubleValue":200}},{"key":"path","value":{"stringValue":"/v1/graphql"}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""}]}]},{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677843112000000","observedTimeUnixNano":"1709677843135879000","severityNumber":9,"severityText":"info","body":{"kvlistValue":{"values":[{"key":"user-agent","value":{"stringValue":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0"}},{"key":"message","value":{"stringValue":"/v1/graphql"}},{"key":"latency","value":{"doubleValue":0.026624375}},{"key":"ip","value":{"stringValue":"127.0.0.1"}},{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:43.112-0500"}},{"key":"method","value":{"stringValue":"POST"}},{"key":"query","value":{"stringValue":""}},{"key":"level","value":{"stringValue":"info"}},{"key":"status","value":{"doubleValue":200}},{"key":"path","value":{"stringValue":"/v1/graphql"}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""}]}]},{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677843239000000","observedTimeUnixNano":"1709677843334008000","severityNumber":9,"severityText":"info","body":{"kvlistValue":{"values":[{"key":"path","value":{"stringValue":"/v1/graphql"}},{"key":"latency","value":{"doubleValue":0.016023542}},{"key":"query","value":{"stringValue":""}},{"key":"ip","value":{"stringValue":"127.0.0.1"}},{"key":"user-agent","value":{"stringValue":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0"}},{"key":"level","value":{"stringValue":"info"}},{"key":"method","value":{"stringValue":"POST"}},{"key":"status","value":{"doubleValue":200}},{"key":"message","value":{"stringValue":"/v1/graphql"}},{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:43.239-0500"}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""}]}]},{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677843239000000","observedTimeUnixNano":"1709677843334008000","severityNumber":9,"severityText":"info","body":{"kvlistValue":{"values":[{"key":"path","value":{"stringValue":"/v1/graphql"}},{"key":"latency","value":{"doubleValue":0.016023542}},{"key":"query","value":{"stringValue":""}},{"key":"ip","value":{"stringValue":"127.0.0.1"}},{"key":"user-agent","value":{"stringValue":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0"}},{"key":"level","value":{"stringValue":"info"}},{"key":"method","value":{"stringValue":"POST"}},{"key":"status","value":{"doubleValue":200}},{"key":"message","value":{"stringValue":"/v1/graphql"}},{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:43.239-0500"}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""}]}]},{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677843375000000","observedTimeUnixNano":"1709677843525540000","severityNumber":9,"severityText":"info","body":{"kvlistValue":{"values":[{"key":"path","value":{"stringValue":"/v1/agents/01HQRTG9AFXV1VCV1TS0Z0942T/health/v1/metrics"}},{"key":"user-agent","value":{"stringValue":"observIQ's opentelemetry-collector distribution/v1.45.0 (darwin/arm64)"}},{"key":"latency","value":{"doubleValue":0.000155209}},{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:43.375-0500"}},{"key":"message","value":{"stringValue":"/v1/agents/01HQRTG9AFXV1VCV1TS0Z0942T/health/v1/metrics"}},{"key":"status","value":{"doubleValue":200}},{"key":"level","value":{"stringValue":"info"}},{"key":"method","value":{"stringValue":"POST"}},{"key":"query","value":{"stringValue":""}},{"key":"ip","value":{"stringValue":"127.0.0.1"}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""}]}]},{"resource":{"attributes":[{"key":"host.name","value":{"stringValue":"Sams-M1-Pro.local"}},{"key":"os.type","value":{"stringValue":"darwin"}}]},"scopeLogs":[{"scope":{},"logRecords":[{"timeUnixNano":"1709677843375000000","observedTimeUnixNano":"1709677843525540000","severityNumber":9,"severityText":"info","body":{"kvlistValue":{"values":[{"key":"path","value":{"stringValue":"/v1/agents/01HQRTG9AFXV1VCV1TS0Z0942T/health/v1/metrics"}},{"key":"user-agent","value":{"stringValue":"observIQ's opentelemetry-collector distribution/v1.45.0 (darwin/arm64)"}},{"key":"latency","value":{"doubleValue":0.000155209}},{"key":"timestamp","value":{"stringValue":"2024-03-05T17:30:43.375-0500"}},{"key":"message","value":{"stringValue":"/v1/agents/01HQRTG9AFXV1VCV1TS0Z0942T/health/v1/metrics"}},{"key":"status","value":{"doubleValue":200}},{"key":"level","value":{"stringValue":"info"}},{"key":"method","value":{"stringValue":"POST"}},{"key":"query","value":{"stringValue":""}},{"key":"ip","value":{"stringValue":"127.0.0.1"}}]}},"attributes":[{"key":"log.file.name","value":{"stringValue":"bindplane.log"}},{"key":"log_type","value":{"stringValue":"bindplane-op"}}],"traceId":"","spanId":""}]}]}]}`, + }, + }, + expectedFile: filepath.Join(expectedOTLPDir, "logs", "bpop_logs.yaml"), + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + getCurrentTime = tc.getCurrentTime + err := tc.cfg.Validate() + require.NoError(t, err) + + g := newOtlpGenerator(tc.cfg, zap.NewNop()) + actualLogs := g.generateLogs() + + expectedLogs, err := golden.ReadLogs(tc.expectedFile) + require.NoError(t, err) + + err = plogtest.CompareLogs(expectedLogs, actualLogs) + require.NoError(t, err) + }) + } +} diff --git a/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/logs/bpop_logs.yaml b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/logs/bpop_logs.yaml new file mode 100644 index 000000000..8f5071046 --- /dev/null +++ b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/logs/bpop_logs.yaml @@ -0,0 +1,763 @@ +resourceLogs: + - resource: + attributes: + - key: host.name + value: + stringValue: Sams-M1-Pro.local + - key: os.type + value: + stringValue: darwin + scopeLogs: + - logRecords: + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: logger + value: + stringValue: opamp + - key: message + value: + stringValue: agent running with the correct config + - key: bindplane.agent.id + value: + stringValue: 01HQRTG9AFXV1VCV1TS0Z0942T + - key: bindplane.configuration.name + value: + stringValue: test-new:31 + - key: level + value: + stringValue: debug + - key: timestamp + value: + stringValue: 2024-03-05T17:30:42.569-0500 + observedTimeUnixNano: "1709677842727442000" + severityNumber: 5 + severityText: debug + spanId: "" + timeUnixNano: "1706791445193459839" + traceId: "" + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: logger + value: + stringValue: opamp + - key: message + value: + stringValue: sending response to the agent + - key: span_id + value: + stringValue: "0000000000000000" + - key: trace_id + value: + stringValue: "00000000000000000000000000000000" + - key: bindplane.agent.id + value: + stringValue: 01HQRTG9AFXV1VCV1TS0Z0942T + - key: components + value: + arrayValue: {} + - key: level + value: + stringValue: debug + - key: timestamp + value: + stringValue: 2024-03-05T17:30:42.581-0500 + observedTimeUnixNano: "1709677842746558000" + severityNumber: 5 + severityText: debug + spanId: "" + timeUnixNano: "1706791445205459839" + traceId: "" + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: message + value: + stringValue: OnMessage release + - key: span_id + value: + stringValue: "0000000000000000" + - key: trace_id + value: + stringValue: "00000000000000000000000000000000" + - key: bindplane.agent.id + value: + stringValue: 01HQRTG9AFXV1VCV1TS0Z0942T + - key: level + value: + stringValue: debug + - key: timestamp + value: + stringValue: 2024-03-05T17:30:42.581-0500 + - key: logger + value: + stringValue: opamp + observedTimeUnixNano: "1709677842746572000" + severityNumber: 5 + severityText: debug + spanId: "" + timeUnixNano: "1706791445205459839" + traceId: "" + scope: {} + - resource: + attributes: + - key: host.name + value: + stringValue: Sams-M1-Pro.local + - key: os.type + value: + stringValue: darwin + scopeLogs: + - logRecords: + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: logger + value: + stringValue: opamp + - key: message + value: + stringValue: agent running with the correct config + - key: bindplane.agent.id + value: + stringValue: 01HQRTG9AFXV1VCV1TS0Z0942T + - key: bindplane.configuration.name + value: + stringValue: test-new:31 + - key: level + value: + stringValue: debug + - key: timestamp + value: + stringValue: 2024-03-05T17:30:42.569-0500 + observedTimeUnixNano: "1709677842727442000" + severityNumber: 5 + severityText: debug + spanId: "" + timeUnixNano: "1706791445193459839" + traceId: "" + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: logger + value: + stringValue: opamp + - key: message + value: + stringValue: sending response to the agent + - key: span_id + value: + stringValue: "0000000000000000" + - key: trace_id + value: + stringValue: "00000000000000000000000000000000" + - key: bindplane.agent.id + value: + stringValue: 01HQRTG9AFXV1VCV1TS0Z0942T + - key: components + value: + arrayValue: {} + - key: level + value: + stringValue: debug + - key: timestamp + value: + stringValue: 2024-03-05T17:30:42.581-0500 + observedTimeUnixNano: "1709677842746558000" + severityNumber: 5 + severityText: debug + spanId: "" + timeUnixNano: "1706791445205459839" + traceId: "" + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: message + value: + stringValue: OnMessage release + - key: span_id + value: + stringValue: "0000000000000000" + - key: trace_id + value: + stringValue: "00000000000000000000000000000000" + - key: bindplane.agent.id + value: + stringValue: 01HQRTG9AFXV1VCV1TS0Z0942T + - key: level + value: + stringValue: debug + - key: timestamp + value: + stringValue: 2024-03-05T17:30:42.581-0500 + - key: logger + value: + stringValue: opamp + observedTimeUnixNano: "1709677842746572000" + severityNumber: 5 + severityText: debug + spanId: "" + timeUnixNano: "1706791445205459839" + traceId: "" + scope: {} + - resource: + attributes: + - key: host.name + value: + stringValue: Sams-M1-Pro.local + - key: os.type + value: + stringValue: darwin + scopeLogs: + - logRecords: + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: latency + value: + doubleValue: 0.029674834 + - key: status + value: + doubleValue: 200 + - key: path + value: + stringValue: /v1/graphql + - key: level + value: + stringValue: info + - key: message + value: + stringValue: /v1/graphql + - key: ip + value: + stringValue: 127.0.0.1 + - key: user-agent + value: + stringValue: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0 + - key: timestamp + value: + stringValue: 2024-03-05T17:30:42.785-0500 + - key: method + value: + stringValue: POST + - key: query + value: + stringValue: "" + observedTimeUnixNano: "1709677842925856000" + severityNumber: 9 + severityText: info + spanId: "" + timeUnixNano: "1706791445409459839" + traceId: "" + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: timestamp + value: + stringValue: 2024-03-05T17:30:42.878-0500 + - key: message + value: + stringValue: Rollout complete + - key: bindplane.configuration.name + value: + stringValue: test-new:31 + - key: duration + value: + doubleValue: 1.313709 + - key: level + value: + stringValue: info + observedTimeUnixNano: "1709677842926280000" + severityNumber: 9 + severityText: info + spanId: "" + timeUnixNano: "1706791445502459839" + traceId: "" + scope: {} + - resource: + attributes: + - key: host.name + value: + stringValue: Sams-M1-Pro.local + - key: os.type + value: + stringValue: darwin + scopeLogs: + - logRecords: + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: latency + value: + doubleValue: 0.029674834 + - key: status + value: + doubleValue: 200 + - key: path + value: + stringValue: /v1/graphql + - key: level + value: + stringValue: info + - key: message + value: + stringValue: /v1/graphql + - key: ip + value: + stringValue: 127.0.0.1 + - key: user-agent + value: + stringValue: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0 + - key: timestamp + value: + stringValue: 2024-03-05T17:30:42.785-0500 + - key: method + value: + stringValue: POST + - key: query + value: + stringValue: "" + observedTimeUnixNano: "1709677842925856000" + severityNumber: 9 + severityText: info + spanId: "" + timeUnixNano: "1706791445409459839" + traceId: "" + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: timestamp + value: + stringValue: 2024-03-05T17:30:42.878-0500 + - key: message + value: + stringValue: Rollout complete + - key: bindplane.configuration.name + value: + stringValue: test-new:31 + - key: duration + value: + doubleValue: 1.313709 + - key: level + value: + stringValue: info + observedTimeUnixNano: "1709677842926280000" + severityNumber: 9 + severityText: info + spanId: "" + timeUnixNano: "1706791445502459839" + traceId: "" + scope: {} + - resource: + attributes: + - key: host.name + value: + stringValue: Sams-M1-Pro.local + - key: os.type + value: + stringValue: darwin + scopeLogs: + - logRecords: + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: user-agent + value: + stringValue: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0 + - key: message + value: + stringValue: /v1/graphql + - key: latency + value: + doubleValue: 0.026624375 + - key: ip + value: + stringValue: 127.0.0.1 + - key: timestamp + value: + stringValue: 2024-03-05T17:30:43.112-0500 + - key: method + value: + stringValue: POST + - key: query + value: + stringValue: "" + - key: level + value: + stringValue: info + - key: status + value: + doubleValue: 200 + - key: path + value: + stringValue: /v1/graphql + observedTimeUnixNano: "1709677843135879000" + severityNumber: 9 + severityText: info + spanId: "" + timeUnixNano: "1706791445736459839" + traceId: "" + scope: {} + - resource: + attributes: + - key: host.name + value: + stringValue: Sams-M1-Pro.local + - key: os.type + value: + stringValue: darwin + scopeLogs: + - logRecords: + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: user-agent + value: + stringValue: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0 + - key: message + value: + stringValue: /v1/graphql + - key: latency + value: + doubleValue: 0.026624375 + - key: ip + value: + stringValue: 127.0.0.1 + - key: timestamp + value: + stringValue: 2024-03-05T17:30:43.112-0500 + - key: method + value: + stringValue: POST + - key: query + value: + stringValue: "" + - key: level + value: + stringValue: info + - key: status + value: + doubleValue: 200 + - key: path + value: + stringValue: /v1/graphql + observedTimeUnixNano: "1709677843135879000" + severityNumber: 9 + severityText: info + spanId: "" + timeUnixNano: "1706791445736459839" + traceId: "" + scope: {} + - resource: + attributes: + - key: host.name + value: + stringValue: Sams-M1-Pro.local + - key: os.type + value: + stringValue: darwin + scopeLogs: + - logRecords: + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: path + value: + stringValue: /v1/graphql + - key: latency + value: + doubleValue: 0.016023542 + - key: query + value: + stringValue: "" + - key: ip + value: + stringValue: 127.0.0.1 + - key: user-agent + value: + stringValue: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0 + - key: level + value: + stringValue: info + - key: method + value: + stringValue: POST + - key: status + value: + doubleValue: 200 + - key: message + value: + stringValue: /v1/graphql + - key: timestamp + value: + stringValue: 2024-03-05T17:30:43.239-0500 + observedTimeUnixNano: "1709677843334008000" + severityNumber: 9 + severityText: info + spanId: "" + timeUnixNano: "1706791445863459839" + traceId: "" + scope: {} + - resource: + attributes: + - key: host.name + value: + stringValue: Sams-M1-Pro.local + - key: os.type + value: + stringValue: darwin + scopeLogs: + - logRecords: + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: path + value: + stringValue: /v1/graphql + - key: latency + value: + doubleValue: 0.016023542 + - key: query + value: + stringValue: "" + - key: ip + value: + stringValue: 127.0.0.1 + - key: user-agent + value: + stringValue: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:124.0) Gecko/20100101 Firefox/124.0 + - key: level + value: + stringValue: info + - key: method + value: + stringValue: POST + - key: status + value: + doubleValue: 200 + - key: message + value: + stringValue: /v1/graphql + - key: timestamp + value: + stringValue: 2024-03-05T17:30:43.239-0500 + observedTimeUnixNano: "1709677843334008000" + severityNumber: 9 + severityText: info + spanId: "" + timeUnixNano: "1706791445863459839" + traceId: "" + scope: {} + - resource: + attributes: + - key: host.name + value: + stringValue: Sams-M1-Pro.local + - key: os.type + value: + stringValue: darwin + scopeLogs: + - logRecords: + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: path + value: + stringValue: /v1/agents/01HQRTG9AFXV1VCV1TS0Z0942T/health/v1/metrics + - key: user-agent + value: + stringValue: observIQ's opentelemetry-collector distribution/v1.45.0 (darwin/arm64) + - key: latency + value: + doubleValue: 0.000155209 + - key: timestamp + value: + stringValue: 2024-03-05T17:30:43.375-0500 + - key: message + value: + stringValue: /v1/agents/01HQRTG9AFXV1VCV1TS0Z0942T/health/v1/metrics + - key: status + value: + doubleValue: 200 + - key: level + value: + stringValue: info + - key: method + value: + stringValue: POST + - key: query + value: + stringValue: "" + - key: ip + value: + stringValue: 127.0.0.1 + observedTimeUnixNano: "1709677843525540000" + severityNumber: 9 + severityText: info + spanId: "" + timeUnixNano: "1706791445999459839" + traceId: "" + scope: {} + - resource: + attributes: + - key: host.name + value: + stringValue: Sams-M1-Pro.local + - key: os.type + value: + stringValue: darwin + scopeLogs: + - logRecords: + - attributes: + - key: log.file.name + value: + stringValue: bindplane.log + - key: log_type + value: + stringValue: bindplane-op + body: + kvlistValue: + values: + - key: path + value: + stringValue: /v1/agents/01HQRTG9AFXV1VCV1TS0Z0942T/health/v1/metrics + - key: user-agent + value: + stringValue: observIQ's opentelemetry-collector distribution/v1.45.0 (darwin/arm64) + - key: latency + value: + doubleValue: 0.000155209 + - key: timestamp + value: + stringValue: 2024-03-05T17:30:43.375-0500 + - key: message + value: + stringValue: /v1/agents/01HQRTG9AFXV1VCV1TS0Z0942T/health/v1/metrics + - key: status + value: + doubleValue: 200 + - key: level + value: + stringValue: info + - key: method + value: + stringValue: POST + - key: query + value: + stringValue: "" + - key: ip + value: + stringValue: 127.0.0.1 + observedTimeUnixNano: "1709677843525540000" + severityNumber: 9 + severityText: info + spanId: "" + timeUnixNano: "1706791445999459839" + traceId: "" + scope: {} diff --git a/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/logs/postgres_logs.yaml b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/logs/postgres_logs.yaml new file mode 100644 index 000000000..84d02c514 --- /dev/null +++ b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/logs/postgres_logs.yaml @@ -0,0 +1,779 @@ +resourceLogs: + - resource: + attributes: + - key: host.name + value: + stringValue: Sams-M1-Pro.local + - key: os.type + value: + stringValue: darwin + scopeLogs: + - logRecords: + - attributes: + - key: tid + value: + stringValue: "8334" + - key: role + value: + stringValue: "" + - key: user + value: + stringValue: "" + - key: level + value: + stringValue: LOG + - key: message + value: + stringValue: 'statement: COMMIT' + - key: log_type + value: + stringValue: postgresql.general + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.097 EST + - key: sql_command + value: + stringValue: COMMIT + - key: duration + value: + stringValue: "" + - key: statement + value: + stringValue: COMMIT + body: + stringValue: '2024-03-05 17:25:36.097 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536223996000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445937459839" + traceId: "" + - attributes: + - key: sql_command + value: + stringValue: COMMIT + - key: log_type + value: + stringValue: postgresql.general + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.111 EST + - key: role + value: + stringValue: "" + - key: level + value: + stringValue: LOG + - key: message + value: + stringValue: 'statement: COMMIT' + - key: tid + value: + stringValue: "8334" + - key: user + value: + stringValue: "" + - key: duration + value: + stringValue: "" + - key: statement + value: + stringValue: COMMIT + body: + stringValue: '2024-03-05 17:25:36.111 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224110000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445951459839" + traceId: "" + - attributes: + - key: message + value: + stringValue: 'statement: COMMIT' + - key: sql_command + value: + stringValue: COMMIT + - key: log_type + value: + stringValue: postgresql.general + - key: user + value: + stringValue: "" + - key: level + value: + stringValue: LOG + - key: duration + value: + stringValue: "" + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.113 EST + - key: tid + value: + stringValue: "8334" + - key: statement + value: + stringValue: COMMIT + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: role + value: + stringValue: "" + body: + stringValue: '2024-03-05 17:25:36.113 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224164000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445953459839" + traceId: "" + - attributes: + - key: sql_command + value: + stringValue: COMMIT + - key: duration + value: + stringValue: "" + - key: role + value: + stringValue: "" + - key: statement + value: + stringValue: COMMIT + - key: level + value: + stringValue: LOG + - key: message + value: + stringValue: 'statement: COMMIT' + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.126 EST + - key: tid + value: + stringValue: "8334" + - key: log_type + value: + stringValue: postgresql.general + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: user + value: + stringValue: "" + body: + stringValue: '2024-03-05 17:25:36.126 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224300000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445966459839" + traceId: "" + - attributes: + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: level + value: + stringValue: LOG + - key: message + value: + stringValue: 'statement: COMMIT' + - key: duration + value: + stringValue: "" + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.149 EST + - key: role + value: + stringValue: "" + - key: user + value: + stringValue: "" + - key: log_type + value: + stringValue: postgresql.general + - key: sql_command + value: + stringValue: COMMIT + - key: statement + value: + stringValue: COMMIT + - key: tid + value: + stringValue: "8334" + body: + stringValue: '2024-03-05 17:25:36.149 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224359000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445989459839" + traceId: "" + - attributes: + - key: role + value: + stringValue: "" + - key: message + value: + stringValue: 'statement: COMMIT' + - key: statement + value: + stringValue: COMMIT + - key: sql_command + value: + stringValue: COMMIT + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: tid + value: + stringValue: "8334" + - key: user + value: + stringValue: "" + - key: level + value: + stringValue: LOG + - key: duration + value: + stringValue: "" + - key: log_type + value: + stringValue: postgresql.general + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.151 EST + body: + stringValue: '2024-03-05 17:25:36.151 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224466000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445991459839" + traceId: "" + - attributes: + - key: role + value: + stringValue: "" + - key: duration + value: + stringValue: "" + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.154 EST + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: tid + value: + stringValue: "8334" + - key: user + value: + stringValue: "" + - key: level + value: + stringValue: LOG + - key: message + value: + stringValue: 'statement: COMMIT' + - key: statement + value: + stringValue: COMMIT + - key: sql_command + value: + stringValue: COMMIT + - key: log_type + value: + stringValue: postgresql.general + body: + stringValue: '2024-03-05 17:25:36.154 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224517000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445994459839" + traceId: "" + - attributes: + - key: log_type + value: + stringValue: postgresql.general + - key: duration + value: + stringValue: "" + - key: user + value: + stringValue: "" + - key: statement + value: + stringValue: COMMIT + - key: sql_command + value: + stringValue: COMMIT + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: level + value: + stringValue: LOG + - key: message + value: + stringValue: 'statement: COMMIT' + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.157 EST + - key: tid + value: + stringValue: "8334" + - key: role + value: + stringValue: "" + body: + stringValue: '2024-03-05 17:25:36.157 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224635000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445997459839" + traceId: "" + - attributes: + - key: tid + value: + stringValue: "8334" + - key: role + value: + stringValue: "" + - key: level + value: + stringValue: LOG + - key: message + value: + stringValue: 'statement: COMMIT' + - key: duration + value: + stringValue: "" + - key: statement + value: + stringValue: COMMIT + - key: sql_command + value: + stringValue: COMMIT + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.159 EST + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: user + value: + stringValue: "" + - key: log_type + value: + stringValue: postgresql.general + body: + stringValue: '2024-03-05 17:25:36.159 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224688000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445999459839" + traceId: "" + scope: {} + - resource: + attributes: + - key: host.name + value: + stringValue: Sams-M1-Pro.local + - key: os.type + value: + stringValue: darwin + scopeLogs: + - logRecords: + - attributes: + - key: tid + value: + stringValue: "8334" + - key: role + value: + stringValue: "" + - key: user + value: + stringValue: "" + - key: level + value: + stringValue: LOG + - key: message + value: + stringValue: 'statement: COMMIT' + - key: log_type + value: + stringValue: postgresql.general + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.097 EST + - key: sql_command + value: + stringValue: COMMIT + - key: duration + value: + stringValue: "" + - key: statement + value: + stringValue: COMMIT + body: + stringValue: '2024-03-05 17:25:36.097 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536223996000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445937459839" + traceId: "" + - attributes: + - key: sql_command + value: + stringValue: COMMIT + - key: log_type + value: + stringValue: postgresql.general + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.111 EST + - key: role + value: + stringValue: "" + - key: level + value: + stringValue: LOG + - key: message + value: + stringValue: 'statement: COMMIT' + - key: tid + value: + stringValue: "8334" + - key: user + value: + stringValue: "" + - key: duration + value: + stringValue: "" + - key: statement + value: + stringValue: COMMIT + body: + stringValue: '2024-03-05 17:25:36.111 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224110000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445951459839" + traceId: "" + - attributes: + - key: message + value: + stringValue: 'statement: COMMIT' + - key: sql_command + value: + stringValue: COMMIT + - key: log_type + value: + stringValue: postgresql.general + - key: user + value: + stringValue: "" + - key: level + value: + stringValue: LOG + - key: duration + value: + stringValue: "" + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.113 EST + - key: tid + value: + stringValue: "8334" + - key: statement + value: + stringValue: COMMIT + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: role + value: + stringValue: "" + body: + stringValue: '2024-03-05 17:25:36.113 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224164000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445953459839" + traceId: "" + - attributes: + - key: sql_command + value: + stringValue: COMMIT + - key: duration + value: + stringValue: "" + - key: role + value: + stringValue: "" + - key: statement + value: + stringValue: COMMIT + - key: level + value: + stringValue: LOG + - key: message + value: + stringValue: 'statement: COMMIT' + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.126 EST + - key: tid + value: + stringValue: "8334" + - key: log_type + value: + stringValue: postgresql.general + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: user + value: + stringValue: "" + body: + stringValue: '2024-03-05 17:25:36.126 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224300000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445966459839" + traceId: "" + - attributes: + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: level + value: + stringValue: LOG + - key: message + value: + stringValue: 'statement: COMMIT' + - key: duration + value: + stringValue: "" + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.149 EST + - key: role + value: + stringValue: "" + - key: user + value: + stringValue: "" + - key: log_type + value: + stringValue: postgresql.general + - key: sql_command + value: + stringValue: COMMIT + - key: statement + value: + stringValue: COMMIT + - key: tid + value: + stringValue: "8334" + body: + stringValue: '2024-03-05 17:25:36.149 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224359000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445989459839" + traceId: "" + - attributes: + - key: role + value: + stringValue: "" + - key: message + value: + stringValue: 'statement: COMMIT' + - key: statement + value: + stringValue: COMMIT + - key: sql_command + value: + stringValue: COMMIT + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: tid + value: + stringValue: "8334" + - key: user + value: + stringValue: "" + - key: level + value: + stringValue: LOG + - key: duration + value: + stringValue: "" + - key: log_type + value: + stringValue: postgresql.general + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.151 EST + body: + stringValue: '2024-03-05 17:25:36.151 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224466000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445991459839" + traceId: "" + - attributes: + - key: role + value: + stringValue: "" + - key: duration + value: + stringValue: "" + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.154 EST + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: tid + value: + stringValue: "8334" + - key: user + value: + stringValue: "" + - key: level + value: + stringValue: LOG + - key: message + value: + stringValue: 'statement: COMMIT' + - key: statement + value: + stringValue: COMMIT + - key: sql_command + value: + stringValue: COMMIT + - key: log_type + value: + stringValue: postgresql.general + body: + stringValue: '2024-03-05 17:25:36.154 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224517000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445994459839" + traceId: "" + - attributes: + - key: log_type + value: + stringValue: postgresql.general + - key: duration + value: + stringValue: "" + - key: user + value: + stringValue: "" + - key: statement + value: + stringValue: COMMIT + - key: sql_command + value: + stringValue: COMMIT + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: level + value: + stringValue: LOG + - key: message + value: + stringValue: 'statement: COMMIT' + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.157 EST + - key: tid + value: + stringValue: "8334" + - key: role + value: + stringValue: "" + body: + stringValue: '2024-03-05 17:25:36.157 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224635000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445997459839" + traceId: "" + - attributes: + - key: tid + value: + stringValue: "8334" + - key: role + value: + stringValue: "" + - key: level + value: + stringValue: LOG + - key: message + value: + stringValue: 'statement: COMMIT' + - key: duration + value: + stringValue: "" + - key: statement + value: + stringValue: COMMIT + - key: sql_command + value: + stringValue: COMMIT + - key: timestamp + value: + stringValue: 2024-03-05 17:25:36.159 EST + - key: log.file.name + value: + stringValue: postgresql-2024-03-05_172300.log + - key: user + value: + stringValue: "" + - key: log_type + value: + stringValue: postgresql.general + body: + stringValue: '2024-03-05 17:25:36.159 EST [8334] LOG: statement: COMMIT' + observedTimeUnixNano: "1709677536224688000" + severityNumber: 9 + severityText: LOG + spanId: "" + timeUnixNano: "1706791445999459839" + traceId: "" + scope: {} diff --git a/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/exp_histogram.yaml b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/exp_histogram.yaml new file mode 100644 index 000000000..ab4f7c752 --- /dev/null +++ b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/exp_histogram.yaml @@ -0,0 +1,17 @@ +resourceMetrics: + - resource: {} + scopeMetrics: + - metrics: + - exponentialHistogram: + dataPoints: + - attributes: + - key: prod-machine + value: + stringValue: prod-1 + count: "4" + max: 100 + min: 0 + negative: {} + positive: {} + timeUnixNano: "1706791445999459839" + scope: {} diff --git a/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/gauge.yaml b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/gauge.yaml new file mode 100644 index 000000000..14460519b --- /dev/null +++ b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/gauge.yaml @@ -0,0 +1,27 @@ +resourceMetrics: + - resource: + attributes: + - key: extra-resource-attr-key + value: + stringValue: extra-resource-attr-value + - key: host.name + value: + stringValue: Linux-Machine + - key: os.type + value: + stringValue: linux + scopeMetrics: + - metrics: + - description: Average CPU Load over 1 minute. + gauge: + dataPoints: + - asDouble: 3.71484375 + attributes: + - key: cool-attribute-key + value: + stringValue: cool-attribute-value + startTimeUnixNano: "1000000" + timeUnixNano: "1706791445999459839" + name: system.cpu.load_average.1m + unit: '{thread}' + scope: {} diff --git a/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/histogram.yaml b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/histogram.yaml new file mode 100644 index 000000000..726bf10e6 --- /dev/null +++ b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/histogram.yaml @@ -0,0 +1,23 @@ +resourceMetrics: + - resource: {} + scopeMetrics: + - metrics: + - histogram: + dataPoints: + - attributes: + - key: prod-machine + value: + stringValue: prod-1 + bucketCounts: + - "0" + - "2" + - "2" + count: "4" + explicitBounds: + - 0 + - 50 + - 100 + max: 100 + min: 0 + timeUnixNano: "1706791445999459839" + scope: {} diff --git a/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/sum.yaml b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/sum.yaml new file mode 100644 index 000000000..e46e60250 --- /dev/null +++ b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/sum.yaml @@ -0,0 +1,39 @@ +resourceMetrics: + - resource: + attributes: + - key: host.name + value: + stringValue: Sams-MBP + - key: os.type + value: + stringValue: darwin + scopeMetrics: + - metrics: + - description: Filesystem bytes used. + name: system.filesystem.usage + sum: + dataPoints: + - asInt: "8717185024" + attributes: + - key: device + value: + stringValue: /dev/disk4s1 + - key: extra-sum-attr-key + value: + stringValue: extra-sum-attr-value + - key: mode + value: + stringValue: rw + - key: mountpoint + value: + stringValue: /Volumes/transfer + - key: state + value: + stringValue: free + - key: type + value: + stringValue: hfs + startTimeUnixNano: "1000000" + timeUnixNano: "1706791445999459839" + unit: By + scope: {} diff --git a/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/summary.yaml b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/summary.yaml new file mode 100644 index 000000000..8c9fd13de --- /dev/null +++ b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/metrics/summary.yaml @@ -0,0 +1,14 @@ +resourceMetrics: + - resource: {} + scopeMetrics: + - metrics: + - summary: + dataPoints: + - attributes: + - key: prod-machine + value: + stringValue: prod-1 + count: "4" + sum: 111 + timeUnixNano: "1706791445999459839" + scope: {} diff --git a/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/traces/bpop_traces.yaml b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/traces/bpop_traces.yaml new file mode 100644 index 000000000..a4b15286f --- /dev/null +++ b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/traces/bpop_traces.yaml @@ -0,0 +1,266 @@ +resourceSpans: + - resource: + attributes: + - key: host.arch + value: + stringValue: arm64 + - key: host.name + value: + stringValue: Sams-M1-Pro.local + - key: service.name + value: + stringValue: bindplane + - key: service.version + value: + stringValue: unknown + scopeSpans: + - scope: {} + spans: + - endTimeUnixNano: "1706791445927702458" + kind: 1 + name: pgstore/addTransitiveUpdates + parentSpanId: b6e1d82a58e8fd61 + spanId: 5a055056ad7713e5 + startTimeUnixNano: "1706791445927700000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445927704250" + kind: 1 + name: pgstore/notify + parentSpanId: 38ff7d679d77bdbd + spanId: b6e1d82a58e8fd61 + startTimeUnixNano: "1706791445927698000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445973101000" + kind: 1 + name: pgstore/scanPostgresResource + parentSpanId: 804ce3fb1b57be5d + spanId: 3eadb90414f2cf22 + startTimeUnixNano: "1706791445971633000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445973109084" + kind: 1 + name: pgstore/pgResourceInternal + parentSpanId: 5236aa938eb9341c + spanId: 804ce3fb1b57be5d + startTimeUnixNano: "1706791445962593000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445973110334" + kind: 1 + name: pgstore/pgResource + parentSpanId: ca3b8e53681a9e8d + spanId: 5236aa938eb9341c + startTimeUnixNano: "1706791445962592000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445973258875" + kind: 1 + name: pgstore/pgEditConfiguration + parentSpanId: a894c9beda2d173a + spanId: ca3b8e53681a9e8d + startTimeUnixNano: "1706791445962589000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445973576917" + kind: 1 + name: pgstore/addTransitiveUpdates + parentSpanId: 94557eef510d0814 + spanId: c3ea8f993f9009ba + startTimeUnixNano: "1706791445973575000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445973579333" + kind: 1 + name: pgstore/notify + parentSpanId: a894c9beda2d173a + spanId: 94557eef510d0814 + startTimeUnixNano: "1706791445973572000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445975115042" + kind: 1 + name: pgstore/releaseAdvisoryLock + parentSpanId: a894c9beda2d173a + spanId: 8906c43abedb6bd9 + startTimeUnixNano: "1706791445973581000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445975119416" + kind: 1 + name: pgstore/UpdateRollout + parentSpanId: 9d5a7e824fa7ba3b + spanId: a894c9beda2d173a + startTimeUnixNano: "1706791445937536000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445975734417" + kind: 1 + name: pgstore/acquireAdvisoryLock + parentSpanId: 078ab0ab7eb707b2 + spanId: f141ff98614cfc0c + startTimeUnixNano: "1706791445975133000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445979767041" + kind: 1 + name: pgstore/scanPostgresResource + parentSpanId: f06908731ed62890 + spanId: e185a7e1c60473b8 + startTimeUnixNano: "1706791445976351000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445979799208" + kind: 1 + name: pgstore/pgResourceInternal + parentSpanId: 078ab0ab7eb707b2 + spanId: f06908731ed62890 + startTimeUnixNano: "1706791445975818000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445999459125" + kind: 1 + name: pgstore/UpdateAllRollouts + parentSpanId: "" + spanId: aeb2a416b8796cba + startTimeUnixNano: "1706791445908223000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - scope: {} + spans: + - attributes: + - key: operation + value: + stringValue: GetConfiguration + endTimeUnixNano: "1706791445376564375" + kind: 1 + name: graphql/GetConfiguration/response + parentSpanId: 723c3f6eb4457b5c + spanId: fd55f461239efdfc + startTimeUnixNano: "1706791445359466000" + status: {} + traceId: a3fbd5dc5db5e1734cb54419ca540b66 + - attributes: + - key: operation + value: + stringValue: GetConfiguration + endTimeUnixNano: "1706791445376589750" + kind: 1 + name: graphql/GetConfiguration/response + parentSpanId: 3e7909bbebcae0ba + spanId: 01f07757e7bb6612 + startTimeUnixNano: "1706791445359560000" + status: {} + traceId: d70c2b5eea8977bb8a0712f8c2a1fcb4 + - scope: {} + spans: + - attributes: + - key: http.method + value: + stringValue: POST + - key: http.scheme + value: + stringValue: http + - key: net.host.name + value: + stringValue: bindplane + - key: net.host.port + value: + intValue: "3001" + - key: net.sock.peer.addr + value: + stringValue: 127.0.0.1 + - key: net.sock.peer.port + value: + intValue: "50141" + - key: user_agent.original + value: + stringValue: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0 + - key: http.client_ip + value: + stringValue: 127.0.0.1 + - key: http.target + value: + stringValue: /v1/graphql + - key: net.protocol.version + value: + stringValue: "1.1" + - key: http.route + value: + stringValue: /v1/graphql + - key: http.status_code + value: + intValue: "200" + endTimeUnixNano: "1706791445376694750" + kind: 2 + name: /v1/graphql + parentSpanId: "" + spanId: 723c3f6eb4457b5c + startTimeUnixNano: "1706791445332980000" + status: {} + traceId: a3fbd5dc5db5e1734cb54419ca540b66 + - attributes: + - key: http.method + value: + stringValue: POST + - key: http.scheme + value: + stringValue: http + - key: net.host.name + value: + stringValue: bindplane + - key: net.host.port + value: + intValue: "3001" + - key: net.sock.peer.addr + value: + stringValue: 127.0.0.1 + - key: net.sock.peer.port + value: + intValue: "50140" + - key: user_agent.original + value: + stringValue: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0 + - key: http.client_ip + value: + stringValue: 127.0.0.1 + - key: http.target + value: + stringValue: /v1/graphql + - key: net.protocol.version + value: + stringValue: "1.1" + - key: http.route + value: + stringValue: /v1/graphql + - key: http.status_code + value: + intValue: "200" + endTimeUnixNano: "1706791445376708291" + kind: 2 + name: /v1/graphql + parentSpanId: "" + spanId: 3e7909bbebcae0ba + startTimeUnixNano: "1706791445332972000" + status: {} + traceId: d70c2b5eea8977bb8a0712f8c2a1fcb4 + - scope: {} + spans: + - endTimeUnixNano: "1706791445913878000" + kind: 1 + name: pgindex/Suggestions + parentSpanId: 9d5a7e824fa7ba3b + spanId: 4c2049c4cd14c987 + startTimeUnixNano: "1706791445912675000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445997017791" + kind: 1 + name: pgindex/Suggestions + parentSpanId: 96ae55c03e5146b3 + spanId: aa69c45bc0970c2f + startTimeUnixNano: "1706791445996229000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 diff --git a/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/traces/bpop_traces2.yaml b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/traces/bpop_traces2.yaml new file mode 100644 index 000000000..ac14c99c3 --- /dev/null +++ b/receiver/telemetrygeneratorreceiver/testdata/expected_otlp/traces/bpop_traces2.yaml @@ -0,0 +1,240 @@ +resourceSpans: + - resource: + attributes: + - key: host.arch + value: + stringValue: arm64 + - key: host.name + value: + stringValue: Sams-M1-Pro.local + - key: service.name + value: + stringValue: bindplane + - key: service.version + value: + stringValue: unknown + scopeSpans: + - scope: {} + spans: + - endTimeUnixNano: "1706791445927702458" + kind: 1 + name: pgstore/addTransitiveUpdates + parentSpanId: b6e1d82a58e8fd61 + spanId: 5a055056ad7713e5 + startTimeUnixNano: "1706791445927700000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445927704250" + kind: 1 + name: pgstore/notify + parentSpanId: 38ff7d679d77bdbd + spanId: b6e1d82a58e8fd61 + startTimeUnixNano: "1706791445927698000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445973101000" + kind: 1 + name: pgstore/scanPostgresResource + parentSpanId: 804ce3fb1b57be5d + spanId: 3eadb90414f2cf22 + startTimeUnixNano: "1706791445971633000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445973109084" + kind: 1 + name: pgstore/pgResourceInternal + parentSpanId: 5236aa938eb9341c + spanId: 804ce3fb1b57be5d + startTimeUnixNano: "1706791445962593000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445973110334" + kind: 1 + name: pgstore/pgResource + parentSpanId: ca3b8e53681a9e8d + spanId: 5236aa938eb9341c + startTimeUnixNano: "1706791445962592000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445973258875" + kind: 1 + name: pgstore/pgEditConfiguration + parentSpanId: a894c9beda2d173a + spanId: ca3b8e53681a9e8d + startTimeUnixNano: "1706791445962589000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445973576917" + kind: 1 + name: pgstore/addTransitiveUpdates + parentSpanId: 94557eef510d0814 + spanId: c3ea8f993f9009ba + startTimeUnixNano: "1706791445973575000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445973579333" + kind: 1 + name: pgstore/notify + parentSpanId: a894c9beda2d173a + spanId: 94557eef510d0814 + startTimeUnixNano: "1706791445973572000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445975115042" + kind: 1 + name: pgstore/releaseAdvisoryLock + parentSpanId: a894c9beda2d173a + spanId: 8906c43abedb6bd9 + startTimeUnixNano: "1706791445973581000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445975119416" + kind: 1 + name: pgstore/UpdateRollout + parentSpanId: 9d5a7e824fa7ba3b + spanId: a894c9beda2d173a + startTimeUnixNano: "1706791445937536000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445975734417" + kind: 1 + name: pgstore/acquireAdvisoryLock + parentSpanId: 078ab0ab7eb707b2 + spanId: f141ff98614cfc0c + startTimeUnixNano: "1706791445975133000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445979767041" + kind: 1 + name: pgstore/scanPostgresResource + parentSpanId: f06908731ed62890 + spanId: e185a7e1c60473b8 + startTimeUnixNano: "1706791445976351000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445979799208" + kind: 1 + name: pgstore/pgResourceInternal + parentSpanId: 078ab0ab7eb707b2 + spanId: f06908731ed62890 + startTimeUnixNano: "1706791445975818000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445999459839" + kind: 1 + name: pgstore/UpdateAllRollouts + parentSpanId: "" + spanId: aeb2a416b8796cba + startTimeUnixNano: "1706791445908223000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - scope: {} + spans: + - attributes: + - key: http.method + value: + stringValue: POST + - key: http.scheme + value: + stringValue: http + - key: net.host.name + value: + stringValue: bindplane + - key: net.host.port + value: + intValue: "3001" + - key: net.sock.peer.addr + value: + stringValue: 127.0.0.1 + - key: net.sock.peer.port + value: + intValue: "50141" + - key: user_agent.original + value: + stringValue: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0 + - key: http.client_ip + value: + stringValue: 127.0.0.1 + - key: http.target + value: + stringValue: /v1/graphql + - key: net.protocol.version + value: + stringValue: "1.1" + - key: http.route + value: + stringValue: /v1/graphql + - key: http.status_code + value: + intValue: "200" + endTimeUnixNano: "1706791445376694750" + kind: 2 + name: /v1/graphql + parentSpanId: "" + spanId: 723c3f6eb4457b5c + startTimeUnixNano: "1706791445332980000" + status: {} + traceId: a3fbd5dc5db5e1734cb54419ca540b66 + - attributes: + - key: http.method + value: + stringValue: POST + - key: http.scheme + value: + stringValue: http + - key: net.host.name + value: + stringValue: bindplane + - key: net.host.port + value: + intValue: "3001" + - key: net.sock.peer.addr + value: + stringValue: 127.0.0.1 + - key: net.sock.peer.port + value: + intValue: "50140" + - key: user_agent.original + value: + stringValue: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0 + - key: http.client_ip + value: + stringValue: 127.0.0.1 + - key: http.target + value: + stringValue: /v1/graphql + - key: net.protocol.version + value: + stringValue: "1.1" + - key: http.route + value: + stringValue: /v1/graphql + - key: http.status_code + value: + intValue: "200" + endTimeUnixNano: "1706791445376708291" + kind: 2 + name: /v1/graphql + parentSpanId: "" + spanId: 3e7909bbebcae0ba + startTimeUnixNano: "1706791445332972000" + status: {} + traceId: d70c2b5eea8977bb8a0712f8c2a1fcb4 + - scope: {} + spans: + - endTimeUnixNano: "1706791445913878000" + kind: 1 + name: pgindex/Suggestions + parentSpanId: 9d5a7e824fa7ba3b + spanId: 4c2049c4cd14c987 + startTimeUnixNano: "1706791445912675000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 + - endTimeUnixNano: "1706791445997017791" + kind: 1 + name: pgindex/Suggestions + parentSpanId: 96ae55c03e5146b3 + spanId: aa69c45bc0970c2f + startTimeUnixNano: "1706791445996229000" + status: {} + traceId: c7f3bb6aa9e7a7dce92d85d1566f2c31 diff --git a/receiver/telemetrygeneratorreceiver/traces_receiver.go b/receiver/telemetrygeneratorreceiver/traces_receiver.go index faa022d3b..83f8b5739 100644 --- a/receiver/telemetrygeneratorreceiver/traces_receiver.go +++ b/receiver/telemetrygeneratorreceiver/traces_receiver.go @@ -18,6 +18,7 @@ import ( "context" "go.opentelemetry.io/collector/consumer" + "go.opentelemetry.io/collector/pdata/ptrace" "go.uber.org/zap" ) @@ -41,7 +42,15 @@ func newTracesReceiver(ctx context.Context, logger *zap.Logger, cfg *Config, nex return tr } -// TODO implement produce for traces +// produce generates traces from each generator and sends them to the next consumer func (r *tracesGeneratorReceiver) produce() error { - return nil + traces := ptrace.NewTraces() + for _, g := range r.generators { + t := g.generateTraces() + for i := 0; i < t.ResourceSpans().Len(); i++ { + src := t.ResourceSpans().At(i) + src.CopyTo(traces.ResourceSpans().AppendEmpty()) + } + } + return r.nextConsumer.ConsumeTraces(r.ctx, traces) }