Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions config/crd/bases/postgres-operator.crunchydata.com_pgadmins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,38 @@ spec:
description: Config is the place for users to configure exporters
and provide files.
properties:
detectors:
description: |-
Resource detectors add identifying attributes to logs and metrics. These run in the order they are defined.
More info: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/processor/resourcedetectionprocessor#readme
items:
properties:
attributes:
additionalProperties:
type: boolean
description: |-
Attributes to use from this detector. Detectors usually add every attribute
they know automatically. Names omitted here behave according to detector defaults.
maxProperties: 30
minProperties: 1
type: object
x-kubernetes-map-type: atomic
name:
description: 'Name of the resource detector to enable:
`aks`, `eks`, `gcp`, etc.'
maxLength: 20
minLength: 1
type: string
required:
- name
type: object
x-kubernetes-map-type: atomic
maxItems: 10
minItems: 1
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
exporters:
description: |-
Exporters allows users to configure OpenTelemetry exporters that exist
Expand Down Expand Up @@ -1937,7 +1969,9 @@ spec:
- path
type: object
type: object
minItems: 1
type: array
x-kubernetes-list-type: atomic
type: object
image:
description: |-
Expand Down Expand Up @@ -1989,12 +2023,12 @@ spec:
- message: minRecords cannot be larger than maxRecords
rule: '!has(self.maxRecords) || self.minRecords <= self.maxRecords'
exporters:
description: |-
Exporters allows users to specify which exporters they want to use in
the logs pipeline.
description: The names of exporters that should send logs.
items:
type: string
minItems: 1
type: array
x-kubernetes-list-type: set
retentionPeriod:
description: |-
How long to retain log files locally. An RFC 3339 duration or a number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11181,6 +11181,38 @@ spec:
description: Config is the place for users to configure exporters
and provide files.
properties:
detectors:
description: |-
Resource detectors add identifying attributes to logs and metrics. These run in the order they are defined.
More info: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/-/processor/resourcedetectionprocessor#readme
items:
properties:
attributes:
additionalProperties:
type: boolean
description: |-
Attributes to use from this detector. Detectors usually add every attribute
they know automatically. Names omitted here behave according to detector defaults.
maxProperties: 30
minProperties: 1
type: object
x-kubernetes-map-type: atomic
name:
description: 'Name of the resource detector to enable:
`aks`, `eks`, `gcp`, etc.'
maxLength: 20
minLength: 1
type: string
required:
- name
type: object
x-kubernetes-map-type: atomic
maxItems: 10
minItems: 1
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
exporters:
description: |-
Exporters allows users to configure OpenTelemetry exporters that exist
Expand Down Expand Up @@ -11513,7 +11545,9 @@ spec:
- path
type: object
type: object
minItems: 1
type: array
x-kubernetes-list-type: atomic
type: object
image:
description: |-
Expand Down Expand Up @@ -11565,12 +11599,12 @@ spec:
- message: minRecords cannot be larger than maxRecords
rule: '!has(self.maxRecords) || self.minRecords <= self.maxRecords'
exporters:
description: |-
Exporters allows users to specify which exporters they want to use in
the logs pipeline.
description: The names of exporters that should send logs.
items:
type: string
minItems: 1
type: array
x-kubernetes-list-type: set
retentionPeriod:
description: |-
How long to retain log files locally. An RFC 3339 duration or a number
Expand Down
29 changes: 29 additions & 0 deletions internal/collector/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,35 @@ func NewConfig(spec *v1beta1.InstrumentationSpec) *Config {
config.Processors[LogsBatchProcessor] = processor
}

