Skip to content

Commit

Permalink
Make fetching the latest chart version configurable (#43)
Browse files Browse the repository at this point in the history
* Make fetching the latest chart version configurable
  • Loading branch information
jmccarty3 authored Sep 16, 2020
1 parent c0f8ed8 commit 5cbe2aa
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ The following table lists the configurable parameters of the helm-exporter chart
| ingress.hosts[0].host | string | `"chart-example.local"` | Ingress hostname |
| ingress.hosts[0].paths | list | `[]` | Ingress paths |
| ingress.tls | list | `[]` | Ingress TLS configuration (YAML) |
| latestChartVersion | bool | `true` | Specifies whether to fetch the latest chart versions from repositories. |
| nameOverride | string | `""` | Provide a name in place of helm-exporter |
| namespaces | string | `""` | Specifies which namespaces to query for helm 3 metrics. Defaults to all |
| nodeSelector | object | `{}` | helm-exporter node selector [https://kubernetes.io/docs/user-guide/node-selection/](https://kubernetes.io/docs/user-guide/node-selection/ ) |
Expand Down
3 changes: 3 additions & 0 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ spec:
{{- if not .Values.timestampMetric }}
- "-timestamp-metric=false"
{{- end }}
{{- if not .Values.latestChartVersion }}
- "-latest-chart-version=false"
{{- end }}
ports:
- name: http
containerPort: 9571
Expand Down
1 change: 1 addition & 0 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespaces: ""
infoMetric: true
timestampMetric: true
latestChartVersion: true

serviceMonitor:
# Specifies whether a ServiceMonitor should be created
Expand Down
16 changes: 11 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package main

import (
"flag"
"github.com/sstarcher/helm-exporter/config"
"github.com/sstarcher/helm-exporter/registries"
"net/http"
"strconv"
"strings"

"github.com/sstarcher/helm-exporter/config"
"github.com/sstarcher/helm-exporter/registries"

cmap "github.com/orcaman/concurrent-map"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -67,6 +68,8 @@ var (
infoMetric = flag.Bool("info-metric", true, "Generate info metric. Defaults to true")
timestampMetric = flag.Bool("timestamp-metric", true, "Generate timestamps metric. Defaults to true")

fetchLatest = flag.Bool("latest-chart-version", true, "Attempt to fetch the latest chart version from registries. Defaults to true")

statusCodeMap = map[string]float64{
"unknown": 0,
"deployed": 1,
Expand Down Expand Up @@ -112,8 +115,11 @@ func runStats(config config.Config) {
updated := item.Info.LastDeployed.Unix() * 1000
namespace := item.Namespace
status := statusCodeMap[item.Info.Status.String()]
latestVersion := getLatestChartVersionFromHelm(item.Chart.Name(), config.HelmRegistries)
//latestVersion := "3.1.8"
latestVersion := ""

if *fetchLatest {
latestVersion = getLatestChartVersionFromHelm(item.Chart.Name(), config.HelmRegistries)
}

if *infoMetric == true {
statsInfo.WithLabelValues(chart, releaseName, version, appVersion, strconv.FormatInt(updated, 10), namespace, latestVersion).Set(status)
Expand All @@ -127,7 +133,7 @@ func runStats(config config.Config) {

func getLatestChartVersionFromHelm(name string, helmRegistries registries.HelmRegistries) (version string) {
version = helmRegistries.GetLatestVersionFromHelm(name)
log.Warnf("last chart repo version is %v", version)
log.WithField("chart", name).Debugf("last chart repo version is %v", version)
return
}

Expand Down

0 comments on commit 5cbe2aa

Please sign in to comment.