Skip to content

Commit

Permalink
make enablement hint mandatory
Browse files Browse the repository at this point in the history
Signed-off-by: ChrsMark <[email protected]>
  • Loading branch information
ChrsMark committed Nov 19, 2024
1 parent fafe526 commit 13adc90
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
6 changes: 3 additions & 3 deletions receiver/receivercreator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,7 @@ Find bellow the supported annotations that user can define to automatically enab

#### Enable/disable discovery

`io.opentelemetry.discovery.metrics/enabled` (example: `"true"`)

By default `"true"`.
`io.opentelemetry.discovery.metrics/enabled` (Required. `"true"` or `"false"`)

#### Define scraper

Expand Down Expand Up @@ -589,12 +587,14 @@ spec:
app: redis
annotations:
# redis container port metrics hints
io.opentelemetry.discovery.metrics.6379/enabled: "true"
io.opentelemetry.discovery.metrics.6379/scraper: redis
io.opentelemetry.discovery.metrics.6379/config: |
collection_interval: "20s"
timeout: "10s"
# nginx container port metrics hints
io.opentelemetry.discovery.metrics.80/enabled: "true"
io.opentelemetry.discovery.metrics.80/scraper: nginx
io.opentelemetry.discovery.metrics.80/config: |
endpoint: "http://`endpoint`/nginx_status"
Expand Down
3 changes: 1 addition & 2 deletions receiver/receivercreator/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ func getHintAnnotation(annotations map[string]string, hintBase string, hintKey s
}

func discoveryMetricsEnabled(annotations map[string]string, hintBase string, scopeSuffix string) bool {
hintVal := getHintAnnotation(annotations, hintBase, discoveryEnabledHint, scopeSuffix)
return hintVal == "true" || hintVal == ""
return getHintAnnotation(annotations, hintBase, discoveryEnabledHint, scopeSuffix) == "true"
}

func getStringEnv(env observer.EndpointEnv, key string) string {
Expand Down
30 changes: 17 additions & 13 deletions receiver/receivercreator/discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ password: "changeme"`
UID: "pod-2-UID",
Labels: map[string]string{"env": "prod"},
Annotations: map[string]string{
otelMetricsHints + "/enabled": "true",
otelMetricsHints + "/scraper": "redis",
otelMetricsHints + "/config": config,
}},
Expand All @@ -74,6 +75,7 @@ password: "changeme"`
UID: "pod-2-UID",
Labels: map[string]string{"env": "prod"},
Annotations: map[string]string{
otelMetricsHints + "/enabled": "true",
otelMetricsHints + "/scraper": "redis",
otelMetricsHints + "/config": config,
}},
Expand All @@ -93,6 +95,7 @@ password: "changeme"`
UID: "pod-2-UID",
Labels: map[string]string{"env": "prod"},
Annotations: map[string]string{
otelMetricsHints + "/enabled": "true",
otelMetricsHints + "/scraper": "redis",
}},
Port: 6379},
Expand All @@ -116,6 +119,7 @@ password: "changeme"`
UID: "pod-2-UID",
Labels: map[string]string{"env": "prod"},
Annotations: map[string]string{
otelMetricsHints + ".6379/enabled": "true",
otelMetricsHints + ".6379/scraper": "redis",
otelMetricsHints + ".6379/config": config,
}},
Expand All @@ -140,6 +144,7 @@ password: "changeme"`
UID: "pod-2-UID",
Labels: map[string]string{"env": "prod"},
Annotations: map[string]string{
otelMetricsHints + ".6379/enabled": "true",
otelMetricsHints + ".6379/scraper": "redis",
otelMetricsHints + "/config": config,
otelMetricsHints + ".6379/config": configRedis,
Expand All @@ -165,6 +170,7 @@ password: "changeme"`
UID: "pod-2-UID",
Labels: map[string]string{"env": "prod"},
Annotations: map[string]string{
otelMetricsHints + "/enabled": "true",
otelMetricsHints + "/scraper": "redis",
otelMetricsHints + "/config": config,
}}},
Expand Down Expand Up @@ -218,7 +224,8 @@ nested_example:
scopeSuffix string
}{"simple_annotation_case": {
hintsAnn: map[string]string{
"io.opentelemetry.discovery.metrics/config": config,
"io.opentelemetry.discovery.metrics/enabled": "true",
"io.opentelemetry.discovery.metrics/config": config,
}, expectedConf: userConfigMap{
"collection_interval": "20s",
"endpoint": "0.0.0.0:8080",
Expand All @@ -229,7 +236,8 @@ nested_example:
scopeSuffix: "",
}, "simple_annotation_case_default_endpoint": {
hintsAnn: map[string]string{
"io.opentelemetry.discovery.metrics/config": configNoEndpoint,
"io.opentelemetry.discovery.metrics/enabled": "true",
"io.opentelemetry.discovery.metrics/config": configNoEndpoint,
}, expectedConf: userConfigMap{
"collection_interval": "20s",
"endpoint": "1.1.1.1:8080",
Expand All @@ -240,7 +248,8 @@ nested_example:
scopeSuffix: "",
}, "simple_annotation_case_scoped": {
hintsAnn: map[string]string{
"io.opentelemetry.discovery.metrics.8080/config": config,
"io.opentelemetry.discovery.metrics.8080/enabled": "true",
"io.opentelemetry.discovery.metrics.8080/config": config,
}, expectedConf: userConfigMap{
"collection_interval": "20s",
"endpoint": "0.0.0.0:8080",
Expand All @@ -251,7 +260,8 @@ nested_example:
scopeSuffix: "8080",
}, "simple_annotation_case_with_invalid_endpoint": {
hintsAnn: map[string]string{
"io.opentelemetry.discovery.metrics/config": config,
"io.opentelemetry.discovery.metrics/enabled": "true",
"io.opentelemetry.discovery.metrics/config": config,
}, expectedConf: userConfigMap{},
defaultEndpoint: "1.2.3.4:8080",
scopeSuffix: "",
Expand Down Expand Up @@ -291,19 +301,13 @@ endpoint: "0.0.0.0:8080"`
},
expected: false,
scopeSuffix: "",
}, "test_default": {
hintsAnn: map[string]string{
"io.opentelemetry.discovery.metrics/config": config,
},
expected: true,
scopeSuffix: "",
}, "test_enabled_scope": {
hintsAnn: map[string]string{
"io.opentelemetry.discovery.metrics/config": config,
"io.opentelemetry.discovery.metrics8080/enabled": "true",
"io.opentelemetry.discovery.metrics/config": config,
"io.opentelemetry.discovery.metrics.8080/enabled": "true",
},
expected: true,
scopeSuffix: "some",
scopeSuffix: "8080",
}, "test_disabled_scoped": {
hintsAnn: map[string]string{
"io.opentelemetry.discovery.metrics/config": config,
Expand Down
1 change: 1 addition & 0 deletions receiver/receivercreator/fixtures_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ var portEndpointWithHints = observer.Endpoint{
UID: "pod-2-UID",
Labels: map[string]string{"env": "prod"},
Annotations: map[string]string{
otelMetricsHints + "/enabled": "true",
otelMetricsHints + "/scraper": "with_endpoint",
otelMetricsHints + "/config": config,
}},
Expand Down

0 comments on commit 13adc90

Please sign in to comment.