Skip to content

Commit

Permalink
feat(golang): add metrics annotation min_replica values #32
Browse files Browse the repository at this point in the history
  • Loading branch information
jplanckeel authored Aug 8, 2022
2 parents 2f75a8d + 217807a commit 7b4f1cc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
paths:
- .github/workflows/go-test.yml
- pkg/**
- cmd/**
- docs/**
- generated/**
Expand All @@ -27,6 +28,8 @@ jobs:

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
args: --timeout=30m

test:
name: Go test
Expand Down
19 changes: 14 additions & 5 deletions pkg/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ import (
)

type prescalingCollector struct {
desiredMetrics *prometheus.Desc
prescaleMetrics *prometheus.Desc
minMetrics *prometheus.Desc
prescaling prescaling.IPrescaling
}

func NewPrescalingCollector(p prescaling.IPrescaling) prometheus.Collector {
return &prescalingCollector{
desiredMetrics: prometheus.NewDesc(
prescaleMetrics: prometheus.NewDesc(
"prescale_metric",
"Number used for prescale application",
[]string{"project", "deployment", "namespace"},
nil,
),minMetrics: prometheus.NewDesc(
"min_replica",
"Number of pod desired for prescale",
[]string{"project", "deployment", "namespace"},
Expand All @@ -26,7 +32,8 @@ func NewPrescalingCollector(p prescaling.IPrescaling) prometheus.Collector {
}

func (collector *prescalingCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- collector.desiredMetrics
ch <- collector.prescaleMetrics
ch <- collector.minMetrics
}

func (collector *prescalingCollector) Collect(ch chan<- prometheus.Metric) {
Expand Down Expand Up @@ -56,6 +63,8 @@ func (collector *prescalingCollector) Collect(ch chan<- prometheus.Metric) {
func (collector *prescalingCollector) addDataToMetrics(ch chan<- prometheus.Metric, multiplier int, hpa prescaling.Hpa) {
eventInRangeTime := utils.InRangeTime(hpa.Start, hpa.End, collector.prescaling.GetEventService().GetClock().Now())
desiredScalingType := prescaling.DesiredScaling(eventInRangeTime, multiplier, hpa.Replica, hpa.CurrentReplicas)
metric := prometheus.MustNewConstMetric(collector.desiredMetrics, prometheus.GaugeValue, float64(desiredScalingType), hpa.Project, hpa.Deployment, hpa.Namespace)
ch <- metric
prescaleMetric := prometheus.MustNewConstMetric(collector.prescaleMetrics, prometheus.GaugeValue, float64(desiredScalingType), hpa.Project, hpa.Deployment, hpa.Namespace)
minMetric := prometheus.MustNewConstMetric(collector.minMetrics, prometheus.GaugeValue, float64(hpa.Replica), hpa.Project, hpa.Deployment, hpa.Namespace)
ch <- prescaleMetric
ch <- minMetric
}

0 comments on commit 7b4f1cc

Please sign in to comment.