Renamed ServiceReplicasCounter to ServiceReplicasGauge

To avoid future confusion, this fix renames ServiceReplicasCounter to
ServiceReplicasGauge.

Signed-off-by: Ken Fukuyama <kenfdev@gmail.com>
This commit is contained in:
Ken Fukuyama
2018-08-12 15:58:37 +09:00
committed by Alex Ellis
parent 4fabd50799
commit 9ceac9c67e
3 changed files with 10 additions and 10 deletions

View File

@ -35,7 +35,7 @@ func NewExporter(options MetricOptions) *Exporter {
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
e.metricOptions.GatewayFunctionInvocation.Describe(ch)
e.metricOptions.GatewayFunctionsHistogram.Describe(ch)
e.metricOptions.ServiceReplicasCounter.Describe(ch)
e.metricOptions.ServiceReplicasGauge.Describe(ch)
}
// Collect collects data to be consumed by prometheus
@ -43,13 +43,13 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
e.metricOptions.GatewayFunctionInvocation.Collect(ch)
e.metricOptions.GatewayFunctionsHistogram.Collect(ch)
e.metricOptions.ServiceReplicasCounter.Reset()
e.metricOptions.ServiceReplicasGauge.Reset()
for _, service := range e.services {
e.metricOptions.ServiceReplicasCounter.
e.metricOptions.ServiceReplicasGauge.
WithLabelValues(service.Name).
Set(float64(service.Replicas))
}
e.metricOptions.ServiceReplicasCounter.Collect(ch)
e.metricOptions.ServiceReplicasGauge.Collect(ch)
}
// StartServiceWatcher starts a ticker and collects service replica counts to expose to prometheus

View File

@ -53,10 +53,10 @@ func Test_Describe_DescribesThePrometheusMetrics(t *testing.T) {
t.Errorf("Want %s, got: %s", expectedGatewayFunctionsHistogramDesc, actualGatewayFunctionsHistogramDesc)
}
d = (<-ch)
expectedServiceReplicasCounterDesc := `Desc{fqName: "gateway_service_count", help: "Docker service replicas", constLabels: {}, variableLabels: [function_name]}`
actualServiceReplicasCounterDesc := d.String()
if expectedServiceReplicasCounterDesc != actualServiceReplicasCounterDesc {
t.Errorf("Want %s, got: %s", expectedServiceReplicasCounterDesc, actualServiceReplicasCounterDesc)
expectedServiceReplicasGaugeDesc := `Desc{fqName: "gateway_service_count", help: "Docker service replicas", constLabels: {}, variableLabels: [function_name]}`
actualServiceReplicasGaugeDesc := d.String()
if expectedServiceReplicasGaugeDesc != actualServiceReplicasGaugeDesc {
t.Errorf("Want %s, got: %s", expectedServiceReplicasGaugeDesc, actualServiceReplicasGaugeDesc)
}
}

View File

@ -13,7 +13,7 @@ import (
type MetricOptions struct {
GatewayFunctionInvocation *prometheus.CounterVec
GatewayFunctionsHistogram *prometheus.HistogramVec
ServiceReplicasCounter *prometheus.GaugeVec
ServiceReplicasGauge *prometheus.GaugeVec
}
// PrometheusHandler Bootstraps prometheus for metrics collection
@ -47,7 +47,7 @@ func BuildMetricsOptions() MetricOptions {
metricsOptions := MetricOptions{
GatewayFunctionsHistogram: gatewayFunctionsHistogram,
GatewayFunctionInvocation: gatewayFunctionInvocation,
ServiceReplicasCounter: serviceReplicas,
ServiceReplicasGauge: serviceReplicas,
}
return metricsOptions