From 6b3547381af51dea8a208aef6efe25e0daa3a781 Mon Sep 17 00:00:00 2001 From: gauravgpta93 Date: Wed, 4 Sep 2024 16:20:03 -0400 Subject: [PATCH 1/3] Add support for gauge metric in static-exporter, keep default as `counter` to avoid any changes for other places --- static-exporter/main.libsonnet | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/static-exporter/main.libsonnet b/static-exporter/main.libsonnet index 229d9bc4e..7e65cfee1 100644 --- a/static-exporter/main.libsonnet +++ b/static-exporter/main.libsonnet @@ -35,7 +35,7 @@ local k = import 'ksonnet-util/kausal.libsonnet'; function(acc, metric) acc + [ '# HELP %(name)s %(description)s' % metric, - '# TYPE %(name)s counter' % metric, + '# TYPE %(name)s %(metricType)s' % metric, ] + [ metric.name + value for value in metric.values @@ -47,14 +47,17 @@ local k = import 'ksonnet-util/kausal.libsonnet'; }), metric:: { - new(name, description):: + new(name, description, metricType="counter"):: self.withName(name) - + self.withDescription(description), + + self.withDescription(description) + + self.withMetricType(metricType), withName(name): { name: name }, withDescription(description): { description: description }, + withMetricType(metricType): { type: metricType }, + local generateValues(labelMap, value=1) = local labels = [ key + '="' + labelMap[key] + '"' From 0998771bfa96991dc3cdd852b0db3710b96aa44a Mon Sep 17 00:00:00 2001 From: gauravgpta93 Date: Wed, 4 Sep 2024 16:32:33 -0400 Subject: [PATCH 2/3] Fix lint --- static-exporter/main.libsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static-exporter/main.libsonnet b/static-exporter/main.libsonnet index 7e65cfee1..aebfa51be 100644 --- a/static-exporter/main.libsonnet +++ b/static-exporter/main.libsonnet @@ -47,7 +47,7 @@ local k = import 'ksonnet-util/kausal.libsonnet'; }), metric:: { - new(name, description, metricType="counter"):: + new(name, description, metricType='counter'):: self.withName(name) + self.withDescription(description) + self.withMetricType(metricType), From d823f7249196a0290e096727f8c8a1e8fe2da6b0 Mon Sep 17 00:00:00 2001 From: gauravgpta93 Date: Thu, 5 Sep 2024 21:03:35 -0400 Subject: [PATCH 3/3] Change the variable name from `metricType` to `type` --- static-exporter/main.libsonnet | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/static-exporter/main.libsonnet b/static-exporter/main.libsonnet index aebfa51be..8ea129923 100644 --- a/static-exporter/main.libsonnet +++ b/static-exporter/main.libsonnet @@ -35,7 +35,7 @@ local k = import 'ksonnet-util/kausal.libsonnet'; function(acc, metric) acc + [ '# HELP %(name)s %(description)s' % metric, - '# TYPE %(name)s %(metricType)s' % metric, + '# TYPE %(name)s %(type)s' % metric, ] + [ metric.name + value for value in metric.values @@ -47,16 +47,16 @@ local k = import 'ksonnet-util/kausal.libsonnet'; }), metric:: { - new(name, description, metricType='counter'):: + new(name, description, type='counter'):: self.withName(name) + self.withDescription(description) - + self.withMetricType(metricType), + + self.withMetricType(type), withName(name): { name: name }, withDescription(description): { description: description }, - withMetricType(metricType): { type: metricType }, + withMetricType(type): { type: type }, local generateValues(labelMap, value=1) = local labels = [