Skip to content

Commit

Permalink
add time series id to v2.json output
Browse files Browse the repository at this point in the history
Update v2.json output to include the id for a time series.
This can be useful when matching without output from other
sources such as streaming data. For consistency also updates
the LWC/fetch output to include the offset dimension.
  • Loading branch information
brharrington committed Feb 12, 2024
1 parent 1677c6d commit a3e36ee
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.netflix.atlas.chart.util.PngImage
import com.netflix.atlas.core.model.ArrayTimeSeq
import com.netflix.atlas.core.model.CollectorStats
import com.netflix.atlas.core.model.DsType
import com.netflix.atlas.core.model.TaggedItem
import com.netflix.atlas.core.model.TimeSeries
import com.netflix.atlas.core.util.Streams
import com.netflix.atlas.core.util.Strings
Expand Down Expand Up @@ -281,6 +282,10 @@ private[chart] object JsonCodec {
): Unit = {
gen.writeStartObject()
gen.writeStringField("type", "timeseries")
line.query.foreach { q =>
val id = TaggedItem.computeId(line.data.tags + ("atlas.query" -> q)).toString
gen.writeStringField("id", id)
}
gen.writeNumberField("plot", plot)
gen.writeStringField("label", line.data.label)
gen.writeFieldName("color")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ case class Grapher(settings: DefaultSettings) {

LineDef(
data = t,
query = Some(s.expr.toString),
query = Some(s.toString),
groupByKeys = s.expr.finalGrouping,
color = color,
lineStyle = s.lineStyle.fold(dfltStyle)(s => LineStyle.valueOf(s.toUpperCase)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ package com.netflix.atlas.eval.model

import com.fasterxml.jackson.core.JsonGenerator
import com.netflix.atlas.core.model.*
import com.netflix.atlas.core.util.Strings
import com.netflix.atlas.json.JsonSupport

import java.time.Duration

/**
* Message type use for emitting time series data in LWC and fetch responses.
*
Expand Down Expand Up @@ -110,7 +113,9 @@ object TimeSeriesMessage {
*/
def apply(expr: StyleExpr, context: EvalContext, ts: TimeSeries): TimeSeriesMessage = {
val query = expr.toString
val id = TaggedItem.computeId(ts.tags + ("atlas.query" -> query)).toString
val offset = Strings.toString(Duration.ofMillis(expr.offset))
val outputTags = ts.tags ++ Map(TagKey.offset -> offset, "atlas.query" -> query)
val id = TaggedItem.computeId(outputTags).toString
val data = ts.data.bounded(context.start, context.end)
TimeSeriesMessage(
id,
Expand All @@ -120,7 +125,7 @@ object TimeSeriesMessage {
context.end,
context.step,
ts.label,
ts.tags,
outputTags,
ArrayData(data.data)
)
}
Expand Down

0 comments on commit a3e36ee

Please sign in to comment.