Skip to content

Commit 4f5c74b

Browse files
authored
fix(metrics): ReportHistogram impl for stasd (#464)
* fix(metrics): ReportHistogram impl for stasd * chore(docker): replace deprecated bitnami/etcd * chore(ci): run CI on go 1.24 due to deps issue * chore: update missing mocks
1 parent b524a30 commit 4f5c74b

File tree

6 files changed

+60
-31
lines changed

6 files changed

+60
-31
lines changed

.github/workflows/tests.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Set up Go
2121
uses: actions/setup-go@v5
2222
with:
23-
go-version: '1.23'
23+
go-version: '1.24'
2424
- name: Download dependencies
2525
run: go mod download
2626
unit-test:
@@ -33,7 +33,7 @@ jobs:
3333
- name: Set up Go
3434
uses: actions/setup-go@v5
3535
with:
36-
go-version: '1.23'
36+
go-version: '1.24'
3737
- name: Setup dependencies
3838
env:
3939
GO111MODULE: auto
@@ -56,7 +56,7 @@ jobs:
5656
- name: Set up Go
5757
uses: actions/setup-go@v5
5858
with:
59-
go-version: '1.23'
59+
go-version: '1.24'
6060
- name: Run tests
6161
run: make e2e-test-nats
6262
e2e-test-grpc:
@@ -69,6 +69,6 @@ jobs:
6969
- name: Set up Go
7070
uses: actions/setup-go@v5
7171
with:
72-
go-version: '1.23'
72+
go-version: '1.24'
7373
- name: Run tests
7474
run: make e2e-test-grpc

examples/testing/docker-compose.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
version: '3'
21
services:
32
nats:
43
image: nats
54
ports:
65
- 4222:4222
76
etcd:
8-
image: bitnami/etcd
9-
environment:
10-
- ALLOW_NONE_AUTHENTICATION=yes
7+
image: quay.io/coreos/etcd:v3.5.15
8+
command:
9+
- /usr/local/bin/etcd
10+
- --listen-client-urls=http://0.0.0.0:2379
11+
- --advertise-client-urls=http://0.0.0.0:2379
1112
ports:
1213
- 2379:2379
1314
redis:

metrics/mocks/statsd_reporter.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

metrics/prometheus_reporter.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type PrometheusReporter struct {
5151
additionalLabels map[string]string
5252
}
5353

54+
var _ Reporter = (*PrometheusReporter)(nil)
55+
5456
func (p *PrometheusReporter) registerCustomMetrics(
5557
constLabels map[string]string,
5658
additionalLabelsKeys []string,

metrics/statsd_reporter.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ package metrics
2323
import (
2424
"fmt"
2525

26-
"github.com/topfreegames/pitaya/v2/constants"
27-
2826
"github.com/DataDog/datadog-go/statsd"
2927
"github.com/topfreegames/pitaya/v2/config"
3028
"github.com/topfreegames/pitaya/v2/logger"
@@ -35,6 +33,7 @@ type Client interface {
3533
Count(name string, value int64, tags []string, rate float64) error
3634
Gauge(name string, value float64, tags []string, rate float64) error
3735
TimeInMilliseconds(name string, value float64, tags []string, rate float64) error
36+
Histogram(name string, value float64, tags []string, rate float64) error
3837
}
3938

4039
// StatsdReporter sends application metrics to statsd
@@ -45,6 +44,8 @@ type StatsdReporter struct {
4544
defaultTags []string
4645
}
4746

47+
var _ Reporter = (*StatsdReporter)(nil)
48+
4849
// NewStatsdReporter returns an instance of statsd reportar and an
4950
// error if something fails
5051
func NewStatsdReporter(
@@ -143,5 +144,16 @@ func (s *StatsdReporter) ReportSummary(metric string, tagsMap map[string]string,
143144

144145
// ReportHistogram observes the histogram value and reports to statsd
145146
func (s *StatsdReporter) ReportHistogram(metric string, tagsMap map[string]string, value float64) error {
146-
return constants.ErrNotImplemented
147+
fullTags := s.defaultTags
148+
149+
for k, v := range tagsMap {
150+
fullTags = append(fullTags, fmt.Sprintf("%s:%s", k, v))
151+
}
152+
153+
err := s.client.Histogram(metric, value, fullTags, s.rate)
154+
if err != nil {
155+
logger.Log.Errorf("failed to report histogram: %q", err)
156+
}
157+
158+
return err
147159
}

mocks/acceptor.go

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)