Skip to content
Open
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
10 changes: 5 additions & 5 deletions apis/telemetrydestinations/definition.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
22 changes: 12 additions & 10 deletions functions/compose-serving-stack/function/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
68 changes: 63 additions & 5 deletions functions/compose-serving-stack/tests/test_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
}
},
Expand All @@ -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",
}
},
Expand All @@ -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",
}
},
Expand Down Expand Up @@ -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"},
},
Expand All @@ -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"}},
Expand Down Expand Up @@ -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",
}
},
),
]


Expand Down
17 changes: 15 additions & 2 deletions functions/compose-serving-stack/tests/test_fn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion schemas/.lock.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
Loading