summaryrefslogtreecommitdiffstats
path: root/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/MetricsFormatter.java
diff options
context:
space:
mode:
Diffstat (limited to 'metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/MetricsFormatter.java')
-rw-r--r--metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/MetricsFormatter.java71
1 files changed, 0 insertions, 71 deletions
diff --git a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/MetricsFormatter.java b/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/MetricsFormatter.java
deleted file mode 100644
index 8858e21486a..00000000000
--- a/metrics-proxy/src/main/java/ai/vespa/metricsproxy/metric/MetricsFormatter.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
- */
-
-package ai.vespa.metricsproxy.metric;
-
-import ai.vespa.metricsproxy.service.VespaService;
-
-import java.text.DecimalFormat;
-import java.text.DecimalFormatSymbols;
-import java.util.Locale;
-
-/**
- * Format metrics as required by users of the "getMetricsById" rpc method.
- *
- * @author Unknown
- */
-public class MetricsFormatter {
- private final boolean includeServiceName;
- private final boolean isSystemMetric;
- private final DecimalFormat df = new DecimalFormat("0.000", new DecimalFormatSymbols(Locale.ENGLISH));
-
- public MetricsFormatter(boolean includeServiceName, boolean isSystemMetric) {
- this.includeServiceName = includeServiceName;
- this.isSystemMetric = isSystemMetric;
- }
-
- public String format(VespaService service, String name, Number value) {
- StringBuilder sb = new StringBuilder();
-
- if (includeServiceName) {
- sb.append(service.getServiceName()).append(".");
- }
-
- if (isSystemMetric)
- sb.append(toSystemServiceId(service.getConfigId()));
- else
- sb.append(toServiceId(service.getConfigId()));
-
- sb.append(".")
- .append(formatMetricName(name))
- .append("=");
-
- if (value instanceof Double) {
- sb.append(df.format(value.doubleValue()));
- } else {
- sb.append(value.toString());
- }
-
- return sb.toString();
- }
-
- private static String formatMetricName(String name) {
- name = name.replaceAll("\"", "");
- name = name.replaceAll("\\.", "_");
- return name;
- }
-
- // E.g. container/qrserver.1 -> 'container.qrserver.1'
- private static String toServiceId(String configId) {
- return "'" + configId.replace("/", ".") + "'";
- }
-
- // E.g. container/qrserver.1 -> container.'qrserver.1'
- private static String toSystemServiceId(String configId) {
- String name = configId.replace("/", ".");
- name = name.replaceFirst("\\.", ".'") + "'";
- return name;
- }
-
-}