Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chart: more heatmap graph examples. #1

Open
wants to merge 2 commits into
base: heatmap3
Choose a base branch
from
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@
package com.netflix.atlas.chart

import com.netflix.atlas.chart.model.GraphDef
import com.netflix.atlas.chart.model.HeatmapDef
import com.netflix.atlas.chart.model.LineDef
import com.netflix.atlas.chart.model.LineStyle
import com.netflix.atlas.chart.model.Palette
import com.netflix.atlas.chart.model.PlotDef
import com.netflix.atlas.core.model.ArrayTimeSeq
import com.netflix.atlas.core.model.DsType
import com.netflix.atlas.core.model.TimeSeries
import munit.FunSuite

import java.awt.Color
import java.time.Instant

class JsonCodecSuite extends FunSuite {
Expand All @@ -46,4 +52,94 @@ class JsonCodecSuite extends FunSuite {
val str = JsonCodec.encode(gdef)
assert(!str.contains(""""type":"graph-image""""))
}

private def generateHeatmap(
isPercentile: Boolean = false,
heatmapDef: Option[HeatmapDef]
): GraphDef = {
val dpsA = new Array[Double](60)
java.util.Arrays.fill(dpsA, 1)
val dpsB = new Array[Double](60)
java.util.Arrays.fill(dpsB, 10)
val timeseries = if (isPercentile) {
List(
LineDef(
TimeSeries(
Map("percentile" -> "T0042"),
new ArrayTimeSeq(DsType.Gauge, 0L, 60_000, dpsA)
),
lineStyle = LineStyle.HEATMAP
),
LineDef(
TimeSeries(
Map("percentile" -> "T0048"),
new ArrayTimeSeq(DsType.Gauge, 0L, 60_000, dpsB)
),
lineStyle = LineStyle.HEATMAP
)
)
} else {
List(
LineDef(
TimeSeries(
Map("series" -> "0"),
new ArrayTimeSeq(DsType.Gauge, 0L, 60_000, dpsA)
),
lineStyle = LineStyle.HEATMAP
),
LineDef(
TimeSeries(
Map("series" -> "1"),
new ArrayTimeSeq(DsType.Gauge, 0L, 60_000, dpsB)
),
lineStyle = LineStyle.HEATMAP
)
)
}

val plotDef = PlotDef(
timeseries,
scale = PlotDef(List.empty).scale,
heatmap = heatmapDef
)

GraphDef(
List(plotDef),
Instant.ofEpochMilli(0L),
Instant.ofEpochMilli(3_600_000)
)
}

test("v2 heatmap") {
val gdef = generateHeatmap(heatmapDef =
Some(
HeatmapDef(
palette = Some(Palette.fromArray("heatmap", Array(Color.RED)))
)
)
)
val str = JsonCodec.encode(gdef)
assert(str.contains(""""type":"heatmap""""))
assert(str.contains(""""data":{"type":"heatmap""""))
assert(str.contains(""""label":"10.0""""))
val obtained = JsonCodec.decode(str)
assertEquals(obtained, gdef)
}

test("v2 percentile heatmap") {
val gdef = generateHeatmap(
true,
Some(
HeatmapDef(
palette = Some(Palette.fromArray("heatmap", Array(Color.RED)))
)
)
)
val str = JsonCodec.encode(gdef)
assert(str.contains(""""type":"heatmap""""))
assert(str.contains(""""data":{"type":"heatmap""""))
assert(str.contains(""""label":"percentile=T0048""""))
val obtained = JsonCodec.decode(str)
assertEquals(obtained, gdef)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import java.time.ZoneId
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.time.temporal.ChronoUnit

import com.netflix.atlas.chart.model.PlotBound.AutoData
import com.netflix.atlas.chart.model.PlotBound.Explicit
import com.netflix.atlas.chart.model._
Expand Down Expand Up @@ -151,8 +150,14 @@ abstract class PngGraphEngineSuite extends FunSuite {
}

def loadV2(resource: String): GraphDef = {
Using.resource(Streams.gzip(Streams.resource(resource))) { in =>
JsonCodec.decode(in)
if (resource.endsWith(".gz")) {
Using.resource(Streams.gzip(Streams.resource(resource))) { in =>
JsonCodec.decode(in)
}
} else {
Using.resource(Streams.resource(resource)) { in =>
JsonCodec.decode(in)
}
}
}

Expand Down Expand Up @@ -804,6 +809,27 @@ abstract class PngGraphEngineSuite extends FunSuite {
check("heatmap_timer.png", graphDef)
}

test("heatmap_timer_log") {
val graphDef = loadV2(s"$dataDir/heatmap_timer.json.gz").adjustPlots(
_.copy(scale = Scale.LOGARITHMIC)
)
check("heatmap_timer_log.png", graphDef)
}

test("heatmap_timer_power2") {
val graphDef = loadV2(s"$dataDir/heatmap_timer.json.gz").adjustPlots(
_.copy(scale = Scale.POWER_2)
)
check("heatmap_timer_power2.png", graphDef)
}

test("heatmap_timer_sqrt") {
val graphDef = loadV2(s"$dataDir/heatmap_timer.json.gz").adjustPlots(
_.copy(scale = Scale.SQRT)
)
check("heatmap_timer_sqrt.png", graphDef)
}

test("heatmap_timer2") {
val graphDef = loadV2(s"$dataDir/heatmap_timer2.json.gz")
check("heatmap_timer2.png", graphDef)
Expand Down Expand Up @@ -880,10 +906,20 @@ abstract class PngGraphEngineSuite extends FunSuite {
check("heatmap_timer_small.png", graphDef)
}

test("heatmap_single_ptile") {
val graphDef = loadV2(s"$dataDir/heatmap_single_ptile.json.gz")
check("heatmap_single_ptile.png", graphDef)
}

test("heatmap_dist") {
val graphDef = loadV2(s"$dataDir/heatmap_dist.json.gz")
check("heatmap_dist.png", graphDef)
}

test("heatmap_empty") {
val graphDef = loadV2(s"$dataDir/heatmap_empty.json.gz")
check("heatmap_empty.png", graphDef)
}
}

case class GraphData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ class GrapherSuite extends FunSuite {
imageTest("heatmap params") {
"/api/v1/graph?e=2012-01-01&q=name,sps,:eq,:sum,(,nf.cluster,),:by,:heatmap&heatmap_palette=greens&heatmap_scale=sqrt&heatmap_u=5&heatmap_label=foo"
}

imageTest("named colors: blue with light theme") {
"/api/v1/graph?e=2012-01-01&q=1,blue1,:color,1,blue2,:color,1,blue3,:color&stack=1&theme=light"
}
Expand Down