From 22cd8a21154cf5fa12cea6af1b0e4f30b978fe44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Horn=C3=A1k?= Date: Thu, 2 Jan 2025 15:33:34 +0100 Subject: [PATCH 01/11] [processor/geoipprocessor] Remove unused field --- .../geoipprocessor/geoip_processor_test.go | 56 ++++++++----------- 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/processor/geoipprocessor/geoip_processor_test.go b/processor/geoipprocessor/geoip_processor_test.go index f0498b7150f8..a06a76d937ca 100644 --- a/processor/geoipprocessor/geoip_processor_test.go +++ b/processor/geoipprocessor/geoip_processor_test.go @@ -82,52 +82,44 @@ var baseProviderMock = providerMock{ } var testCases = []struct { - name string - goldenDir string - context ContextID - lookupAttributes []attribute.Key + name string + goldenDir string + context ContextID }{ { - name: "default source.address attribute, not found", - goldenDir: "no_source_address", - context: resource, - lookupAttributes: defaultResourceAttributes, + name: "default source.address attribute, not found", + goldenDir: "no_source_address", + context: resource, }, { - name: "default source.address attribute", - goldenDir: "source_address", - context: resource, - lookupAttributes: defaultResourceAttributes, + name: "default source.address attribute", + goldenDir: "source_address", + context: resource, }, { - name: "default source.address attribute no geo metadata found by providers", - goldenDir: "source_address_geo_not_found", - context: resource, - lookupAttributes: defaultResourceAttributes, + name: "default source.address attribute no geo metadata found by providers", + goldenDir: "source_address_geo_not_found", + context: resource, }, { - name: "default source.ip attribute with an unspecified IP address should be skipped", - goldenDir: "unspecified_address", - context: resource, - lookupAttributes: defaultResourceAttributes, + name: "default source.ip attribute with an unspecified IP address should be skipped", + goldenDir: "unspecified_address", + context: resource, }, { - name: "custom source attributes", - goldenDir: "custom_sources", - context: resource, - lookupAttributes: []attribute.Key{"ip", "host.ip"}, + name: "custom source attributes", + goldenDir: "custom_sources", + context: resource, }, { - name: "do not add resource attributes with an invalid ip", - goldenDir: "invalid_address", - context: resource, - lookupAttributes: defaultResourceAttributes, + name: "do not add resource attributes with an invalid ip", + goldenDir: "invalid_address", + context: resource, }, { - name: "source address located in inner attributes", - goldenDir: "attribute_source_address", - context: record, - lookupAttributes: defaultResourceAttributes, + name: "source address located in inner attributes", + goldenDir: "attribute_source_address", + context: record, }, } From dd1e8cf8a02ec099c68ef24860893d435628217d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Horn=C3=A1k?= Date: Thu, 2 Jan 2025 16:13:30 +0100 Subject: [PATCH 02/11] [processor/geoipprocessor] Read both the client.address and the source.address attributes --- processor/geoipprocessor/README.md | 2 +- processor/geoipprocessor/factory.go | 5 +- .../geoipprocessor/geoip_processor_test.go | 7 +- .../attribute_client_address/input-logs.yaml | 23 ++ .../input-metrics.yaml | 72 ++++++ .../input-traces.yaml | 39 ++++ .../attribute_client_address/output-logs.yaml | 56 +++++ .../output-metrics.yaml | 213 ++++++++++++++++++ .../output-traces.yaml | 70 ++++++ 9 files changed, 483 insertions(+), 4 deletions(-) create mode 100644 processor/geoipprocessor/testdata/attribute_client_address/input-logs.yaml create mode 100644 processor/geoipprocessor/testdata/attribute_client_address/input-metrics.yaml create mode 100644 processor/geoipprocessor/testdata/attribute_client_address/input-traces.yaml create mode 100644 processor/geoipprocessor/testdata/attribute_client_address/output-logs.yaml create mode 100644 processor/geoipprocessor/testdata/attribute_client_address/output-metrics.yaml create mode 100644 processor/geoipprocessor/testdata/attribute_client_address/output-traces.yaml diff --git a/processor/geoipprocessor/README.md b/processor/geoipprocessor/README.md index 6d91b7b6a7d5..3539d2fc9b01 100644 --- a/processor/geoipprocessor/README.md +++ b/processor/geoipprocessor/README.md @@ -14,7 +14,7 @@ ## Description -The geoIP processor `geoipprocessor` enhances the attributes of a span, log, or metric by appending information about the geographical location of an IP address. To add geographical information, the IP address must be included in the attributes using the [`source.address` semantic conventions key attribute](https://github.com/open-telemetry/semantic-conventions/blob/v1.26.0/docs/general/attributes.md#source). By default, only the resource attributes will be modified. Please refer to [config.go](./config.go) for the config spec. +The geoIP processor `geoipprocessor` enhances the attributes of a span, log, or metric by appending information about the geographical location of an IP address. To add geographical information, the IP address must be included in the attributes using the [`client.address`](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/general/attributes.md#client-attributes) or the [`source.address`](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/general/attributes.md#source) semantic conventions key attribute. By default, only the resource attributes will be modified. Please refer to [config.go](./config.go) for the config spec. ### Geographical location metadata diff --git a/processor/geoipprocessor/factory.go b/processor/geoipprocessor/factory.go index fc2f40e0b0b2..afaf95b73962 100644 --- a/processor/geoipprocessor/factory.go +++ b/processor/geoipprocessor/factory.go @@ -24,7 +24,10 @@ var ( // defaultResourceAttributes holds a list of default resource attribute keys. // These keys are used to identify an IP address attribute associated with the resource. defaultResourceAttributes = []attribute.Key{ - semconv.SourceAddressKey, // This key represents the standard source address attribute as defined in the OpenTelemetry semantic conventions. + // The client attributes are in use by the HTTP semantic conventions + semconv.ClientAddressKey, + // The source attributes are used when there is no client/server relationship between the two sides, or when that relationship is unknown + semconv.SourceAddressKey, } ) diff --git a/processor/geoipprocessor/geoip_processor_test.go b/processor/geoipprocessor/geoip_processor_test.go index a06a76d937ca..db2b740d917b 100644 --- a/processor/geoipprocessor/geoip_processor_test.go +++ b/processor/geoipprocessor/geoip_processor_test.go @@ -15,7 +15,6 @@ import ( "go.opentelemetry.io/collector/processor" "go.opentelemetry.io/collector/processor/processortest" "go.opentelemetry.io/otel/attribute" - semconv "go.opentelemetry.io/otel/semconv/v1.21.0" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/golden" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/plogtest" @@ -121,6 +120,11 @@ var testCases = []struct { goldenDir: "attribute_source_address", context: record, }, + { + name: "client address located in inner attributes", + goldenDir: "attribute_client_address", + context: record, + }, } func compareAllSignals(cfg component.Config, goldenDir string) func(t *testing.T) { @@ -197,7 +201,6 @@ func TestProcessor(t *testing.T) { baseProviderMock.LocationF = func(_ context.Context, sourceIP net.IP) (attribute.Set, error) { if sourceIP.Equal(net.IPv4(1, 2, 3, 4)) { return attribute.NewSet([]attribute.KeyValue{ - semconv.SourceAddress("1.2.3.4"), attribute.String(conventions.AttributeGeoCityName, "Boxford"), attribute.String(conventions.AttributeGeoContinentCode, "EU"), attribute.String(conventions.AttributeGeoContinentName, "Europe"), diff --git a/processor/geoipprocessor/testdata/attribute_client_address/input-logs.yaml b/processor/geoipprocessor/testdata/attribute_client_address/input-logs.yaml new file mode 100644 index 000000000000..f17f702a4d7c --- /dev/null +++ b/processor/geoipprocessor/testdata/attribute_client_address/input-logs.yaml @@ -0,0 +1,23 @@ +resourceLogs: + - resource: + attributes: + - key: ip + value: + stringValue: 1.2.2.1 + scopeLogs: + - logRecords: + - attributes: + - key: client.address + value: + stringValue: 1.2.3.4 + - key: host.name + value: + stringValue: HOST.ONE + - key: log.file.name + value: + stringValue: one.log + body: + stringValue: hello one + spanId: "" + traceId: "" + scope: {} diff --git a/processor/geoipprocessor/testdata/attribute_client_address/input-metrics.yaml b/processor/geoipprocessor/testdata/attribute_client_address/input-metrics.yaml new file mode 100644 index 000000000000..1606146333fe --- /dev/null +++ b/processor/geoipprocessor/testdata/attribute_client_address/input-metrics.yaml @@ -0,0 +1,72 @@ +resourceMetrics: + - resource: + attributes: + - key: ip + value: + stringValue: 1.2.2.1 + schemaUrl: https://test-res-schema.com/schema + scopeMetrics: + - metrics: + - description: This also isn't a real metric + name: storage.amplitude + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "0" + attributes: + - key: a + value: + stringValue: AAAA + - key: client.address + value: + stringValue: 1.2.3.4 + isMonotonic: false + unit: "1" + - name: delta.histogram.test + histogram: + aggregationTemporality: 1 + dataPoints: + - explicitBounds: [0.01, 0.1, 1, 10, 100] + timeUnixNano: "1000000" + bucketCounts: [9, 12, 17, 8, 34] + attributes: + - key: client.address + value: + stringValue: 1.2.3.4 + - name: summary.test + summary: + dataPoints: + - timeUnixNano: "1000000" + quantileValues: + - quantile: 0.25 + value: 50 + - quantile: 0.5 + value: 20 + - quantile: 0.75 + value: 75 + - quantile: 0.95 + value: 10 + attributes: + - key: client.address + value: + stringValue: 1.2.3.4 + - gauge: + dataPoints: + - asDouble: 345 + attributes: + - key: client.address + value: + stringValue: 1.2.3.4 + - key: aaa + value: + stringValue: bbb + timeUnixNano: "1000000" + name: test.gauge + schemaUrl: https://test-scope-schema.com/schema + scope: + attributes: + - key: foo + value: + stringValue: bar + name: MyTestInstrument + version: 1.2.3 diff --git a/processor/geoipprocessor/testdata/attribute_client_address/input-traces.yaml b/processor/geoipprocessor/testdata/attribute_client_address/input-traces.yaml new file mode 100644 index 000000000000..a1d181c2b6e3 --- /dev/null +++ b/processor/geoipprocessor/testdata/attribute_client_address/input-traces.yaml @@ -0,0 +1,39 @@ +resourceSpans: + - resource: + attributes: + scopeSpans: + - scope: {} + spans: + - attributes: + - key: http.request.method + value: + stringValue: POST + - key: url.full + value: + stringValue: https://www.foo.bar/search?q=OpenTelemetry#SemConv + - key: http.response.status_code + value: + intValue: "201" + - key: ip + value: + stringValue: 1.2.2.1 + - key: client.address + value: + stringValue: 1.2.3.4 + endTimeUnixNano: "1581452773000000789" + events: + - attributes: + - key: event.attr1 + value: + stringValue: foo2 + - key: event.attr2 + value: + stringValue: bar2 + name: event2 + timeUnixNano: "1581452773000000123" + name: span-elastic-http + parentSpanId: bcff497b5a47310f + spanId: "" + startTimeUnixNano: "1581452772000000321" + status: {} + traceId: "" diff --git a/processor/geoipprocessor/testdata/attribute_client_address/output-logs.yaml b/processor/geoipprocessor/testdata/attribute_client_address/output-logs.yaml new file mode 100644 index 000000000000..bc875fe99583 --- /dev/null +++ b/processor/geoipprocessor/testdata/attribute_client_address/output-logs.yaml @@ -0,0 +1,56 @@ +resourceLogs: + - resource: + attributes: + - key: ip + value: + stringValue: 1.2.2.1 + scopeLogs: + - logRecords: + - attributes: + - key: client.address + value: + stringValue: 1.2.3.4 + - key: host.name + value: + stringValue: HOST.ONE + - key: log.file.name + value: + stringValue: one.log + - key: geo.city_name + value: + stringValue: Boxford + - key: geo.continent_code + value: + stringValue: EU + - key: geo.continent_name + value: + stringValue: Europe + - key: geo.country_iso_code + value: + stringValue: GB + - key: geo.country_name + value: + stringValue: United Kingdom + - key: geo.location.lat + value: + doubleValue: 1234 + - key: geo.location.lon + value: + doubleValue: 5678 + - key: geo.postal_code + value: + stringValue: OX1 + - key: geo.region_iso_code + value: + stringValue: WBK + - key: geo.region_name + value: + stringValue: West Berkshire + - key: geo.timezone + value: + stringValue: Europe/London + body: + stringValue: hello one + spanId: "" + traceId: "" + scope: {} diff --git a/processor/geoipprocessor/testdata/attribute_client_address/output-metrics.yaml b/processor/geoipprocessor/testdata/attribute_client_address/output-metrics.yaml new file mode 100644 index 000000000000..e2389712f8c9 --- /dev/null +++ b/processor/geoipprocessor/testdata/attribute_client_address/output-metrics.yaml @@ -0,0 +1,213 @@ +resourceMetrics: + - resource: + attributes: + - key: ip + value: + stringValue: 1.2.2.1 + schemaUrl: https://test-res-schema.com/schema + scopeMetrics: + - metrics: + - description: This also isn't a real metric + name: storage.amplitude + sum: + aggregationTemporality: 2 + dataPoints: + - asInt: "0" + attributes: + - key: a + value: + stringValue: AAAA + - key: geo.city_name + value: + stringValue: Boxford + - key: geo.continent_code + value: + stringValue: EU + - key: geo.continent_name + value: + stringValue: Europe + - key: geo.country_iso_code + value: + stringValue: GB + - key: geo.country_name + value: + stringValue: United Kingdom + - key: geo.location.lat + value: + doubleValue: 1234 + - key: geo.location.lon + value: + doubleValue: 5678 + - key: geo.postal_code + value: + stringValue: OX1 + - key: geo.region_iso_code + value: + stringValue: WBK + - key: geo.region_name + value: + stringValue: West Berkshire + - key: geo.timezone + value: + stringValue: Europe/London + - key: client.address + value: + stringValue: 1.2.3.4 + unit: "1" + - histogram: + aggregationTemporality: 1 + dataPoints: + - attributes: + - key: geo.city_name + value: + stringValue: Boxford + - key: geo.continent_code + value: + stringValue: EU + - key: geo.continent_name + value: + stringValue: Europe + - key: geo.country_iso_code + value: + stringValue: GB + - key: geo.country_name + value: + stringValue: United Kingdom + - key: geo.location.lat + value: + doubleValue: 1234 + - key: geo.location.lon + value: + doubleValue: 5678 + - key: geo.postal_code + value: + stringValue: OX1 + - key: geo.region_iso_code + value: + stringValue: WBK + - key: geo.region_name + value: + stringValue: West Berkshire + - key: geo.timezone + value: + stringValue: Europe/London + - key: client.address + value: + stringValue: 1.2.3.4 + bucketCounts: + - "9" + - "12" + - "17" + - "8" + - "34" + explicitBounds: + - 0.01 + - 0.1 + - 1 + - 10 + - 100 + timeUnixNano: "1000000" + name: delta.histogram.test + - name: summary.test + summary: + dataPoints: + - attributes: + - key: geo.city_name + value: + stringValue: Boxford + - key: geo.continent_code + value: + stringValue: EU + - key: geo.continent_name + value: + stringValue: Europe + - key: geo.country_iso_code + value: + stringValue: GB + - key: geo.country_name + value: + stringValue: United Kingdom + - key: geo.location.lat + value: + doubleValue: 1234 + - key: geo.location.lon + value: + doubleValue: 5678 + - key: geo.postal_code + value: + stringValue: OX1 + - key: geo.region_iso_code + value: + stringValue: WBK + - key: geo.region_name + value: + stringValue: West Berkshire + - key: geo.timezone + value: + stringValue: Europe/London + - key: client.address + value: + stringValue: 1.2.3.4 + quantileValues: + - quantile: 0.25 + value: 50 + - quantile: 0.5 + value: 20 + - quantile: 0.75 + value: 75 + - quantile: 0.95 + value: 10 + timeUnixNano: "1000000" + - gauge: + dataPoints: + - asDouble: 345 + attributes: + - key: aaa + value: + stringValue: bbb + - key: geo.city_name + value: + stringValue: Boxford + - key: geo.continent_code + value: + stringValue: EU + - key: geo.continent_name + value: + stringValue: Europe + - key: geo.country_iso_code + value: + stringValue: GB + - key: geo.country_name + value: + stringValue: United Kingdom + - key: geo.location.lat + value: + doubleValue: 1234 + - key: geo.location.lon + value: + doubleValue: 5678 + - key: geo.postal_code + value: + stringValue: OX1 + - key: geo.region_iso_code + value: + stringValue: WBK + - key: geo.region_name + value: + stringValue: West Berkshire + - key: geo.timezone + value: + stringValue: Europe/London + - key: client.address + value: + stringValue: 1.2.3.4 + timeUnixNano: "1000000" + name: test.gauge + schemaUrl: https://test-scope-schema.com/schema + scope: + attributes: + - key: foo + value: + stringValue: bar + name: MyTestInstrument + version: 1.2.3 diff --git a/processor/geoipprocessor/testdata/attribute_client_address/output-traces.yaml b/processor/geoipprocessor/testdata/attribute_client_address/output-traces.yaml new file mode 100644 index 000000000000..7f9729e5cb59 --- /dev/null +++ b/processor/geoipprocessor/testdata/attribute_client_address/output-traces.yaml @@ -0,0 +1,70 @@ +resourceSpans: + - resource: {} + scopeSpans: + - scope: {} + spans: + - attributes: + - key: http.request.method + value: + stringValue: POST + - key: url.full + value: + stringValue: https://www.foo.bar/search?q=OpenTelemetry#SemConv + - key: http.response.status_code + value: + intValue: "201" + - key: ip + value: + stringValue: 1.2.2.1 + - key: client.address + value: + stringValue: 1.2.3.4 + - key: geo.city_name + value: + stringValue: Boxford + - key: geo.continent_code + value: + stringValue: EU + - key: geo.continent_name + value: + stringValue: Europe + - key: geo.country_iso_code + value: + stringValue: GB + - key: geo.country_name + value: + stringValue: United Kingdom + - key: geo.location.lat + value: + doubleValue: 1234 + - key: geo.location.lon + value: + doubleValue: 5678 + - key: geo.postal_code + value: + stringValue: OX1 + - key: geo.region_iso_code + value: + stringValue: WBK + - key: geo.region_name + value: + stringValue: West Berkshire + - key: geo.timezone + value: + stringValue: Europe/London + events: + - attributes: + - key: event.attr1 + value: + stringValue: foo2 + - key: event.attr2 + value: + stringValue: bar2 + name: event2 + timeUnixNano: "1581452773000000123" + name: span-elastic-http + parentSpanId: bcff497b5a47310f + spanId: "" + startTimeUnixNano: "1581452772000000321" + status: {} + traceId: "" From 37acb5dc3e4acf5def217696fff970bdc7eee58f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Horn=C3=A1k?= Date: Thu, 2 Jan 2025 17:20:14 +0100 Subject: [PATCH 03/11] [processor/geoipprocessor] Add changelog entry --- .chloggen/geoipprocessor-client-address.yaml | 27 ++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .chloggen/geoipprocessor-client-address.yaml diff --git a/.chloggen/geoipprocessor-client-address.yaml b/.chloggen/geoipprocessor-client-address.yaml new file mode 100644 index 000000000000..b2e93926f1eb --- /dev/null +++ b/.chloggen/geoipprocessor-client-address.yaml @@ -0,0 +1,27 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) +component: geoipprocessor + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Read both the `client.address` and the `source.address` attributes + +# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. +issues: [37008] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# If your change doesn't affect end users or the exported elements of any package, +# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [user] From b62e20f3152693134fc695374c5dadea314a7e37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Horn=C3=A1k?= Date: Mon, 6 Jan 2025 22:24:54 +0100 Subject: [PATCH 04/11] [processor/geoipprocessor] Add attributes parameter --- processor/geoipprocessor/README.md | 10 ++++++---- processor/geoipprocessor/config.go | 8 ++++++++ processor/geoipprocessor/config_test.go | 17 +++++++++++++++++ processor/geoipprocessor/factory.go | 13 +++++++------ processor/geoipprocessor/geoip_processor.go | 16 +++++++--------- .../geoipprocessor/geoip_processor_test.go | 2 +- processor/geoipprocessor/integration_test.go | 2 +- processor/geoipprocessor/testdata/config.yaml | 10 ++++++++++ 8 files changed, 57 insertions(+), 21 deletions(-) diff --git a/processor/geoipprocessor/README.md b/processor/geoipprocessor/README.md index 3539d2fc9b01..0b1699ebf185 100644 --- a/processor/geoipprocessor/README.md +++ b/processor/geoipprocessor/README.md @@ -14,7 +14,7 @@ ## Description -The geoIP processor `geoipprocessor` enhances the attributes of a span, log, or metric by appending information about the geographical location of an IP address. To add geographical information, the IP address must be included in the attributes using the [`client.address`](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/general/attributes.md#client-attributes) or the [`source.address`](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/general/attributes.md#source) semantic conventions key attribute. By default, only the resource attributes will be modified. Please refer to [config.go](./config.go) for the config spec. +The geoIP processor `geoipprocessor` enhances the attributes of a span, log, or metric by appending information about the geographical location of an IP address. To add geographical information, the IP address must be included in the attributes specified by `attributes` ([`client.address`](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/general/attributes.md#client-attributes) and [`source.address`](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/general/attributes.md#source) by default). By default, only the resource attributes will be modified. Please refer to [config.go](./config.go) for the config spec. ### Geographical location metadata @@ -36,13 +36,14 @@ The following [resource attributes](./internal/convention/attributes.go) will be ## Configuration -The following settings must be configured: +The following settings can be configured: - `providers`: A map containing geographical location information providers. These providers are used to search for the geographical location attributes associated with an IP. Supported providers: - [maxmind](./internal/provider/maxmindprovider/README.md) -- `context`: Allows specifying the underlying telemetry context the processor will work with. Available values: - - `resource`(default): Resource attributes. +- `context` (default: `resource`): Allows specifying the underlying telemetry context the processor will work with. Available values: + - `resource`: Resource attributes. - `record`: Attributes within a data point, log record or a span. +- `attributes` (default: `[client.address, source.address]`): An array of attribute names, which are used for the IP address lookup ## Examples @@ -54,4 +55,5 @@ processors: providers: maxmind: database_path: /tmp/mygeodb + attributes: [client.address, source.address, custom.address] ``` diff --git a/processor/geoipprocessor/config.go b/processor/geoipprocessor/config.go index 03144906d360..62fcd8c1ace5 100644 --- a/processor/geoipprocessor/config.go +++ b/processor/geoipprocessor/config.go @@ -10,6 +10,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap" + "go.opentelemetry.io/otel/attribute" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/geoipprocessor/internal/provider" ) @@ -43,6 +44,9 @@ type Config struct { // Context section allows specifying the source type to look for the IP. Available options: resource or record. Context ContextID `mapstructure:"context"` + + // An array of attribute names, which are used for the IP address lookup + Attributes []attribute.Key `mapstructure:"attributes"` } var ( @@ -62,6 +66,10 @@ func (cfg *Config) Validate() error { } } + if cfg.Attributes != nil && len(cfg.Attributes) == 0 { + return errors.New("the attributes array must not be empty") + } + return nil } diff --git a/processor/geoipprocessor/config_test.go b/processor/geoipprocessor/config_test.go index 746b210685fc..69d2f8bca4ce 100644 --- a/processor/geoipprocessor/config_test.go +++ b/processor/geoipprocessor/config_test.go @@ -13,6 +13,7 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap/confmaptest" "go.opentelemetry.io/collector/otelcol/otelcoltest" + "go.opentelemetry.io/otel/attribute" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/geoipprocessor/internal/metadata" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/geoipprocessor/internal/provider" @@ -39,6 +40,7 @@ func TestLoadConfig(t *testing.T) { Providers: map[string]provider.Config{ "maxmind": &maxmind.Config{DatabasePath: "/tmp/db"}, }, + Attributes: defaultAttributes, }, }, { @@ -48,6 +50,7 @@ func TestLoadConfig(t *testing.T) { Providers: map[string]provider.Config{ "maxmind": &maxmind.Config{DatabasePath: "/tmp/db"}, }, + Attributes: defaultAttributes, }, }, { @@ -58,6 +61,20 @@ func TestLoadConfig(t *testing.T) { id: component.NewIDWithName(metadata.Type, "invalid_source"), unmarshalErrorMessage: "unknown context not.an.otlp.context, available values: resource, record", }, + { + id: component.NewIDWithName(metadata.Type, "invalid_source_attributes"), + validateErrorMessage: "the attributes array must not be empty", + }, + { + id: component.NewIDWithName(metadata.Type, "custom_source_attributes"), + expected: &Config{ + Context: resource, + Providers: map[string]provider.Config{ + "maxmind": &maxmind.Config{DatabasePath: "/tmp/db"}, + }, + Attributes: []attribute.Key{"client.address", "source.address", "custom.address"}, + }, + }, } for _, tt := range tests { diff --git a/processor/geoipprocessor/factory.go b/processor/geoipprocessor/factory.go index afaf95b73962..9867c3ba87da 100644 --- a/processor/geoipprocessor/factory.go +++ b/processor/geoipprocessor/factory.go @@ -21,9 +21,9 @@ import ( var ( processorCapabilities = consumer.Capabilities{MutatesData: true} - // defaultResourceAttributes holds a list of default resource attribute keys. + // defaultAttributes holds a list of default resource attribute keys. // These keys are used to identify an IP address attribute associated with the resource. - defaultResourceAttributes = []attribute.Key{ + defaultAttributes = []attribute.Key{ // The client attributes are in use by the HTTP semantic conventions semconv.ClientAddressKey, // The source attributes are used when there is no client/server relationship between the two sides, or when that relationship is unknown @@ -55,7 +55,8 @@ func getProviderFactory(key string) (provider.GeoIPProviderFactory, bool) { // createDefaultConfig returns a default configuration for the processor. func createDefaultConfig() component.Config { return &Config{ - Context: resource, + Context: resource, + Attributes: defaultAttributes, } } @@ -91,7 +92,7 @@ func createMetricsProcessor(ctx context.Context, set processor.Settings, cfg com if err != nil { return nil, err } - return processorhelper.NewMetrics(ctx, set, cfg, nextConsumer, newGeoIPProcessor(geoCfg, defaultResourceAttributes, providers, set).processMetrics, processorhelper.WithCapabilities(processorCapabilities)) + return processorhelper.NewMetrics(ctx, set, cfg, nextConsumer, newGeoIPProcessor(geoCfg, providers, set).processMetrics, processorhelper.WithCapabilities(processorCapabilities)) } func createTracesProcessor(ctx context.Context, set processor.Settings, cfg component.Config, nextConsumer consumer.Traces) (processor.Traces, error) { @@ -100,7 +101,7 @@ func createTracesProcessor(ctx context.Context, set processor.Settings, cfg comp if err != nil { return nil, err } - return processorhelper.NewTraces(ctx, set, cfg, nextConsumer, newGeoIPProcessor(geoCfg, defaultResourceAttributes, providers, set).processTraces, processorhelper.WithCapabilities(processorCapabilities)) + return processorhelper.NewTraces(ctx, set, cfg, nextConsumer, newGeoIPProcessor(geoCfg, providers, set).processTraces, processorhelper.WithCapabilities(processorCapabilities)) } func createLogsProcessor(ctx context.Context, set processor.Settings, cfg component.Config, nextConsumer consumer.Logs) (processor.Logs, error) { @@ -109,5 +110,5 @@ func createLogsProcessor(ctx context.Context, set processor.Settings, cfg compon if err != nil { return nil, err } - return processorhelper.NewLogs(ctx, set, cfg, nextConsumer, newGeoIPProcessor(geoCfg, defaultResourceAttributes, providers, set).processLogs, processorhelper.WithCapabilities(processorCapabilities)) + return processorhelper.NewLogs(ctx, set, cfg, nextConsumer, newGeoIPProcessor(geoCfg, providers, set).processLogs, processorhelper.WithCapabilities(processorCapabilities)) } diff --git a/processor/geoipprocessor/geoip_processor.go b/processor/geoipprocessor/geoip_processor.go index c78d112c0725..3a5cdbc63a86 100644 --- a/processor/geoipprocessor/geoip_processor.go +++ b/processor/geoipprocessor/geoip_processor.go @@ -26,19 +26,17 @@ var ( // newGeoIPProcessor creates a new instance of geoIPProcessor with the specified fields. type geoIPProcessor struct { - providers []provider.GeoIPProvider - resourceAttributes []attribute.Key - logger *zap.Logger + providers []provider.GeoIPProvider + logger *zap.Logger cfg *Config } -func newGeoIPProcessor(processorConfig *Config, resourceAttributes []attribute.Key, providers []provider.GeoIPProvider, params processor.Settings) *geoIPProcessor { +func newGeoIPProcessor(processorConfig *Config, providers []provider.GeoIPProvider, params processor.Settings) *geoIPProcessor { return &geoIPProcessor{ - resourceAttributes: resourceAttributes, - providers: providers, - cfg: processorConfig, - logger: params.Logger, + providers: providers, + cfg: processorConfig, + logger: params.Logger, } } @@ -92,7 +90,7 @@ func (g *geoIPProcessor) geoLocation(ctx context.Context, ip net.IP) (attribute. // processAttributes processes a pcommon.Map by adding geolocation attributes based on the found IP address. func (g *geoIPProcessor) processAttributes(ctx context.Context, metadata pcommon.Map) error { - ipAddr, err := ipFromAttributes(g.resourceAttributes, metadata) + ipAddr, err := ipFromAttributes(g.cfg.Attributes, metadata) if err != nil { // TODO: log IP error not found if errors.Is(err, errIPNotFound) { diff --git a/processor/geoipprocessor/geoip_processor_test.go b/processor/geoipprocessor/geoip_processor_test.go index db2b740d917b..5e0b65a77c79 100644 --- a/processor/geoipprocessor/geoip_processor_test.go +++ b/processor/geoipprocessor/geoip_processor_test.go @@ -221,7 +221,7 @@ func TestProcessor(t *testing.T) { for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { - cfg := &Config{Context: tt.context, Providers: map[string]provider.Config{providerKey: &providerConfigMock{}}} + cfg := &Config{Context: tt.context, Providers: map[string]provider.Config{providerKey: &providerConfigMock{}}, Attributes: defaultAttributes} compareAllSignals(cfg, tt.goldenDir)(t) }) } diff --git a/processor/geoipprocessor/integration_test.go b/processor/geoipprocessor/integration_test.go index 57892c2a35a8..0d04c1f24816 100644 --- a/processor/geoipprocessor/integration_test.go +++ b/processor/geoipprocessor/integration_test.go @@ -22,7 +22,7 @@ func TestProcessorWithMaxMind(t *testing.T) { for _, tt := range testCases { t.Run("maxmind_"+tt.name, func(t *testing.T) { - cfg := &Config{Context: tt.context, Providers: map[string]provider.Config{"maxmind": &maxmindConfig}} + cfg := &Config{Context: tt.context, Providers: map[string]provider.Config{"maxmind": &maxmindConfig}, Attributes: defaultAttributes} compareAllSignals(cfg, tt.goldenDir)(t) }) diff --git a/processor/geoipprocessor/testdata/config.yaml b/processor/geoipprocessor/testdata/config.yaml index 01c7234a1b3c..21f3c104558c 100644 --- a/processor/geoipprocessor/testdata/config.yaml +++ b/processor/geoipprocessor/testdata/config.yaml @@ -15,3 +15,13 @@ geoip/invalid_source: maxmind: database_path: /tmp/db context: not.an.otlp.context +geoip/invalid_source_attributes: + providers: + maxmind: + database_path: /tmp/db + attributes: [] +geoip/custom_source_attributes: + providers: + maxmind: + database_path: /tmp/db + attributes: [client.address, source.address, custom.address] \ No newline at end of file From 183625806d322a3e5d2493b183a7662129a6efb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Horn=C3=A1k?= Date: Mon, 6 Jan 2025 22:40:17 +0100 Subject: [PATCH 05/11] [processor/geoipprocessor] Make custom_source test cases more interesting --- .../geoipprocessor/geoip_processor_test.go | 4 +- processor/geoipprocessor/integration_test.go | 3 +- .../testdata/custom_sources/input-logs.yaml | 6 +-- .../custom_sources/input-metrics.yaml | 6 +-- .../testdata/custom_sources/input-traces.yaml | 6 +-- .../testdata/custom_sources/output-logs.yaml | 39 +++++++++++++++++-- .../custom_sources/output-metrics.yaml | 39 +++++++++++++++++-- .../custom_sources/output-traces.yaml | 39 +++++++++++++++++-- 8 files changed, 121 insertions(+), 21 deletions(-) diff --git a/processor/geoipprocessor/geoip_processor_test.go b/processor/geoipprocessor/geoip_processor_test.go index 5e0b65a77c79..ac348e7c48f3 100644 --- a/processor/geoipprocessor/geoip_processor_test.go +++ b/processor/geoipprocessor/geoip_processor_test.go @@ -108,7 +108,7 @@ var testCases = []struct { { name: "custom source attributes", goldenDir: "custom_sources", - context: resource, + context: record, }, { name: "do not add resource attributes with an invalid ip", @@ -221,7 +221,7 @@ func TestProcessor(t *testing.T) { for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { - cfg := &Config{Context: tt.context, Providers: map[string]provider.Config{providerKey: &providerConfigMock{}}, Attributes: defaultAttributes} + cfg := &Config{Context: tt.context, Providers: map[string]provider.Config{providerKey: &providerConfigMock{}}, Attributes: []attribute.Key{"source.address", "client.address", "custom.address"}} compareAllSignals(cfg, tt.goldenDir)(t) }) } diff --git a/processor/geoipprocessor/integration_test.go b/processor/geoipprocessor/integration_test.go index 0d04c1f24816..743ca473443a 100644 --- a/processor/geoipprocessor/integration_test.go +++ b/processor/geoipprocessor/integration_test.go @@ -10,6 +10,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/processor/geoipprocessor/internal/provider" maxmind "github.com/open-telemetry/opentelemetry-collector-contrib/processor/geoipprocessor/internal/provider/maxmindprovider" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/geoipprocessor/internal/provider/maxmindprovider/testdata" + "go.opentelemetry.io/otel/attribute" ) func TestProcessorWithMaxMind(t *testing.T) { @@ -22,7 +23,7 @@ func TestProcessorWithMaxMind(t *testing.T) { for _, tt := range testCases { t.Run("maxmind_"+tt.name, func(t *testing.T) { - cfg := &Config{Context: tt.context, Providers: map[string]provider.Config{"maxmind": &maxmindConfig}, Attributes: defaultAttributes} + cfg := &Config{Context: tt.context, Providers: map[string]provider.Config{"maxmind": &maxmindConfig}, Attributes: []attribute.Key{"source.address", "client.address", "custom.address"}} compareAllSignals(cfg, tt.goldenDir)(t) }) diff --git a/processor/geoipprocessor/testdata/custom_sources/input-logs.yaml b/processor/geoipprocessor/testdata/custom_sources/input-logs.yaml index 33c04700e776..520a445ab7a5 100644 --- a/processor/geoipprocessor/testdata/custom_sources/input-logs.yaml +++ b/processor/geoipprocessor/testdata/custom_sources/input-logs.yaml @@ -1,9 +1,6 @@ resourceLogs: - resource: attributes: - - key: host.ip - value: - stringValue: 1.2.3.4 - key: ip value: stringValue: 1.2.3.4 @@ -12,6 +9,9 @@ resourceLogs: - body: stringValue: "hello one" attributes: + - key: custom.address + value: + stringValue: 1.2.3.4 - key: host.name value: stringValue: HOST.ONE diff --git a/processor/geoipprocessor/testdata/custom_sources/input-metrics.yaml b/processor/geoipprocessor/testdata/custom_sources/input-metrics.yaml index 9a36a49f7534..99f5060d22f6 100644 --- a/processor/geoipprocessor/testdata/custom_sources/input-metrics.yaml +++ b/processor/geoipprocessor/testdata/custom_sources/input-metrics.yaml @@ -2,9 +2,6 @@ resourceMetrics: - schemaUrl: https://test-res-schema.com/schema resource: attributes: - - key: host.ip - value: - stringValue: 1.2.3.4 - key: ip value: stringValue: 1.2.3.4 @@ -24,6 +21,9 @@ resourceMetrics: - timeUnixNano: "1000000" asDouble: 345 attributes: + - key: custom.address + value: + stringValue: 1.2.3.4 - key: aaa value: stringValue: bbb diff --git a/processor/geoipprocessor/testdata/custom_sources/input-traces.yaml b/processor/geoipprocessor/testdata/custom_sources/input-traces.yaml index 23eb39fc427a..665d598b371a 100644 --- a/processor/geoipprocessor/testdata/custom_sources/input-traces.yaml +++ b/processor/geoipprocessor/testdata/custom_sources/input-traces.yaml @@ -1,9 +1,6 @@ resourceSpans: - resource: attributes: - - key: host.ip - value: - stringValue: 1.2.3.4 - key: ip value: stringValue: 1.2.3.4 @@ -11,6 +8,9 @@ resourceSpans: - scope: {} spans: - attributes: + - key: custom.address + value: + stringValue: 1.2.3.4 - key: http.request.method value: stringValue: POST diff --git a/processor/geoipprocessor/testdata/custom_sources/output-logs.yaml b/processor/geoipprocessor/testdata/custom_sources/output-logs.yaml index df50e8eace83..6ae68bc5c7cd 100644 --- a/processor/geoipprocessor/testdata/custom_sources/output-logs.yaml +++ b/processor/geoipprocessor/testdata/custom_sources/output-logs.yaml @@ -1,21 +1,54 @@ resourceLogs: - resource: attributes: - - key: host.ip - value: - stringValue: 1.2.3.4 - key: ip value: stringValue: 1.2.3.4 scopeLogs: - logRecords: - attributes: + - key: custom.address + value: + stringValue: 1.2.3.4 - key: host.name value: stringValue: HOST.ONE - key: log.file.name value: stringValue: one.log + - key: geo.city_name + value: + stringValue: Boxford + - key: geo.continent_code + value: + stringValue: EU + - key: geo.continent_name + value: + stringValue: Europe + - key: geo.country_iso_code + value: + stringValue: GB + - key: geo.country_name + value: + stringValue: United Kingdom + - key: geo.location.lat + value: + doubleValue: 1234 + - key: geo.location.lon + value: + doubleValue: 5678 + - key: geo.postal_code + value: + stringValue: OX1 + - key: geo.region_iso_code + value: + stringValue: WBK + - key: geo.region_name + value: + stringValue: West Berkshire + - key: geo.timezone + value: + stringValue: Europe/London body: stringValue: hello one spanId: "" diff --git a/processor/geoipprocessor/testdata/custom_sources/output-metrics.yaml b/processor/geoipprocessor/testdata/custom_sources/output-metrics.yaml index 092b79b2b3f7..6b4f8fe3d4ed 100644 --- a/processor/geoipprocessor/testdata/custom_sources/output-metrics.yaml +++ b/processor/geoipprocessor/testdata/custom_sources/output-metrics.yaml @@ -1,9 +1,6 @@ resourceMetrics: - resource: attributes: - - key: host.ip - value: - stringValue: 1.2.3.4 - key: ip value: stringValue: 1.2.3.4 @@ -14,9 +11,45 @@ resourceMetrics: dataPoints: - asDouble: 345 attributes: + - key: custom.address + value: + stringValue: 1.2.3.4 - key: aaa value: stringValue: bbb + - key: geo.city_name + value: + stringValue: Boxford + - key: geo.continent_code + value: + stringValue: EU + - key: geo.continent_name + value: + stringValue: Europe + - key: geo.country_iso_code + value: + stringValue: GB + - key: geo.country_name + value: + stringValue: United Kingdom + - key: geo.location.lat + value: + doubleValue: 1234 + - key: geo.location.lon + value: + doubleValue: 5678 + - key: geo.postal_code + value: + stringValue: OX1 + - key: geo.region_iso_code + value: + stringValue: WBK + - key: geo.region_name + value: + stringValue: West Berkshire + - key: geo.timezone + value: + stringValue: Europe/London timeUnixNano: "1000000" name: test.gauge schemaUrl: https://test-scope-schema.com/schema diff --git a/processor/geoipprocessor/testdata/custom_sources/output-traces.yaml b/processor/geoipprocessor/testdata/custom_sources/output-traces.yaml index 18b233132028..a6f86e6a8e18 100644 --- a/processor/geoipprocessor/testdata/custom_sources/output-traces.yaml +++ b/processor/geoipprocessor/testdata/custom_sources/output-traces.yaml @@ -1,9 +1,6 @@ resourceSpans: - resource: attributes: - - key: host.ip - value: - stringValue: 1.2.3.4 - key: ip value: stringValue: 1.2.3.4 @@ -11,6 +8,9 @@ resourceSpans: - scope: {} spans: - attributes: + - key: custom.address + value: + stringValue: 1.2.3.4 - key: http.request.method value: stringValue: POST @@ -20,6 +20,39 @@ resourceSpans: - key: http.response.status_code value: intValue: "201" + - key: geo.city_name + value: + stringValue: Boxford + - key: geo.continent_code + value: + stringValue: EU + - key: geo.continent_name + value: + stringValue: Europe + - key: geo.country_iso_code + value: + stringValue: GB + - key: geo.country_name + value: + stringValue: United Kingdom + - key: geo.location.lat + value: + doubleValue: 1234 + - key: geo.location.lon + value: + doubleValue: 5678 + - key: geo.postal_code + value: + stringValue: OX1 + - key: geo.region_iso_code + value: + stringValue: WBK + - key: geo.region_name + value: + stringValue: West Berkshire + - key: geo.timezone + value: + stringValue: Europe/London endTimeUnixNano: "1581452773000000789" events: - attributes: From 3ad4fafe67e3395d09dcb0061f703ff1c4a8c8dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Horn=C3=A1k?= Date: Mon, 6 Jan 2025 22:45:34 +0100 Subject: [PATCH 06/11] [processor/geoipprocessor] Add record/resource prefix to test cases --- .../geoipprocessor/geoip_processor_test.go | 28 +++++++++---------- .../input-logs.yaml | 0 .../input-metrics.yaml | 0 .../input-traces.yaml | 0 .../output-logs.yaml | 0 .../output-metrics.yaml | 0 .../output-traces.yaml | 0 .../input-logs.yaml | 0 .../input-metrics.yaml | 0 .../input-traces.yaml | 0 .../output-logs.yaml | 0 .../output-metrics.yaml | 0 .../output-traces.yaml | 0 .../input-logs.yaml | 0 .../input-metrics.yaml | 0 .../input-traces.yaml | 0 .../output-logs.yaml | 0 .../output-metrics.yaml | 0 .../output-traces.yaml | 0 .../input-logs.yaml | 0 .../input-metrics.yaml | 0 .../input-traces.yaml | 0 .../output-logs.yaml | 0 .../output-metrics.yaml | 0 .../output-traces.yaml | 0 .../input-logs.yaml | 0 .../input-metrics.yaml | 0 .../input-traces.yaml | 0 .../output-logs.yaml | 0 .../output-metrics.yaml | 0 .../output-traces.yaml | 0 .../input-logs.yaml | 0 .../input-metrics.yaml | 0 .../input-traces.yaml | 0 .../output-logs.yaml | 0 .../output-metrics.yaml | 0 .../output-traces.yaml | 0 .../input-logs.yaml | 0 .../input-metrics.yaml | 0 .../input-traces.yaml | 0 .../output-logs.yaml | 0 .../output-metrics.yaml | 0 .../output-traces.yaml | 0 .../input-logs.yaml | 0 .../input-metrics.yaml | 0 .../input-traces.yaml | 0 .../output-logs.yaml | 0 .../output-metrics.yaml | 0 .../output-traces.yaml | 0 49 files changed, 14 insertions(+), 14 deletions(-) rename processor/geoipprocessor/testdata/{attribute_client_address => record_client_address}/input-logs.yaml (100%) rename processor/geoipprocessor/testdata/{attribute_client_address => record_client_address}/input-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{attribute_client_address => record_client_address}/input-traces.yaml (100%) rename processor/geoipprocessor/testdata/{attribute_client_address => record_client_address}/output-logs.yaml (100%) rename processor/geoipprocessor/testdata/{attribute_client_address => record_client_address}/output-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{attribute_client_address => record_client_address}/output-traces.yaml (100%) rename processor/geoipprocessor/testdata/{custom_sources => record_custom_address}/input-logs.yaml (100%) rename processor/geoipprocessor/testdata/{custom_sources => record_custom_address}/input-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{custom_sources => record_custom_address}/input-traces.yaml (100%) rename processor/geoipprocessor/testdata/{custom_sources => record_custom_address}/output-logs.yaml (100%) rename processor/geoipprocessor/testdata/{custom_sources => record_custom_address}/output-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{custom_sources => record_custom_address}/output-traces.yaml (100%) rename processor/geoipprocessor/testdata/{attribute_source_address => record_source_address}/input-logs.yaml (100%) rename processor/geoipprocessor/testdata/{attribute_source_address => record_source_address}/input-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{attribute_source_address => record_source_address}/input-traces.yaml (100%) rename processor/geoipprocessor/testdata/{attribute_source_address => record_source_address}/output-logs.yaml (100%) rename processor/geoipprocessor/testdata/{attribute_source_address => record_source_address}/output-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{attribute_source_address => record_source_address}/output-traces.yaml (100%) rename processor/geoipprocessor/testdata/{invalid_address => resource_invalid_address}/input-logs.yaml (100%) rename processor/geoipprocessor/testdata/{invalid_address => resource_invalid_address}/input-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{invalid_address => resource_invalid_address}/input-traces.yaml (100%) rename processor/geoipprocessor/testdata/{invalid_address => resource_invalid_address}/output-logs.yaml (100%) rename processor/geoipprocessor/testdata/{invalid_address => resource_invalid_address}/output-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{invalid_address => resource_invalid_address}/output-traces.yaml (100%) rename processor/geoipprocessor/testdata/{no_source_address => resource_no_source_address}/input-logs.yaml (100%) rename processor/geoipprocessor/testdata/{no_source_address => resource_no_source_address}/input-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{no_source_address => resource_no_source_address}/input-traces.yaml (100%) rename processor/geoipprocessor/testdata/{no_source_address => resource_no_source_address}/output-logs.yaml (100%) rename processor/geoipprocessor/testdata/{no_source_address => resource_no_source_address}/output-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{no_source_address => resource_no_source_address}/output-traces.yaml (100%) rename processor/geoipprocessor/testdata/{source_address => resource_source_address}/input-logs.yaml (100%) rename processor/geoipprocessor/testdata/{source_address => resource_source_address}/input-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{source_address => resource_source_address}/input-traces.yaml (100%) rename processor/geoipprocessor/testdata/{source_address => resource_source_address}/output-logs.yaml (100%) rename processor/geoipprocessor/testdata/{source_address => resource_source_address}/output-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{source_address => resource_source_address}/output-traces.yaml (100%) rename processor/geoipprocessor/testdata/{source_address_geo_not_found => resource_source_address_geo_not_found}/input-logs.yaml (100%) rename processor/geoipprocessor/testdata/{source_address_geo_not_found => resource_source_address_geo_not_found}/input-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{source_address_geo_not_found => resource_source_address_geo_not_found}/input-traces.yaml (100%) rename processor/geoipprocessor/testdata/{source_address_geo_not_found => resource_source_address_geo_not_found}/output-logs.yaml (100%) rename processor/geoipprocessor/testdata/{source_address_geo_not_found => resource_source_address_geo_not_found}/output-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{source_address_geo_not_found => resource_source_address_geo_not_found}/output-traces.yaml (100%) rename processor/geoipprocessor/testdata/{unspecified_address => resource_unspecified_address}/input-logs.yaml (100%) rename processor/geoipprocessor/testdata/{unspecified_address => resource_unspecified_address}/input-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{unspecified_address => resource_unspecified_address}/input-traces.yaml (100%) rename processor/geoipprocessor/testdata/{unspecified_address => resource_unspecified_address}/output-logs.yaml (100%) rename processor/geoipprocessor/testdata/{unspecified_address => resource_unspecified_address}/output-metrics.yaml (100%) rename processor/geoipprocessor/testdata/{unspecified_address => resource_unspecified_address}/output-traces.yaml (100%) diff --git a/processor/geoipprocessor/geoip_processor_test.go b/processor/geoipprocessor/geoip_processor_test.go index ac348e7c48f3..705f74d3be2d 100644 --- a/processor/geoipprocessor/geoip_processor_test.go +++ b/processor/geoipprocessor/geoip_processor_test.go @@ -87,42 +87,42 @@ var testCases = []struct { }{ { name: "default source.address attribute, not found", - goldenDir: "no_source_address", + goldenDir: "resource_no_source_address", context: resource, }, { name: "default source.address attribute", - goldenDir: "source_address", + goldenDir: "resource_source_address", context: resource, }, { name: "default source.address attribute no geo metadata found by providers", - goldenDir: "source_address_geo_not_found", + goldenDir: "resource_source_address_geo_not_found", context: resource, }, { name: "default source.ip attribute with an unspecified IP address should be skipped", - goldenDir: "unspecified_address", + goldenDir: "resource_unspecified_address", context: resource, }, - { - name: "custom source attributes", - goldenDir: "custom_sources", - context: record, - }, { name: "do not add resource attributes with an invalid ip", - goldenDir: "invalid_address", + goldenDir: "resource_invalid_address", context: resource, }, { - name: "source address located in inner attributes", - goldenDir: "attribute_source_address", + name: "source address located in the record attributes", + goldenDir: "record_source_address", + context: record, + }, + { + name: "client address located in the record attributes", + goldenDir: "record_client_address", context: record, }, { - name: "client address located in inner attributes", - goldenDir: "attribute_client_address", + name: "custom address located in the record attributes", + goldenDir: "record_custom_address", context: record, }, } diff --git a/processor/geoipprocessor/testdata/attribute_client_address/input-logs.yaml b/processor/geoipprocessor/testdata/record_client_address/input-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/attribute_client_address/input-logs.yaml rename to processor/geoipprocessor/testdata/record_client_address/input-logs.yaml diff --git a/processor/geoipprocessor/testdata/attribute_client_address/input-metrics.yaml b/processor/geoipprocessor/testdata/record_client_address/input-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/attribute_client_address/input-metrics.yaml rename to processor/geoipprocessor/testdata/record_client_address/input-metrics.yaml diff --git a/processor/geoipprocessor/testdata/attribute_client_address/input-traces.yaml b/processor/geoipprocessor/testdata/record_client_address/input-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/attribute_client_address/input-traces.yaml rename to processor/geoipprocessor/testdata/record_client_address/input-traces.yaml diff --git a/processor/geoipprocessor/testdata/attribute_client_address/output-logs.yaml b/processor/geoipprocessor/testdata/record_client_address/output-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/attribute_client_address/output-logs.yaml rename to processor/geoipprocessor/testdata/record_client_address/output-logs.yaml diff --git a/processor/geoipprocessor/testdata/attribute_client_address/output-metrics.yaml b/processor/geoipprocessor/testdata/record_client_address/output-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/attribute_client_address/output-metrics.yaml rename to processor/geoipprocessor/testdata/record_client_address/output-metrics.yaml diff --git a/processor/geoipprocessor/testdata/attribute_client_address/output-traces.yaml b/processor/geoipprocessor/testdata/record_client_address/output-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/attribute_client_address/output-traces.yaml rename to processor/geoipprocessor/testdata/record_client_address/output-traces.yaml diff --git a/processor/geoipprocessor/testdata/custom_sources/input-logs.yaml b/processor/geoipprocessor/testdata/record_custom_address/input-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/custom_sources/input-logs.yaml rename to processor/geoipprocessor/testdata/record_custom_address/input-logs.yaml diff --git a/processor/geoipprocessor/testdata/custom_sources/input-metrics.yaml b/processor/geoipprocessor/testdata/record_custom_address/input-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/custom_sources/input-metrics.yaml rename to processor/geoipprocessor/testdata/record_custom_address/input-metrics.yaml diff --git a/processor/geoipprocessor/testdata/custom_sources/input-traces.yaml b/processor/geoipprocessor/testdata/record_custom_address/input-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/custom_sources/input-traces.yaml rename to processor/geoipprocessor/testdata/record_custom_address/input-traces.yaml diff --git a/processor/geoipprocessor/testdata/custom_sources/output-logs.yaml b/processor/geoipprocessor/testdata/record_custom_address/output-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/custom_sources/output-logs.yaml rename to processor/geoipprocessor/testdata/record_custom_address/output-logs.yaml diff --git a/processor/geoipprocessor/testdata/custom_sources/output-metrics.yaml b/processor/geoipprocessor/testdata/record_custom_address/output-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/custom_sources/output-metrics.yaml rename to processor/geoipprocessor/testdata/record_custom_address/output-metrics.yaml diff --git a/processor/geoipprocessor/testdata/custom_sources/output-traces.yaml b/processor/geoipprocessor/testdata/record_custom_address/output-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/custom_sources/output-traces.yaml rename to processor/geoipprocessor/testdata/record_custom_address/output-traces.yaml diff --git a/processor/geoipprocessor/testdata/attribute_source_address/input-logs.yaml b/processor/geoipprocessor/testdata/record_source_address/input-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/attribute_source_address/input-logs.yaml rename to processor/geoipprocessor/testdata/record_source_address/input-logs.yaml diff --git a/processor/geoipprocessor/testdata/attribute_source_address/input-metrics.yaml b/processor/geoipprocessor/testdata/record_source_address/input-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/attribute_source_address/input-metrics.yaml rename to processor/geoipprocessor/testdata/record_source_address/input-metrics.yaml diff --git a/processor/geoipprocessor/testdata/attribute_source_address/input-traces.yaml b/processor/geoipprocessor/testdata/record_source_address/input-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/attribute_source_address/input-traces.yaml rename to processor/geoipprocessor/testdata/record_source_address/input-traces.yaml diff --git a/processor/geoipprocessor/testdata/attribute_source_address/output-logs.yaml b/processor/geoipprocessor/testdata/record_source_address/output-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/attribute_source_address/output-logs.yaml rename to processor/geoipprocessor/testdata/record_source_address/output-logs.yaml diff --git a/processor/geoipprocessor/testdata/attribute_source_address/output-metrics.yaml b/processor/geoipprocessor/testdata/record_source_address/output-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/attribute_source_address/output-metrics.yaml rename to processor/geoipprocessor/testdata/record_source_address/output-metrics.yaml diff --git a/processor/geoipprocessor/testdata/attribute_source_address/output-traces.yaml b/processor/geoipprocessor/testdata/record_source_address/output-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/attribute_source_address/output-traces.yaml rename to processor/geoipprocessor/testdata/record_source_address/output-traces.yaml diff --git a/processor/geoipprocessor/testdata/invalid_address/input-logs.yaml b/processor/geoipprocessor/testdata/resource_invalid_address/input-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/invalid_address/input-logs.yaml rename to processor/geoipprocessor/testdata/resource_invalid_address/input-logs.yaml diff --git a/processor/geoipprocessor/testdata/invalid_address/input-metrics.yaml b/processor/geoipprocessor/testdata/resource_invalid_address/input-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/invalid_address/input-metrics.yaml rename to processor/geoipprocessor/testdata/resource_invalid_address/input-metrics.yaml diff --git a/processor/geoipprocessor/testdata/invalid_address/input-traces.yaml b/processor/geoipprocessor/testdata/resource_invalid_address/input-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/invalid_address/input-traces.yaml rename to processor/geoipprocessor/testdata/resource_invalid_address/input-traces.yaml diff --git a/processor/geoipprocessor/testdata/invalid_address/output-logs.yaml b/processor/geoipprocessor/testdata/resource_invalid_address/output-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/invalid_address/output-logs.yaml rename to processor/geoipprocessor/testdata/resource_invalid_address/output-logs.yaml diff --git a/processor/geoipprocessor/testdata/invalid_address/output-metrics.yaml b/processor/geoipprocessor/testdata/resource_invalid_address/output-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/invalid_address/output-metrics.yaml rename to processor/geoipprocessor/testdata/resource_invalid_address/output-metrics.yaml diff --git a/processor/geoipprocessor/testdata/invalid_address/output-traces.yaml b/processor/geoipprocessor/testdata/resource_invalid_address/output-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/invalid_address/output-traces.yaml rename to processor/geoipprocessor/testdata/resource_invalid_address/output-traces.yaml diff --git a/processor/geoipprocessor/testdata/no_source_address/input-logs.yaml b/processor/geoipprocessor/testdata/resource_no_source_address/input-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/no_source_address/input-logs.yaml rename to processor/geoipprocessor/testdata/resource_no_source_address/input-logs.yaml diff --git a/processor/geoipprocessor/testdata/no_source_address/input-metrics.yaml b/processor/geoipprocessor/testdata/resource_no_source_address/input-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/no_source_address/input-metrics.yaml rename to processor/geoipprocessor/testdata/resource_no_source_address/input-metrics.yaml diff --git a/processor/geoipprocessor/testdata/no_source_address/input-traces.yaml b/processor/geoipprocessor/testdata/resource_no_source_address/input-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/no_source_address/input-traces.yaml rename to processor/geoipprocessor/testdata/resource_no_source_address/input-traces.yaml diff --git a/processor/geoipprocessor/testdata/no_source_address/output-logs.yaml b/processor/geoipprocessor/testdata/resource_no_source_address/output-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/no_source_address/output-logs.yaml rename to processor/geoipprocessor/testdata/resource_no_source_address/output-logs.yaml diff --git a/processor/geoipprocessor/testdata/no_source_address/output-metrics.yaml b/processor/geoipprocessor/testdata/resource_no_source_address/output-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/no_source_address/output-metrics.yaml rename to processor/geoipprocessor/testdata/resource_no_source_address/output-metrics.yaml diff --git a/processor/geoipprocessor/testdata/no_source_address/output-traces.yaml b/processor/geoipprocessor/testdata/resource_no_source_address/output-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/no_source_address/output-traces.yaml rename to processor/geoipprocessor/testdata/resource_no_source_address/output-traces.yaml diff --git a/processor/geoipprocessor/testdata/source_address/input-logs.yaml b/processor/geoipprocessor/testdata/resource_source_address/input-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/source_address/input-logs.yaml rename to processor/geoipprocessor/testdata/resource_source_address/input-logs.yaml diff --git a/processor/geoipprocessor/testdata/source_address/input-metrics.yaml b/processor/geoipprocessor/testdata/resource_source_address/input-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/source_address/input-metrics.yaml rename to processor/geoipprocessor/testdata/resource_source_address/input-metrics.yaml diff --git a/processor/geoipprocessor/testdata/source_address/input-traces.yaml b/processor/geoipprocessor/testdata/resource_source_address/input-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/source_address/input-traces.yaml rename to processor/geoipprocessor/testdata/resource_source_address/input-traces.yaml diff --git a/processor/geoipprocessor/testdata/source_address/output-logs.yaml b/processor/geoipprocessor/testdata/resource_source_address/output-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/source_address/output-logs.yaml rename to processor/geoipprocessor/testdata/resource_source_address/output-logs.yaml diff --git a/processor/geoipprocessor/testdata/source_address/output-metrics.yaml b/processor/geoipprocessor/testdata/resource_source_address/output-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/source_address/output-metrics.yaml rename to processor/geoipprocessor/testdata/resource_source_address/output-metrics.yaml diff --git a/processor/geoipprocessor/testdata/source_address/output-traces.yaml b/processor/geoipprocessor/testdata/resource_source_address/output-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/source_address/output-traces.yaml rename to processor/geoipprocessor/testdata/resource_source_address/output-traces.yaml diff --git a/processor/geoipprocessor/testdata/source_address_geo_not_found/input-logs.yaml b/processor/geoipprocessor/testdata/resource_source_address_geo_not_found/input-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/source_address_geo_not_found/input-logs.yaml rename to processor/geoipprocessor/testdata/resource_source_address_geo_not_found/input-logs.yaml diff --git a/processor/geoipprocessor/testdata/source_address_geo_not_found/input-metrics.yaml b/processor/geoipprocessor/testdata/resource_source_address_geo_not_found/input-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/source_address_geo_not_found/input-metrics.yaml rename to processor/geoipprocessor/testdata/resource_source_address_geo_not_found/input-metrics.yaml diff --git a/processor/geoipprocessor/testdata/source_address_geo_not_found/input-traces.yaml b/processor/geoipprocessor/testdata/resource_source_address_geo_not_found/input-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/source_address_geo_not_found/input-traces.yaml rename to processor/geoipprocessor/testdata/resource_source_address_geo_not_found/input-traces.yaml diff --git a/processor/geoipprocessor/testdata/source_address_geo_not_found/output-logs.yaml b/processor/geoipprocessor/testdata/resource_source_address_geo_not_found/output-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/source_address_geo_not_found/output-logs.yaml rename to processor/geoipprocessor/testdata/resource_source_address_geo_not_found/output-logs.yaml diff --git a/processor/geoipprocessor/testdata/source_address_geo_not_found/output-metrics.yaml b/processor/geoipprocessor/testdata/resource_source_address_geo_not_found/output-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/source_address_geo_not_found/output-metrics.yaml rename to processor/geoipprocessor/testdata/resource_source_address_geo_not_found/output-metrics.yaml diff --git a/processor/geoipprocessor/testdata/source_address_geo_not_found/output-traces.yaml b/processor/geoipprocessor/testdata/resource_source_address_geo_not_found/output-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/source_address_geo_not_found/output-traces.yaml rename to processor/geoipprocessor/testdata/resource_source_address_geo_not_found/output-traces.yaml diff --git a/processor/geoipprocessor/testdata/unspecified_address/input-logs.yaml b/processor/geoipprocessor/testdata/resource_unspecified_address/input-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/unspecified_address/input-logs.yaml rename to processor/geoipprocessor/testdata/resource_unspecified_address/input-logs.yaml diff --git a/processor/geoipprocessor/testdata/unspecified_address/input-metrics.yaml b/processor/geoipprocessor/testdata/resource_unspecified_address/input-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/unspecified_address/input-metrics.yaml rename to processor/geoipprocessor/testdata/resource_unspecified_address/input-metrics.yaml diff --git a/processor/geoipprocessor/testdata/unspecified_address/input-traces.yaml b/processor/geoipprocessor/testdata/resource_unspecified_address/input-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/unspecified_address/input-traces.yaml rename to processor/geoipprocessor/testdata/resource_unspecified_address/input-traces.yaml diff --git a/processor/geoipprocessor/testdata/unspecified_address/output-logs.yaml b/processor/geoipprocessor/testdata/resource_unspecified_address/output-logs.yaml similarity index 100% rename from processor/geoipprocessor/testdata/unspecified_address/output-logs.yaml rename to processor/geoipprocessor/testdata/resource_unspecified_address/output-logs.yaml diff --git a/processor/geoipprocessor/testdata/unspecified_address/output-metrics.yaml b/processor/geoipprocessor/testdata/resource_unspecified_address/output-metrics.yaml similarity index 100% rename from processor/geoipprocessor/testdata/unspecified_address/output-metrics.yaml rename to processor/geoipprocessor/testdata/resource_unspecified_address/output-metrics.yaml diff --git a/processor/geoipprocessor/testdata/unspecified_address/output-traces.yaml b/processor/geoipprocessor/testdata/resource_unspecified_address/output-traces.yaml similarity index 100% rename from processor/geoipprocessor/testdata/unspecified_address/output-traces.yaml rename to processor/geoipprocessor/testdata/resource_unspecified_address/output-traces.yaml From 3f88565bf448040f4c59815f4c2864433b04f66c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Horn=C3=A1k?= Date: Mon, 6 Jan 2025 22:55:30 +0100 Subject: [PATCH 07/11] [processor/geoipprocessor] Update changelog entry --- .chloggen/geoipprocessor-client-address.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chloggen/geoipprocessor-client-address.yaml b/.chloggen/geoipprocessor-client-address.yaml index b2e93926f1eb..ff5cc9d5e4ba 100644 --- a/.chloggen/geoipprocessor-client-address.yaml +++ b/.chloggen/geoipprocessor-client-address.yaml @@ -7,7 +7,7 @@ change_type: enhancement component: geoipprocessor # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Read both the `client.address` and the `source.address` attributes +note: Add the `attributes` parameter and consider both `source.address` and `client.address` by default # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. issues: [37008] From 7027470d71b041a96b720fd0c6693f60eb057f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Horn=C3=A1k?= Date: Tue, 7 Jan 2025 17:02:30 +0100 Subject: [PATCH 08/11] [processor/geoipprocessor] Update README --- processor/geoipprocessor/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/processor/geoipprocessor/README.md b/processor/geoipprocessor/README.md index 0b1699ebf185..b97fb956c379 100644 --- a/processor/geoipprocessor/README.md +++ b/processor/geoipprocessor/README.md @@ -14,7 +14,7 @@ ## Description -The geoIP processor `geoipprocessor` enhances the attributes of a span, log, or metric by appending information about the geographical location of an IP address. To add geographical information, the IP address must be included in the attributes specified by `attributes` ([`client.address`](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/general/attributes.md#client-attributes) and [`source.address`](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/general/attributes.md#source) by default). By default, only the resource attributes will be modified. Please refer to [config.go](./config.go) for the config spec. +The geoIP processor `geoipprocessor` enhances the attributes of a span, log, or metric by appending information about the geographical location of an IP address. To add geographical information, the IP address must be included in the attributes specified by the `attributes` configuration option (e.g., [`client.address`](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/general/attributes.md#client-attributes) and [`source.address`](https://github.com/open-telemetry/semantic-conventions/blob/v1.29.0/docs/general/attributes.md#source) by default). By default, only the resource attributes will be modified. Please refer to [config.go](./config.go) for the config spec. ### Geographical location metadata @@ -43,7 +43,7 @@ The following settings can be configured: - `context` (default: `resource`): Allows specifying the underlying telemetry context the processor will work with. Available values: - `resource`: Resource attributes. - `record`: Attributes within a data point, log record or a span. -- `attributes` (default: `[client.address, source.address]`): An array of attribute names, which are used for the IP address lookup +- `attributes` (default: `[client.address, source.address]`): An array of attribute names, which are used for the IP address lookup. ## Examples From e6ca723e7d9cd3696b59be882c588992580eb5c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Horn=C3=A1k?= Date: Tue, 7 Jan 2025 17:03:25 +0100 Subject: [PATCH 09/11] [processor/geoipprocessor] Make README example more realistic --- processor/geoipprocessor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processor/geoipprocessor/README.md b/processor/geoipprocessor/README.md index b97fb956c379..4c8ebc583445 100644 --- a/processor/geoipprocessor/README.md +++ b/processor/geoipprocessor/README.md @@ -51,9 +51,9 @@ The following settings can be configured: processors: # processor name: geoip geoip: - context: resource providers: maxmind: database_path: /tmp/mygeodb + context: record attributes: [client.address, source.address, custom.address] ``` From 0a5d84807c09383986f58e35e7bb1c25ef6f32bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Horn=C3=A1k?= Date: Tue, 7 Jan 2025 17:09:40 +0100 Subject: [PATCH 10/11] [processor/geoipprocessor] Refactor record_custom_address test case --- .../geoipprocessor/geoip_processor_test.go | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/processor/geoipprocessor/geoip_processor_test.go b/processor/geoipprocessor/geoip_processor_test.go index 705f74d3be2d..3b8ee0e015b5 100644 --- a/processor/geoipprocessor/geoip_processor_test.go +++ b/processor/geoipprocessor/geoip_processor_test.go @@ -81,9 +81,10 @@ var baseProviderMock = providerMock{ } var testCases = []struct { - name string - goldenDir string - context ContextID + name string + goldenDir string + context ContextID + attributes []attribute.Key }{ { name: "default source.address attribute, not found", @@ -121,9 +122,10 @@ var testCases = []struct { context: record, }, { - name: "custom address located in the record attributes", - goldenDir: "record_custom_address", - context: record, + name: "custom address located in the record attributes", + goldenDir: "record_custom_address", + context: record, + attributes: []attribute.Key{"source.address", "client.address", "custom.address"}, }, } @@ -221,7 +223,11 @@ func TestProcessor(t *testing.T) { for _, tt := range testCases { t.Run(tt.name, func(t *testing.T) { - cfg := &Config{Context: tt.context, Providers: map[string]provider.Config{providerKey: &providerConfigMock{}}, Attributes: []attribute.Key{"source.address", "client.address", "custom.address"}} + var attributes []attribute.Key = defaultAttributes + if tt.attributes != nil { + attributes = tt.attributes + } + cfg := &Config{Context: tt.context, Providers: map[string]provider.Config{providerKey: &providerConfigMock{}}, Attributes: attributes} compareAllSignals(cfg, tt.goldenDir)(t) }) } From abae47a9b7887578895ad911d580fb4c969da2af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bence=20Horn=C3=A1k?= Date: Fri, 24 Jan 2025 22:05:30 +0100 Subject: [PATCH 11/11] Run golangci-lint --fix --- processor/geoipprocessor/integration_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/processor/geoipprocessor/integration_test.go b/processor/geoipprocessor/integration_test.go index 743ca473443a..36e28d82b4c9 100644 --- a/processor/geoipprocessor/integration_test.go +++ b/processor/geoipprocessor/integration_test.go @@ -7,10 +7,11 @@ import ( "os" "testing" + "go.opentelemetry.io/otel/attribute" + "github.com/open-telemetry/opentelemetry-collector-contrib/processor/geoipprocessor/internal/provider" maxmind "github.com/open-telemetry/opentelemetry-collector-contrib/processor/geoipprocessor/internal/provider/maxmindprovider" "github.com/open-telemetry/opentelemetry-collector-contrib/processor/geoipprocessor/internal/provider/maxmindprovider/testdata" - "go.opentelemetry.io/otel/attribute" ) func TestProcessorWithMaxMind(t *testing.T) {