From 792c18eddf6437022161d1910f7aaa5e87572a26 Mon Sep 17 00:00:00 2001 From: Matt Dannenberg Date: Thu, 1 Oct 2020 21:56:53 +0000 Subject: [PATCH] util-stats: use service scopeSeparator in MetricBuilder Problem ------- Metric Metadata uses / as the scope separator in all cases. As a result, when service owners configure a custom scope separator (ex, -) the metric names will differ in metrics.json and metric_metadata.json. Solution -------- Create an object in util-stats to store a scope separating character for MetricBuilder and metric_metadata.json to make use of. Result ------ Metric names now align across metrics.json and metric_metadata.json for services with custom configured scope separators JIRA Issues: CSL-10202 Differential Revision: https://phabricator.twitter.biz/D557994 --- .../twitter/server/util/MetricSchemaJsonModule.scala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/server/src/main/scala/com/twitter/server/util/MetricSchemaJsonModule.scala b/server/src/main/scala/com/twitter/server/util/MetricSchemaJsonModule.scala index a7c324d3..6e38f202 100644 --- a/server/src/main/scala/com/twitter/server/util/MetricSchemaJsonModule.scala +++ b/server/src/main/scala/com/twitter/server/util/MetricSchemaJsonModule.scala @@ -4,7 +4,13 @@ import com.fasterxml.jackson.core.JsonGenerator import com.fasterxml.jackson.databind.SerializerProvider import com.fasterxml.jackson.databind.module.SimpleModule import com.fasterxml.jackson.databind.ser.std.StdSerializer -import com.twitter.finagle.stats.{CounterSchema, GaugeSchema, HistogramSchema, MetricSchema} +import com.twitter.finagle.stats.{ + CounterSchema, + GaugeSchema, + HistogramSchema, + MetricSchema, + metadataScopeSeparator +} object SchemaSerializer extends StdSerializer[MetricSchema](classOf[MetricSchema]) { @@ -26,7 +32,9 @@ object SchemaSerializer extends StdSerializer[MetricSchema](classOf[MetricSchema serializerProvider: SerializerProvider ): Unit = { jsonGenerator.writeStartObject() - jsonGenerator.writeStringField("name", metricSchema.metricBuilder.name.mkString("/")) + jsonGenerator.writeStringField( + "name", + metricSchema.metricBuilder.name.mkString(metadataScopeSeparator())) jsonGenerator.writeArrayFieldStart("relative_name") if (metricSchema.metricBuilder.relativeName != Seq.empty) { metricSchema.metricBuilder.relativeName.foreach(segment => jsonGenerator.writeString(segment))