blob: f4d743689e365ed7ae0349fb79d608909707875f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package ai.vespa.metricsproxy.http.application;
import ai.vespa.metricsproxy.metric.model.MetricsPacket;
import ai.vespa.metricsproxy.metric.model.processing.MetricsProcessor;
import static ai.vespa.metricsproxy.metric.dimensions.PublicDimensions.CLUSTER_ID;
import static ai.vespa.metricsproxy.metric.dimensions.PublicDimensions.INTERNAL_CLUSTER_ID;
import static ai.vespa.metricsproxy.metric.dimensions.PublicDimensions.INTERNAL_CLUSTER_TYPE;
import static ai.vespa.metricsproxy.metric.model.DimensionId.toDimensionId;
/**
* Replaces the current cluster ID dimension value with "clustertype/clusterid".
*
* @author gjoranv
*/
public class ClusterIdDimensionProcessor implements MetricsProcessor {
@Override
public void process(MetricsPacket.Builder builder) {
String clusterType = emptyIfNull(builder.getDimensionValue(toDimensionId(INTERNAL_CLUSTER_TYPE)));
String clusterId = emptyIfNull(builder.getDimensionValue(toDimensionId(INTERNAL_CLUSTER_ID)));
String newClusterId;
if (! clusterType.isEmpty() && ! clusterId.isEmpty())
newClusterId = clusterType + "/" + clusterId;
else if (! clusterType.isEmpty())
newClusterId = clusterType;
else if (! clusterId.isEmpty())
newClusterId = clusterId;
else
return; // Both type and id were null or empty
builder.putDimension(toDimensionId(CLUSTER_ID), newClusterId);
}
private String emptyIfNull(String s) {
return s == null ? "" : s;
}
}
|