Skip to content

Commit 9ceabb9

Browse files
authored
Add option to disable metrics collection logging (#82)
* exporter: implement option for disabling metric collection logging * helm: add helm chart option to disable metric collection logging * exporter: move log metric collection parse err earlier * bump version and add docs to README
1 parent ad3ffa3 commit 9ceabb9

File tree

6 files changed

+22
-6
lines changed

6 files changed

+22
-6
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Helm Chart with values and deployment can be found [here](./helm/github-rate-lim
1010

1111
For the exporter to run you need to supply either a GitHub Token or a set of a GitHub App credentials, alongside with a type of authentication to use(pat/app)
1212

13+
You can use the environment variable `GITHUB_LOG_METRIC_COLLECTION` (boolean) to control if rate limit metrics are also logged to the console when they're collected by Prometheus. As the functionality is backed by [Golang `strconv.ParseBool`](https://pkg.go.dev/strconv#ParseBool), it accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other value or lack thereof will default to enabling logs.
14+
1315
### The metrics can then be represented on a [grafana](https://grafana.com) dashboard
1416

1517

helm/github-rate-limits-prometheus-exporter/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.2.12
18+
version: 0.2.13
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "v3.0.0"
24+
appVersion: "v3.1.0"

helm/github-rate-limits-prometheus-exporter/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ spec:
3434
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
3535
imagePullPolicy: {{ .Values.image.pullPolicy }}
3636
env:
37+
- name: GITHUB_LOG_METRIC_COLLECTION
38+
value: {{ .Values.logging.logMetricCollection | default "true" }}
3739
{{- if eq .Values.github.authType "app" }}
3840
- name: GITHUB_AUTH_TYPE
3941
value: {{ .Values.github.authType | upper | quote }}

helm/github-rate-limits-prometheus-exporter/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ github:
1717

1818
replicaCount: 1
1919

20+
logging:
21+
logMetricCollection: true
22+
2023
image:
2124
repository: ghcr.io/kalgurn/grl-exporter
2225
pullPolicy: IfNotPresent

internal/prometheus_exporter/server.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package prometheus_exporter
33
import (
44
"log"
55
"net/http"
6+
"strconv"
67
"time"
78

89
"github.com/kalgurn/github-rate-limits-prometheus-exporter/internal/github_client"
@@ -12,7 +13,8 @@ import (
1213
)
1314

1415
var (
15-
githubAccount = utils.GetOSVar("GITHUB_ACCOUNT_NAME")
16+
githubAccount = utils.GetOSVar("GITHUB_ACCOUNT_NAME")
17+
logMetricCollection, logMetricCollectionParseErr = strconv.ParseBool(utils.GetOSVar("GITHUB_LOG_METRIC_COLLECTION"))
1618
)
1719

1820
func newLimitsCollector() *LimitsCollector {
@@ -51,8 +53,10 @@ func (collector *LimitsCollector) Collect(ch chan<- prometheus.Metric) {
5153

5254
auth := github_client.InitConfig()
5355
limits := github_client.GetRemainingLimits(auth.InitClient())
54-
log.Printf("Collected metrics for %s", githubAccount)
55-
log.Printf("Limit: %d | Used: %d | Remaining: %d", limits.Limit, limits.Used, limits.Remaining)
56+
if logMetricCollection {
57+
log.Printf("Collected metrics for %s", githubAccount)
58+
log.Printf("Limit: %d | Used: %d | Remaining: %d", limits.Limit, limits.Used, limits.Remaining)
59+
}
5660
//Write latest value for each metric in the prometheus metric channel.
5761
//Note that you can pass CounterValue, GaugeValue, or UntypedValue types here.
5862
m1 := prometheus.MustNewConstMetric(collector.LimitTotal, prometheus.GaugeValue, float64(limits.Limit))
@@ -70,6 +74,11 @@ func (collector *LimitsCollector) Collect(ch chan<- prometheus.Metric) {
7074
}
7175

7276
func Run() {
77+
// Default to logging metric collection
78+
if logMetricCollectionParseErr != nil {
79+
logMetricCollection = true
80+
}
81+
7382
limit := newLimitsCollector()
7483
prometheus.NewRegistry()
7584
prometheus.MustRegister(limit)

version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"name": "github-rate-limits-prometheus-exporter",
3-
"version": "3.0.0"
3+
"version": "3.1.0"
44
}

0 commit comments

Comments
 (0)