Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4dbc86030 | ||
| e98e425c54 | |||
| 591c427815 |
53
.github/workflows/job_coverage.yml
vendored
Normal file
53
.github/workflows/job_coverage.yml
vendored
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
name: coverage
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main, v3, v4 ]
|
||||||
|
paths-ignore:
|
||||||
|
- '.github/**'
|
||||||
|
- '.gitea/**'
|
||||||
|
pull_request:
|
||||||
|
branches: [ main, v3, v4 ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
build:
|
||||||
|
if: github.server_url != 'https://github.com'
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
filter: 'blob:none'
|
||||||
|
|
||||||
|
- name: setup go
|
||||||
|
uses: actions/setup-go@v5
|
||||||
|
with:
|
||||||
|
cache-dependency-path: "**/*.sum"
|
||||||
|
go-version: 'stable'
|
||||||
|
|
||||||
|
- name: test coverage
|
||||||
|
run: |
|
||||||
|
go test -v -cover ./... -covermode=count -coverprofile coverage.out -coverpkg ./...
|
||||||
|
go tool cover -func coverage.out -o coverage.out
|
||||||
|
|
||||||
|
- name: coverage badge
|
||||||
|
uses: tj-actions/coverage-badge-go@v2
|
||||||
|
with:
|
||||||
|
green: 80
|
||||||
|
filename: coverage.out
|
||||||
|
|
||||||
|
- uses: stefanzweifel/git-auto-commit-action@v4
|
||||||
|
name: autocommit
|
||||||
|
with:
|
||||||
|
commit_message: Apply Code Coverage Badge
|
||||||
|
skip_fetch: false
|
||||||
|
skip_checkout: false
|
||||||
|
file_pattern: ./README.md
|
||||||
|
|
||||||
|
- name: push
|
||||||
|
if: steps.auto-commit-action.outputs.changes_detected == 'true'
|
||||||
|
uses: ad-m/github-push-action@master
|
||||||
|
with:
|
||||||
|
github_token: ${{ github.token }}
|
||||||
|
branch: ${{ github.ref }}
|
||||||
@@ -3,10 +3,10 @@ name: lint
|
|||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
types: [opened, reopened, synchronize]
|
types: [opened, reopened, synchronize]
|
||||||
branches:
|
branches: [ master, v3, v4 ]
|
||||||
- master
|
paths-ignore:
|
||||||
- v3
|
- '.github/**'
|
||||||
- v4
|
- '.gitea/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
lint:
|
lint:
|
||||||
@@ -20,10 +20,10 @@ jobs:
|
|||||||
uses: actions/setup-go@v5
|
uses: actions/setup-go@v5
|
||||||
with:
|
with:
|
||||||
cache-dependency-path: "**/*.sum"
|
cache-dependency-path: "**/*.sum"
|
||||||
go-version: 'stable'
|
go-version: 'stable'
|
||||||
- name: setup deps
|
- name: setup deps
|
||||||
run: go get -v ./...
|
run: go get -v ./...
|
||||||
- name: run lint
|
- name: run lint
|
||||||
uses: https://github.com/golangci/golangci-lint-action@v6
|
uses: golangci/golangci-lint-action@v6
|
||||||
with:
|
with:
|
||||||
version: 'latest'
|
version: 'latest'
|
||||||
@@ -3,15 +3,12 @@ name: test
|
|||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
types: [opened, reopened, synchronize]
|
types: [opened, reopened, synchronize]
|
||||||
branches:
|
branches: [ master, v3, v4 ]
|
||||||
- master
|
|
||||||
- v3
|
|
||||||
- v4
|
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: [ master, v3, v4 ]
|
||||||
- master
|
paths-ignore:
|
||||||
- v3
|
- '.github/**'
|
||||||
- v4
|
- '.gitea/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
@@ -3,15 +3,12 @@ name: test
|
|||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
types: [opened, reopened, synchronize]
|
types: [opened, reopened, synchronize]
|
||||||
branches:
|
branches: [ master, v3, v4 ]
|
||||||
- master
|
|
||||||
- v3
|
|
||||||
- v4
|
|
||||||
push:
|
push:
|
||||||
branches:
|
branches: [ master, v3, v4 ]
|
||||||
- master
|
paths-ignore:
|
||||||
- v3
|
- '.github/**'
|
||||||
- v4
|
- '.gitea/**'
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
@@ -35,19 +32,19 @@ jobs:
|
|||||||
go-version: 'stable'
|
go-version: 'stable'
|
||||||
- name: setup go work
|
- name: setup go work
|
||||||
env:
|
env:
|
||||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
GOWORK: ${{ github.workspace }}/go.work
|
||||||
run: |
|
run: |
|
||||||
go work init
|
go work init
|
||||||
go work use .
|
go work use .
|
||||||
go work use micro-tests
|
go work use micro-tests
|
||||||
- name: setup deps
|
- name: setup deps
|
||||||
env:
|
env:
|
||||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
GOWORK: ${{ github.workspace }}/go.work
|
||||||
run: go get -v ./...
|
run: go get -v ./...
|
||||||
- name: run tests
|
- name: run tests
|
||||||
env:
|
env:
|
||||||
INTEGRATION_TESTS: yes
|
INTEGRATION_TESTS: yes
|
||||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
GOWORK: ${{ github.workspace }}/go.work
|
||||||
run: |
|
run: |
|
||||||
cd micro-tests
|
cd micro-tests
|
||||||
go test -mod readonly -v ./... || true
|
go test -mod readonly -v ./... || true
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
run:
|
run:
|
||||||
concurrency: 8
|
concurrency: 8
|
||||||
deadline: 5m
|
timeout: 5m
|
||||||
issues-exit-code: 1
|
issues-exit-code: 1
|
||||||
tests: true
|
tests: true
|
||||||
|
|||||||
2
README.md
Normal file
2
README.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# micro-meter-prometheus
|
||||||
|

|
||||||
1
go.mod
1
go.mod
@@ -2,7 +2,6 @@ module go.unistack.org/micro-meter-prometheus/v3
|
|||||||
|
|
||||||
go 1.22.0
|
go 1.22.0
|
||||||
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/prometheus/client_golang v1.21.0
|
github.com/prometheus/client_golang v1.21.0
|
||||||
github.com/prometheus/client_model v0.6.1
|
github.com/prometheus/client_model v0.6.1
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ type prometheusMeter struct {
|
|||||||
gauge map[string]*gauges
|
gauge map[string]*gauges
|
||||||
histogram map[string]*histograms
|
histogram map[string]*histograms
|
||||||
summary map[string]*summaries
|
summary map[string]*summaries
|
||||||
sync.Mutex
|
mu *sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
type counters struct {
|
type counters struct {
|
||||||
@@ -79,6 +79,7 @@ func NewMeter(opts ...meter.Option) *prometheusMeter {
|
|||||||
gauge: make(map[string]*gauges),
|
gauge: make(map[string]*gauges),
|
||||||
histogram: make(map[string]*histograms),
|
histogram: make(map[string]*histograms),
|
||||||
summary: make(map[string]*summaries),
|
summary: make(map[string]*summaries),
|
||||||
|
mu: &sync.Mutex{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,8 +101,8 @@ func (m *prometheusMeter) Name() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *prometheusMeter) Counter(name string, labels ...string) meter.Counter {
|
func (m *prometheusMeter) Counter(name string, labels ...string) meter.Counter {
|
||||||
m.Lock()
|
m.mu.Lock()
|
||||||
defer m.Unlock()
|
defer m.mu.Unlock()
|
||||||
nm := m.buildMetric(name)
|
nm := m.buildMetric(name)
|
||||||
labels = append(m.opts.Labels, labels...)
|
labels = append(m.opts.Labels, labels...)
|
||||||
cd, ok := m.counter[nm]
|
cd, ok := m.counter[nm]
|
||||||
@@ -123,8 +124,8 @@ func (m *prometheusMeter) Counter(name string, labels ...string) meter.Counter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *prometheusMeter) FloatCounter(name string, labels ...string) meter.FloatCounter {
|
func (m *prometheusMeter) FloatCounter(name string, labels ...string) meter.FloatCounter {
|
||||||
m.Lock()
|
m.mu.Lock()
|
||||||
defer m.Unlock()
|
defer m.mu.Unlock()
|
||||||
nm := m.buildMetric(name)
|
nm := m.buildMetric(name)
|
||||||
labels = append(m.opts.Labels, labels...)
|
labels = append(m.opts.Labels, labels...)
|
||||||
cd, ok := m.floatCounter[nm]
|
cd, ok := m.floatCounter[nm]
|
||||||
@@ -146,8 +147,8 @@ func (m *prometheusMeter) FloatCounter(name string, labels ...string) meter.Floa
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *prometheusMeter) Gauge(name string, fn func() float64, labels ...string) meter.Gauge {
|
func (m *prometheusMeter) Gauge(name string, fn func() float64, labels ...string) meter.Gauge {
|
||||||
m.Lock()
|
m.mu.Lock()
|
||||||
defer m.Unlock()
|
defer m.mu.Unlock()
|
||||||
nm := m.buildMetric(name)
|
nm := m.buildMetric(name)
|
||||||
labels = append(m.opts.Labels, labels...)
|
labels = append(m.opts.Labels, labels...)
|
||||||
cd, ok := m.gauge[nm]
|
cd, ok := m.gauge[nm]
|
||||||
@@ -169,8 +170,8 @@ func (m *prometheusMeter) Gauge(name string, fn func() float64, labels ...string
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *prometheusMeter) Histogram(name string, labels ...string) meter.Histogram {
|
func (m *prometheusMeter) Histogram(name string, labels ...string) meter.Histogram {
|
||||||
m.Lock()
|
m.mu.Lock()
|
||||||
defer m.Unlock()
|
defer m.mu.Unlock()
|
||||||
nm := m.buildMetric(name)
|
nm := m.buildMetric(name)
|
||||||
labels = append(m.opts.Labels, labels...)
|
labels = append(m.opts.Labels, labels...)
|
||||||
cd, ok := m.histogram[nm]
|
cd, ok := m.histogram[nm]
|
||||||
@@ -192,8 +193,8 @@ func (m *prometheusMeter) Histogram(name string, labels ...string) meter.Histogr
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *prometheusMeter) Summary(name string, labels ...string) meter.Summary {
|
func (m *prometheusMeter) Summary(name string, labels ...string) meter.Summary {
|
||||||
m.Lock()
|
m.mu.Lock()
|
||||||
defer m.Unlock()
|
defer m.mu.Unlock()
|
||||||
nm := m.buildMetric(name)
|
nm := m.buildMetric(name)
|
||||||
labels = append(m.opts.Labels, labels...)
|
labels = append(m.opts.Labels, labels...)
|
||||||
cd, ok := m.summary[nm]
|
cd, ok := m.summary[nm]
|
||||||
@@ -215,8 +216,8 @@ func (m *prometheusMeter) Summary(name string, labels ...string) meter.Summary {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *prometheusMeter) SummaryExt(name string, window time.Duration, quantiles []float64, labels ...string) meter.Summary {
|
func (m *prometheusMeter) SummaryExt(name string, window time.Duration, quantiles []float64, labels ...string) meter.Summary {
|
||||||
m.Lock()
|
m.mu.Lock()
|
||||||
defer m.Unlock()
|
defer m.mu.Unlock()
|
||||||
nm := m.buildMetric(name)
|
nm := m.buildMetric(name)
|
||||||
labels = append(m.opts.Labels, labels...)
|
labels = append(m.opts.Labels, labels...)
|
||||||
cd, ok := m.summary[nm]
|
cd, ok := m.summary[nm]
|
||||||
@@ -277,6 +278,8 @@ func (m *prometheusMeter) Write(w io.Writer, opts ...meter.Option) error {
|
|||||||
|
|
||||||
enc := expfmt.NewEncoder(w, expfmt.NewFormat(expfmt.TypeTextPlain))
|
enc := expfmt.NewEncoder(w, expfmt.NewFormat(expfmt.TypeTextPlain))
|
||||||
|
|
||||||
|
m.mu.Lock()
|
||||||
|
|
||||||
for name, metrics := range m.counter {
|
for name, metrics := range m.counter {
|
||||||
mf := &dto.MetricFamily{
|
mf := &dto.MetricFamily{
|
||||||
Name: newName(name),
|
Name: newName(name),
|
||||||
@@ -352,6 +355,8 @@ func (m *prometheusMeter) Write(w io.Writer, opts ...meter.Option) error {
|
|||||||
mfs = append(mfs, mf)
|
mfs = append(mfs, mf)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.mu.Unlock()
|
||||||
|
|
||||||
for _, mf := range mfs {
|
for _, mf := range mfs {
|
||||||
_ = enc.Encode(mf)
|
_ = enc.Encode(mf)
|
||||||
}
|
}
|
||||||
@@ -370,6 +375,7 @@ func (m *prometheusMeter) Clone(opts ...meter.Option) meter.Meter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &prometheusMeter{
|
return &prometheusMeter{
|
||||||
|
mu: m.mu,
|
||||||
set: m.set,
|
set: m.set,
|
||||||
opts: options,
|
opts: options,
|
||||||
floatCounter: m.floatCounter,
|
floatCounter: m.floatCounter,
|
||||||
|
|||||||
Reference in New Issue
Block a user