Skip to content

Commit

Permalink
fix: rename metrics and fix version number from git in releases
Browse files Browse the repository at this point in the history
  • Loading branch information
philmtd committed Jun 17, 2022
1 parent c98f2a3 commit a89381a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
command: make go-build-for-docker
- run: mkdir ./circle-artifacts && cp ./o-neko-catnip ./circle-artifacts/
- save_cache:
key: oneko-catnip-artifacts-{{ .Environment.CIRCLE_SHA1 }}
key: oneko-catnip-artifacts-{{ or .Environment.CIRCLE_TAG .Environment.CIRCLE_SHA1 }}
paths:
- ./circle-artifacts/
- store_artifacts:
Expand All @@ -46,7 +46,7 @@ jobs:
- checkout
- setup_remote_docker
- restore_cache:
key: oneko-catnip-artifacts-{{ .Environment.CIRCLE_SHA1 }}
key: oneko-catnip-artifacts-{{ or .Environment.CIRCLE_TAG .Environment.CIRCLE_SHA1 }}
- run: cp ./circle-artifacts/o-neko-catnip .
- run: docker build -t subshellgmbh/o-neko-catnip:latest-dev .
- run: echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
Expand All @@ -59,7 +59,7 @@ jobs:
- checkout
- setup_remote_docker
- restore_cache:
key: oneko-catnip-artifacts-{{ .Environment.CIRCLE_SHA1 }}
key: oneko-catnip-artifacts-{{ or .Environment.CIRCLE_TAG .Environment.CIRCLE_SHA1 }}
- run: cp ./circle-artifacts/o-neko-catnip .
- run: docker build -t subshellgmbh/o-neko-catnip:latest .
- run: docker tag subshellgmbh/o-neko-catnip:latest subshellgmbh/o-neko-catnip:$CIRCLE_TAG
Expand Down
2 changes: 1 addition & 1 deletion go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ GO ?= go
LINTER ?= golangci-lint
GO_TESTSUM ?= gotestsum
GIT_DIRTY := $(shell git diff --quiet || echo '-dirty')
VERSION := $(shell [ -z $(git tag --points-at HEAD) ] || echo $(git tag --points-at HEAD))
VERSION := $(shell [ -z $$(git tag --points-at HEAD) ] && echo "unknown" || echo $$(git tag --points-at HEAD))
COMMIT := $(shell git rev-parse --short HEAD)$(GIT_DIRTY)
LDFLAGS += -ldflags '-extldflags "-static" -s -w -X=main.GitTag=$(VERSION) -X=main.GitCommit=$(COMMIT)' # -s -w reduces binary size by removing some debug information
BUILDFLAGS += -installsuffix cgo --tags release
Expand Down
4 changes: 2 additions & 2 deletions pkg/o-neko-catnip/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func RegisterCommonMetrics(appVersion string) {
func startMonitoringUptime() {
startTime := time.Now()
promauto.NewGaugeFunc(prometheus.GaugeOpts{
Name: "oneko_url_trigger_uptime_duration_seconds",
Name: "oneko_catnip_uptime_duration_seconds",
Help: "The uptime of the application",
}, func() float64 {
return time.Since(startTime).Seconds()
Expand All @@ -32,7 +32,7 @@ func startMonitoringUptime() {

func registerAppInfoMetric(appVersion string) {
promauto.NewGauge(prometheus.GaugeOpts{
Name: "oneko_url_trigger_info",
Name: "oneko_catnip_info",
Help: "Information about this application",
ConstLabels: map[string]string{
"version": appVersion,
Expand Down
4 changes: 2 additions & 2 deletions pkg/o-neko-catnip/oneko/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ func buildClient(conf *config.Config) (*resty.Client, error) {

func startPingMonitor(api *ONekoApi, ctx context.Context) {
onekoPingDuration := promauto.NewHistogram(prometheus.HistogramOpts{
Name: "oneko_url_trigger_api_ping_duration_seconds",
Name: "oneko_catnip_api_ping_duration_seconds",
Help: "Ping duration to the O-Neko base application.",
Buckets: prometheus.DefBuckets,
})
onekoConnected := promauto.NewGauge(prometheus.GaugeOpts{
Name: "oneko_url_trigger_api_connected",
Name: "oneko_catnip_api_connected",
Help: "1 if the API is connected, 0 if not",
})
onekoConnected.Set(0)
Expand Down
8 changes: 4 additions & 4 deletions pkg/o-neko-catnip/oneko/oneko.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,28 @@ func New(configuration *config.Config, ctx context.Context) *ONekoApi {
log: logger.New("oneko"),
cache: requestCache,
wakeupCounter: promauto.NewCounter(prometheus.CounterOpts{
Name: "oneko_url_trigger_wakeups_total",
Name: "oneko_catnip_wakeups_total",
Help: "The number of wakeup API requests done.",
ConstLabels: map[string]string{
"success": "true",
},
}),
errorCounter: promauto.NewCounter(prometheus.CounterOpts{
Name: "oneko_url_trigger_wakeups_total",
Name: "oneko_catnip_wakeups_total",
Help: "The number of wakeup API requests done.",
ConstLabels: map[string]string{
"success": "false",
},
}),
apiCallDuration: promauto.NewHistogram(prometheus.HistogramOpts{
Name: "oneko_url_trigger_api_call_duration_seconds",
Name: "oneko_catnip_api_call_duration_seconds",
Help: "Wakeup API call duration.",
Buckets: prometheus.DefBuckets,
}),
}

promauto.NewGaugeFunc(prometheus.GaugeOpts{
Name: "oneko_url_trigger_cache_size",
Name: "oneko_catnip_cache_size",
Help: "The number of cached API responses",
}, func() float64 {
return float64(len(requestCache.GetKeys()))
Expand Down

0 comments on commit a89381a

Please sign in to comment.