From de5e3a610f524f30d0651a682fc0f0dffce314e2 Mon Sep 17 00:00:00 2001 From: humoflife Date: Mon, 9 Nov 2026 13:47:05 -0800 Subject: [PATCH] Export identity labels with resource_constant_labels compose-serving-stack sets resource_to_telemetry_conversion on prometheus and prometheus_remote_write sinks, so their series keep the cluster, deployment, engine and role they belong to. Collector 0.161.0 deprecates that setting and warns about it at startup. Its replacement, resource_constant_labels, takes an allowlist. This sets it to the identity attributes, the only ones transform/identity leaves on the resource, so the exporters convert the same attributes as before. A sink that sets either setting itself gets no default, because an exporter refuses a config that sets both. Fixes #489. Co-Authored-By: Claude Opus 5.5 Signed-off-by: humoflife --- apis/telemetrydestinations/definition.yaml | 10 +-- .../function/collector.py | 22 +++--- .../tests/test_collector.py | 68 +++++++++++++++++-- .../compose-serving-stack/tests/test_fn.py | 17 ++++- schemas/.lock.json | 2 +- .../telemetrydestination/v1alpha1.py | 2 +- 6 files changed, 97 insertions(+), 24 deletions(-) diff --git a/apis/telemetrydestinations/definition.yaml b/apis/telemetrydestinations/definition.yaml index 0d24e9a83..4a39c307f 100644 --- a/apis/telemetrydestinations/definition.yaml +++ b/apis/telemetrydestinations/definition.yaml @@ -116,11 +116,11 @@ spec: Modelplane sets one default, for the exporters that flatten a series into labels: prometheus and - prometheus_remote_write get - resource_to_telemetry_conversion, or they would - receive every series stripped of the cluster, - deployment, engine and role it belongs to. Setting it - here overrides that. + prometheus_remote_write get resource_constant_labels, + or they would receive every series stripped of the + cluster, deployment, engine and role it belongs to. + Setting it, or the deprecated + resource_to_telemetry_conversion, here overrides that. secretRef: type: object required: [name] diff --git a/functions/compose-serving-stack/function/collector.py b/functions/compose-serving-stack/function/collector.py index ab55e97e1..9558d5ec5 100644 --- a/functions/compose-serving-stack/function/collector.py +++ b/functions/compose-serving-stack/function/collector.py @@ -561,23 +561,25 @@ def _transform(mappings: list[mmv1alpha1.MetricMapping]) -> dict[str, Any]: # receives every series stripped of everything that says what it measures. # # Applied under an operator's own config rather than over it: this is a default, -# and a sink that sets it wins. +# and a sink that sets it wins. So does a sink that sets the deprecated +# resource_to_telemetry_conversion, because an exporter refuses a config that +# sets both. # # Keyed under both spellings of the remote-write exporter. The component # registers as prometheus_remote_write and still answers to the older # prometheusremotewrite, so a sink writing the name the collector's own # documentation gives would otherwise match nothing here and export every # series stripped of its identity - a silent loss, since the sink itself works. -_RESOURCE_TO_LABELS = {"resource_to_telemetry_conversion": {"enabled": True}} -_SINK_DEFAULTS = { - "prometheus_remote_write": _RESOURCE_TO_LABELS, - "prometheusremotewrite": _RESOURCE_TO_LABELS, - "prometheus": _RESOURCE_TO_LABELS, -} +_FLATTENING_EXPORTERS = {"prometheus_remote_write", "prometheusremotewrite", "prometheus"} +_RESOURCE_LABEL_SETTINGS = {"resource_constant_labels", "resource_to_telemetry_conversion"} -def _sink_defaults(exporter: str) -> dict[str, Any]: - return {k: dict(v) for k, v in _SINK_DEFAULTS.get(exporter, {}).items()} +def _sink_defaults(sink: tdv1alpha1.Sink) -> dict[str, Any]: + if sink.type not in _FLATTENING_EXPORTERS or _RESOURCE_LABEL_SETTINGS & (sink.config or {}).keys(): + return {} + # transform/identity leaves nothing but the identity on the resource, so + # this converts everything that reaches the exporter. + return {"resource_constant_labels": {"included": list(_IDENTITY)}} def _credential_path(sink: tdv1alpha1.Sink, key: str) -> str: @@ -617,7 +619,7 @@ def exporters(sinks: list[tdv1alpha1.Sink]) -> dict[str, Any]: """ rendered: dict[str, Any] = {} for sink in sinks: - cfg: dict[str, Any] = _sink_defaults(sink.type) | dict(sink.config or {}) + cfg: dict[str, Any] = _sink_defaults(sink) | dict(sink.config or {}) if sink.endpoint: cfg["endpoint"] = sink.endpoint if sink.auth and sink.auth.bearerTokenKey: diff --git a/functions/compose-serving-stack/tests/test_collector.py b/functions/compose-serving-stack/tests/test_collector.py index 3583f936d..21956252e 100644 --- a/functions/compose-serving-stack/tests/test_collector.py +++ b/functions/compose-serving-stack/tests/test_collector.py @@ -121,6 +121,22 @@ class AuthenticatorsCase: want: dict +# The resource attributes Modelplane converts to labels on an exporter that +# flattens a series into labels: collector._IDENTITY. +_IDENTITY = ( + "cluster", + "namespace", + "deployment", + "replica", + "engine", + "role", + "phase", + "node", + "service.name", + "service.instance.id", +) + + def _sink(*, name: str, type_: str, secret: str | None) -> tdv1alpha1.Sink: """A sink exporting to otel.acme.example, with a bearer token read from secret if there is one.""" return tdv1alpha1.Sink.model_validate( @@ -738,7 +754,7 @@ def _deployment( want=_config( exporters={ "prometheus_remote_write/primary": { - "resource_to_telemetry_conversion": {"enabled": True}, + "resource_constant_labels": {"included": list(_IDENTITY)}, "endpoint": "https://otel.acme.example", } }, @@ -757,7 +773,7 @@ def _deployment( want=_config( exporters={ "prometheusremotewrite/primary": { - "resource_to_telemetry_conversion": {"enabled": True}, + "resource_constant_labels": {"included": list(_IDENTITY)}, "endpoint": "https://otel.acme.example", } }, @@ -776,7 +792,7 @@ def _deployment( want=_config( exporters={ "prometheus/primary": { - "resource_to_telemetry_conversion": {"enabled": True}, + "resource_constant_labels": {"included": list(_IDENTITY)}, "endpoint": "https://otel.acme.example", } }, @@ -1334,7 +1350,7 @@ def test_transform(case: TransformCase) -> None: "auth": {"authenticator": "bearertokenauth/vendor"}, }, "prometheusremotewrite/prometheus": { - "resource_to_telemetry_conversion": {"enabled": True}, + "resource_constant_labels": {"included": list(_IDENTITY)}, "endpoint": "https://otel.acme.example", "auth": {"authenticator": "bearertokenauth/prometheus"}, }, @@ -1357,7 +1373,7 @@ def test_transform(case: TransformCase) -> None: ( "collector", _deployment( - config_hash="b1539f5a25d85bfc", + config_hash="45ee5c54e7529c48", volumes=[ {"name": "config", "configMap": {"name": "modelplane-collector"}}, {"name": "credentials-vendor", "secret": {"secretName": "vendor-token"}}, @@ -1446,6 +1462,48 @@ def test_objects(case: ObjectsCase) -> None: ], want={"otlphttp/primary": {"endpoint": "https://otel.acme.example", "compression": "gzip"}}, ), + ExportersCase( + name="OwnConstantLabels", + reason="A sink that sets resource_constant_labels keeps its own instead of Modelplane's.", + sinks=[ + tdv1alpha1.Sink.model_validate( + { + "name": "primary", + "type": "prometheus_remote_write", + "endpoint": "https://otel.acme.example", + "config": {"resource_constant_labels": {"included": ["deployment"]}}, + } + ) + ], + want={ + "prometheus_remote_write/primary": { + "resource_constant_labels": {"included": ["deployment"]}, + "endpoint": "https://otel.acme.example", + } + }, + ), + # An exporter refuses a config that sets both resource_constant_labels and + # the deprecated resource_to_telemetry_conversion. + ExportersCase( + name="OwnDeprecatedConversion", + reason="A sink that sets resource_to_telemetry_conversion gets no resource_constant_labels.", + sinks=[ + tdv1alpha1.Sink.model_validate( + { + "name": "primary", + "type": "prometheus", + "endpoint": "https://otel.acme.example", + "config": {"resource_to_telemetry_conversion": {"enabled": True}}, + } + ) + ], + want={ + "prometheus/primary": { + "resource_to_telemetry_conversion": {"enabled": True}, + "endpoint": "https://otel.acme.example", + } + }, + ), ] diff --git a/functions/compose-serving-stack/tests/test_fn.py b/functions/compose-serving-stack/tests/test_fn.py index d3e90092a..f1ef68bb8 100644 --- a/functions/compose-serving-stack/tests/test_fn.py +++ b/functions/compose-serving-stack/tests/test_fn.py @@ -5343,7 +5343,20 @@ def _to_dict(msg: message.Message) -> dict: exporters={ "otlphttp/vendor": {"endpoint": "https://otel.vendor.example"}, "prometheus_remote_write/prom": { - "resource_to_telemetry_conversion": {"enabled": True}, + "resource_constant_labels": { + "included": [ + "cluster", + "namespace", + "deployment", + "replica", + "engine", + "role", + "phase", + "node", + "service.name", + "service.instance.id", + ] + }, "endpoint": "https://p.example/w", }, }, @@ -5352,7 +5365,7 @@ def _to_dict(msg: message.Message) -> dict: service_extensions=None, ), "collector": _collector( - config_hash="0a72aaee56455e72", + config_hash="5119d7881b94cc5b", volumes=[{"name": "config", "configMap": {"name": "modelplane-collector"}}], volume_mounts=[{"name": "config", "mountPath": "/conf"}], env_from=None, diff --git a/schemas/.lock.json b/schemas/.lock.json index f5e193428..d3d5a01e3 100644 --- a/schemas/.lock.json +++ b/schemas/.lock.json @@ -1,6 +1,6 @@ { "packages": { - "fs://apis": "7765fe0a737410e9a3f3504455b088e8d2c9ba91fb33046a56acb5441f1ce741", + "fs://apis": "5118ca67149270d612face0165f8d97952868ccbaabfb9ad80662e851d829711", "git://https://github.com/crossplane/crossplane/cluster/crds": "14c53aac914d393b5bcc00962fbc90d4be5d35bc", "git://https://github.com/modelplaneai/cluster-agent/cluster/charts/cluster-agent/files/crds": "a833d3f6f7d9a6ac6083e7453375b58b65ee741a", "xpkg://xpkg.upbound.io/upbound/provider-aws-ec2:v2.9.4": "sha256:7a0febdfb8da2d59a9fdcdbc2d476811f00566fcb941880313fc2034b0ca6177", diff --git a/schemas/python/models/ai/modelplane/telemetrydestination/v1alpha1.py b/schemas/python/models/ai/modelplane/telemetrydestination/v1alpha1.py index 3414851d8..37550494c 100644 --- a/schemas/python/models/ai/modelplane/telemetrydestination/v1alpha1.py +++ b/schemas/python/models/ai/modelplane/telemetrydestination/v1alpha1.py @@ -65,7 +65,7 @@ class Sink(BaseModel): config: dict[str, Any] | None = None """ The rest of the exporter's configuration, passed through as written: TLS, retries, queueing, compression, headers. - Modelplane sets one default, for the exporters that flatten a series into labels: prometheus and prometheus_remote_write get resource_to_telemetry_conversion, or they would receive every series stripped of the cluster, deployment, engine and role it belongs to. Setting it here overrides that. + Modelplane sets one default, for the exporters that flatten a series into labels: prometheus and prometheus_remote_write get resource_constant_labels, or they would receive every series stripped of the cluster, deployment, engine and role it belongs to. Setting it, or the deprecated resource_to_telemetry_conversion, here overrides that. """ endpoint: constr(max_length=2048) | None = None """