Skip to content

Commit a2924e6

Browse files
eduardodbrJoibel
andauthored
fix: allow legacy name validation scheme for prometheus metrics (#14879)
Signed-off-by: Eduardo Rodrigues <[email protected]> Co-authored-by: Alan Clucas <[email protected]>
1 parent b4c578f commit a2924e6

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

.spelling

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Traefik
129129
Triaging
130130
TripAdvisor
131131
UI
132+
UTF-8
132133
VSCode
133134
Valasek
134135
Webhooks

docs/environment-variables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ This document outlines environment variables that can be used to customize behav
4444
| `OFFLOAD_NODE_STATUS_TTL` | `time.Duration` | `5m` | The TTL to delete the offloaded node status. Currently only used for testing. |
4545
| `OPERATION_DURATION_METRIC_BUCKET_COUNT` | `int` | `6` | The number of buckets to collect the metric for the operation duration. |
4646
| `POD_NAMES` | `string` | `v2` | Whether to have pod names contain the template name (v2) or be the node id (v1) - should be set the same for Argo Server. |
47+
| `PROMETHEUS_LEGACY_NAME_VALIDATION_SCHEME` | `bool` | `false` | Makes Prometheus emit metrics with only underscores as delimiters by setting `NameValidationScheme` to `LegacyValidation`. |
4748
| `RECENTLY_STARTED_POD_DURATION` | `time.Duration` | `10s` | The duration of a pod before the pod is considered to be recently started. |
4849
| `RECENTLY_DELETED_POD_DURATION` | `time.Duration` | `2m` | The duration of a pod before the pod is considered to be recently deleted. |
4950
| `TASK_RESULT_TIMEOUT_DURATION` | `time.Duration` | `10m` | The duration of time before a node is marked completed but the `taskresult` has not arrived yet, this is a more general and more conservative version of `RECENTLY_DELETED_POD_DURATION` that is used when a `taskresult` hasn't arrived but the pod is still around. |

docs/metrics.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ Assuming you only have one controller replica, you can port-forward with:
124124
kubectl -n argo port-forward deploy/workflow-controller 9090:9090
125125
```
126126

127+
!!! Note "UTF-8 in Prometheus metrics"
128+
Version `v3.7` upgraded the `github.com/prometheus/client_golang` library, changing the `NameValidationScheme` to `UTF8Validation`. This allows metric names to retain their original delimiters (e.g., .), instead of replacing them with underscores. To maintain the legacy behavior, you can set the environment variable `PROMETHEUS_LEGACY_NAME_VALIDATION_SCHEME`. For more details, refer to the official [Prometheus documentation](https://prometheus.io/docs/guides/utf8/).
129+
127130
### Common
128131

129132
You can adjust various elements of the metrics configuration by changing values in the [Workflow Controller Config Map](workflow-controller-configmap.md).

util/telemetry/exporter_prometheus.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ import (
55
"crypto/tls"
66
"fmt"
77
"net/http"
8+
"os"
89
"time"
910

1011
"github.com/argoproj/argo-workflows/v3/util/logging"
1112

1213
promgo "github.com/prometheus/client_golang/prometheus"
14+
prommodel "github.com/prometheus/common/model"
1315
"go.opentelemetry.io/otel/exporters/prometheus"
1416

1517
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -19,6 +21,14 @@ import (
1921
tlsutils "github.com/argoproj/argo-workflows/v3/util/tls"
2022
)
2123

24+
// by default prometheus has NameValidationScheme set to UTF8Validation which allows metrics names to keep original delimiters (e.g. .),
25+
// rather than replacing with underscores. This flag allows the user to revert to the legacy behavior.
26+
func init() {
27+
if _, legacyValidationScheme := os.LookupEnv("PROMETHEUS_LEGACY_NAME_VALIDATION_SCHEME"); legacyValidationScheme {
28+
prommodel.NameValidationScheme = prommodel.LegacyValidation //nolint:staticcheck
29+
}
30+
}
31+
2232
const (
2333
DefaultPrometheusServerPort = 9090
2434
DefaultPrometheusServerPath = "/metrics"

0 commit comments

Comments
 (0)