// Create a resource detection processor according to the API spec.
// When nothing is specified, the processor does nothing.
{
// https://pkg.go.dev/github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor#section-readme
processor := map[string]any{"override": false, "timeout": "30s"}

if spec != nil && spec.Config != nil {
names := make([]string, len(spec.Config.Detectors))
for i, detector := range spec.Config.Detectors {
names[i] = detector.Name

if len(detector.Attributes) > 0 {
attributes := make(map[string]any, len(detector.Attributes))
for k, v := range detector.Attributes {
attributes[k] = map[string]any{"enabled": v}
}
processor[detector.Name] = map[string]any{
"resource_attributes": attributes,
}
}
}
processor["detectors"] = names
} else {
processor["detectors"] = []string{}
}

config.Processors[ResourceDetectionProcessor] = processor
}

// If there are exporters defined in the spec, add them to the config.
if spec != nil && spec.Config != nil && spec.Config.Exporters != nil {
for k, v := range spec.Config.Exporters {
Expand Down
35 changes: 35 additions & 0 deletions internal/collector/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ processors:
send_batch_size: 8192
timeout: 200ms
groupbyattrs/compact: {}
resourcedetection:
detectors: []
override: false
timeout: 30s
receivers: {}
service:
extensions: []
Expand Down Expand Up @@ -64,6 +68,10 @@ processors:
send_batch_size: 8192
timeout: 200ms
groupbyattrs/compact: {}
resourcedetection:
detectors: []
override: false
timeout: 30s
receivers: {}
service:
extensions: []
Expand Down Expand Up @@ -109,6 +117,33 @@ service:
`))
})
})

t.Run("Detectors", func(t *testing.T) {
var spec *v1beta1.InstrumentationSpec
require.UnmarshalInto(t, &spec, `{
config: {
detectors: [
{ name: gcp },
{ name: aks, attributes: { k8s.cluster.name: true } },
],
},
}`)

result, err := NewConfig(spec).ToYAML()
assert.NilError(t, err)
assert.Assert(t, cmp.Contains(result, `
resourcedetection:
aks:
resource_attributes:
k8s.cluster.name:
enabled: true
detectors:
- gcp
- aks
override: false
timeout: 30s
Comment on lines +135 to +144
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, so this form lets us avoid specifying the resourcedetection sources like resourcedetection/ec2.

(hmmm, for a moment I had /aws there before double-checking -- not here, but maybe in the docs we want to say what the allowable options are or say that there are only a set list and send people to the otel docs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this component handles lots of ... sources. 🤔 Now that I think about it, that seems unusual because it means you must include/compile support for multiple clouds, even if you don't use them.

`))
})
}

func TestGenerateLogrotateConfig(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions internal/collector/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Prometheus = "prometheus"
const PGBouncerMetrics = "metrics/pgbouncer"
const PostgresMetrics = "metrics/postgres"
const PatroniMetrics = "metrics/patroni"
const ResourceDetectionProcessor = "resourcedetection"

const SqlQuery = "sqlquery"

Expand Down
1 change: 1 addition & 0 deletions internal/collector/patroni.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func EnablePatroniLogging(ctx context.Context,
Processors: []ComponentID{
"resource/patroni",
"transform/patroni_logs",
ResourceDetectionProcessor,
LogsBatchProcessor,
CompactingProcessor,
},
Expand Down
10 changes: 10 additions & 0 deletions internal/collector/patroni_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ processors:
- action: insert
key: k8s.pod.name
value: ${env:K8S_POD_NAME}
resourcedetection:
detectors: []
override: false
timeout: 30s
transform/patroni_logs:
log_statements:
- context: log
Expand Down Expand Up @@ -92,6 +96,7 @@ service:
processors:
- resource/patroni
- transform/patroni_logs
- resourcedetection
- batch/logs
- groupbyattrs/compact
receivers:
Expand Down Expand Up @@ -148,6 +153,10 @@ processors:
- action: insert
key: k8s.pod.name
value: ${env:K8S_POD_NAME}
resourcedetection:
detectors: []
override: false
timeout: 30s
transform/patroni_logs:
log_statements:
- context: log
Expand Down Expand Up @@ -182,6 +191,7 @@ service:
processors:
- resource/patroni
- transform/patroni_logs
- resourcedetection
- batch/logs
- groupbyattrs/compact
receivers:
Expand Down
2 changes: 2 additions & 0 deletions internal/collector/pgadmin.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func EnablePgAdminLogging(ctx context.Context, spec *v1beta1.InstrumentationSpec
Processors: []ComponentID{
"resource/pgadmin",
"transform/pgadmin_log",
ResourceDetectionProcessor,
LogsBatchProcessor,
CompactingProcessor,
},
Expand All @@ -113,6 +114,7 @@ func EnablePgAdminLogging(ctx context.Context, spec *v1beta1.InstrumentationSpec
Processors: []ComponentID{
"resource/pgadmin",
"transform/pgadmin_log",
ResourceDetectionProcessor,
LogsBatchProcessor,
CompactingProcessor,
},
Expand Down
12 changes: 12 additions & 0 deletions internal/collector/pgadmin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ collector.yaml: |
- action: insert
key: k8s.pod.name
value: ${env:K8S_POD_NAME}
resourcedetection:
detectors: []
override: false
timeout: 30s
transform/pgadmin_log:
log_statements:
- context: log
Expand Down Expand Up @@ -102,6 +106,7 @@ collector.yaml: |
processors:
- resource/pgadmin
- transform/pgadmin_log
- resourcedetection
- batch/logs
- groupbyattrs/compact
receivers:
Expand All @@ -112,6 +117,7 @@ collector.yaml: |
processors:
- resource/pgadmin
- transform/pgadmin_log
- resourcedetection
- batch/logs
- groupbyattrs/compact
receivers:
Expand Down Expand Up @@ -181,6 +187,10 @@ collector.yaml: |
- action: insert
key: k8s.pod.name
value: ${env:K8S_POD_NAME}
resourcedetection:
detectors: []
override: false
timeout: 30s
transform/pgadmin_log:
log_statements:
- context: log
Expand Down Expand Up @@ -217,6 +227,7 @@ collector.yaml: |
processors:
- resource/pgadmin
- transform/pgadmin_log
- resourcedetection
- batch/logs
- groupbyattrs/compact
receivers:
Expand All @@ -227,6 +238,7 @@ collector.yaml: |
processors:
- resource/pgadmin
- transform/pgadmin_log
- resourcedetection
- batch/logs
- groupbyattrs/compact
receivers:
Expand Down
1 change: 1 addition & 0 deletions internal/collector/pgbackrest.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func NewConfigForPgBackrestRepoHostPod(
Processors: []ComponentID{
"resource/pgbackrest",
"transform/pgbackrest_logs",
ResourceDetectionProcessor,
LogsBatchProcessor,
CompactingProcessor,
},
Expand Down
10 changes: 10 additions & 0 deletions internal/collector/pgbackrest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ processors:
- action: insert
key: k8s.pod.name
value: ${env:K8S_POD_NAME}
resourcedetection:
detectors: []
override: false
timeout: 30s
transform/pgbackrest_logs:
log_statements:
- context: log
Expand Down Expand Up @@ -99,6 +103,7 @@ service:
processors:
- resource/pgbackrest
- transform/pgbackrest_logs
- resourcedetection
- batch/logs
- groupbyattrs/compact
receivers:
Expand Down Expand Up @@ -157,6 +162,10 @@ processors:
- action: insert
key: k8s.pod.name
value: ${env:K8S_POD_NAME}
resourcedetection:
detectors: []
override: false
timeout: 30s
transform/pgbackrest_logs:
log_statements:
- context: log
Expand Down Expand Up @@ -194,6 +203,7 @@ service:
processors:
- resource/pgbackrest
- transform/pgbackrest_logs
- resourcedetection
- batch/logs
- groupbyattrs/compact
receivers:
Expand Down
1 change: 1 addition & 0 deletions internal/collector/pgbouncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func EnablePgBouncerLogging(ctx context.Context,
Processors: []ComponentID{
"resource/pgbouncer",
"transform/pgbouncer_logs",
ResourceDetectionProcessor,
LogsBatchProcessor,
CompactingProcessor,
},
Expand Down
Loading