Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
collector: collect releases per cluster
Browse files Browse the repository at this point in the history
Our last iteration on this (4229528)
did not account for the fact that we did have releases grouped by
cluster (but not other attributes, as the original code did). So we're
partially backtracking here, and grouping releases into a grand total
per target cluster.
  • Loading branch information
juliogreff committed Sep 24, 2019
1 parent a45e0ec commit a418306
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions cmd/shipper-state-metrics/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ var (
nil,
)

relsPerClusterDesc = prometheus.NewDesc(
fqn("releases_per_cluster"),
"Number of Release objects per cluster",
[]string{"cluster"},
nil,
)

relDurationDesc = prometheus.NewDesc(
fqn("release_durations"),
"Duration of release objects",
Expand Down Expand Up @@ -156,7 +163,8 @@ func (ssm ShipperStateMetrics) collectReleases(ch chan<- prometheus.Metric) {
now := time.Now()
relAgesByCondition := make(map[string][]float64)

breakdown := make(map[string]float64)
releasesPerCluster := make(map[string]float64)
releasesPerCondition := make(map[string]float64)
conditions := []shipper.ReleaseConditionType{
shipper.ReleaseConditionTypeScheduled,
shipper.ReleaseConditionTypeComplete,
Expand All @@ -171,6 +179,11 @@ func (ssm ShipperStateMetrics) collectReleases(ch chan<- prometheus.Metric) {
appName = "unknown"
}

clusters := strings.Split(rel.Annotations[shipper.ReleaseClustersAnnotation], ",")
for _, cluster := range clusters {
releasesPerCluster[cluster]++
}

for _, c := range conditions {
var reason, status string

Expand All @@ -189,7 +202,7 @@ func (ssm ShipperStateMetrics) collectReleases(ch chan<- prometheus.Metric) {
}

// it's either this or map[string]map[string]map[string]map[string]float64
breakdown[key(rel.Namespace, appName, string(c), status, reason)]++
releasesPerCondition[key(rel.Namespace, appName, string(c), status, reason)]++
}

// We're only interested in incomplete releases, as this metric
Expand All @@ -210,12 +223,14 @@ func (ssm ShipperStateMetrics) collectReleases(ch chan<- prometheus.Metric) {

}

klog.V(4).Infof("releases: %v", breakdown)

for k, v := range breakdown {
for k, v := range releasesPerCondition {
ch <- prometheus.MustNewConstMetric(relsDesc, prometheus.GaugeValue, v, unkey(k)...)
}

for cluster, v := range releasesPerCluster {
ch <- prometheus.MustNewConstMetric(relsPerClusterDesc, prometheus.GaugeValue, v, cluster)
}

for condition, ages := range relAgesByCondition {
count := uint64(len(ages))
sum := Sum(ages)
Expand Down

0 comments on commit a418306

Please sign in to comment.