17 Commits

Author SHA1 Message Date
997f062023 fixup and copy from v4
All checks were successful
test / test (push) Successful in 2m45s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2025-03-04 14:31:15 +03:00
1dbf610d02 reuse sync.Map
All checks were successful
test / test (push) Successful in 2m52s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2025-01-20 12:43:22 +03:00
0f9ff3fe38 Merge pull request 'Update workflows' (#109) from atolstikhin/micro-meter-prometheus:v3 into v3
All checks were successful
test / test (push) Successful in 4m56s
Reviewed-on: #109
2024-12-19 19:53:21 +03:00
3dcb589de9 Merge branch 'v3' into v3
Some checks failed
automerge / automerge (pull_request) Failing after 20s
autoapprove / autoapprove (pull_request) Failing after 1m38s
lint / lint (pull_request) Successful in 3m59s
dependabot-automerge / automerge (pull_request) Failing after 13m39s
test / test (pull_request) Successful in 15m58s
2024-12-15 17:51:38 +03:00
3c23fa1343 fixup lint
Some checks failed
codeql / analyze (go) (push) Failing after 5m32s
build / lint (push) Successful in 1m5s
build / test (push) Failing after 1m58s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-12-15 17:51:29 +03:00
Aleksandr Tolstikhin
8aecd80e99 Update workflows
Some checks failed
automerge / automerge (pull_request) Has been skipped
dependabot-automerge / automerge (pull_request) Has been skipped
autoapprove / autoapprove (pull_request) Successful in 6s
test / test (pull_request) Successful in 1m23s
lint / lint (pull_request) Failing after 27s
2024-12-14 01:35:16 +07:00
d4472e1ab2 partially fix race cond
Some checks failed
codeql / analyze (go) (push) Failing after 49s
build / test (push) Failing after 4m54s
build / lint (push) Successful in 9m28s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-11-08 15:27:05 +03:00
6f6d362c20 experimental race free labels
Some checks failed
codeql / analyze (go) (push) Failing after 44s
build / test (push) Failing after 4m52s
build / lint (push) Successful in 9m27s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-11-07 16:49:16 +03:00
dd71d9ec59 add locking
Some checks failed
codeql / analyze (go) (push) Failing after 44s
build / test (push) Failing after 4m56s
build / lint (push) Successful in 9m35s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-11-06 00:00:17 +03:00
da9201efff lower memory usage
Some checks failed
codeql / analyze (go) (push) Failing after 35s
build / test (push) Failing after 4m53s
build / lint (push) Successful in 9m30s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-10-06 13:45:33 +03:00
fc9be7fb46 update deps, minimise memory allocations
Some checks failed
build / test (push) Failing after 9s
build / lint (push) Failing after 8s
codeql / analyze (go) (push) Failing after 11s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-09-20 18:50:08 +03:00
1dc55cc0c9 register std metrics once on init
Some checks failed
build / test (push) Has been cancelled
build / lint (push) Has been cancelled
codeql / analyze (go) (push) Has been cancelled
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-04-15 08:00:38 +03:00
21494e0e7a prometheus fixup panics and interface conversations
Some checks are pending
build / test (push) Waiting to run
build / lint (push) Waiting to run
codeql / analyze (go) (push) Waiting to run
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-04-15 00:49:09 +03:00
0975e8fb4d fixup panics and interface conversations
Some checks failed
build / lint (push) Waiting to run
codeql / analyze (go) (push) Waiting to run
build / test (push) Failing after 14m2s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-04-15 00:34:55 +03:00
8dfa97b54f rewrite to use sync.Map
Some checks failed
build / test (push) Failing after 1m29s
codeql / analyze (go) (push) Failing after 1m38s
build / lint (push) Has been cancelled
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-04-15 00:27:15 +03:00
439d5cf125 fixup golang std metrics
Some checks failed
build / test (push) Failing after 1m23s
codeql / analyze (go) (push) Failing after 2m37s
build / lint (push) Successful in 9m31s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-04-04 16:36:48 +03:00
e02f291db2 fixup uniq labels
Some checks failed
build / test (push) Has been cancelled
build / lint (push) Has been cancelled
codeql / analyze (go) (push) Has been cancelled
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2024-03-27 11:49:31 +03:00
16 changed files with 49 additions and 236 deletions

View File

@@ -3,10 +3,10 @@ name: lint
on: on:
pull_request: pull_request:
types: [opened, reopened, synchronize] types: [opened, reopened, synchronize]
branches: [ master, v3, v4 ] branches:
paths-ignore: - master
- '.github/**' - v3
- '.gitea/**' - v4
jobs: jobs:
lint: lint:
@@ -24,6 +24,6 @@ jobs:
- name: setup deps - name: setup deps
run: go get -v ./... run: go get -v ./...
- name: run lint - name: run lint
uses: golangci/golangci-lint-action@v6 uses: https://github.com/golangci/golangci-lint-action@v6
with: with:
version: 'latest' version: 'latest'

View File

@@ -3,12 +3,15 @@ name: test
on: on:
pull_request: pull_request:
types: [opened, reopened, synchronize] types: [opened, reopened, synchronize]
branches: [ master, v3, v4 ] branches:
- master
- v3
- v4
push: push:
branches: [ master, v3, v4 ] branches:
paths-ignore: - master
- '.github/**' - v3
- '.gitea/**' - v4
jobs: jobs:
test: test:

View File

@@ -3,12 +3,15 @@ name: test
on: on:
pull_request: pull_request:
types: [opened, reopened, synchronize] types: [opened, reopened, synchronize]
branches: [ master, v3, v4 ] branches:
- master
- v3
- v4
push: push:
branches: [ master, v3, v4 ] branches:
paths-ignore: - master
- '.github/**' - v3
- '.gitea/**' - v4
jobs: jobs:
test: test:
@@ -32,19 +35,19 @@ jobs:
go-version: 'stable' go-version: 'stable'
- name: setup go work - name: setup go work
env: env:
GOWORK: ${{ github.workspace }}/go.work GOWORK: /workspace/${{ github.repository_owner }}/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: ${{ github.workspace }}/go.work GOWORK: /workspace/${{ github.repository_owner }}/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: ${{ github.workspace }}/go.work GOWORK: /workspace/${{ github.repository_owner }}/go.work
run: | run: |
cd micro-tests cd micro-tests
go test -mod readonly -v ./... || true go test -mod readonly -v ./... || true

View File

@@ -1,28 +0,0 @@
name: "autoapprove"
on:
pull_request_target:
types: [assigned, opened, synchronize, reopened]
workflow_run:
workflows: ["prbuild"]
types:
- completed
permissions:
pull-requests: write
contents: write
jobs:
autoapprove:
runs-on: ubuntu-latest
steps:
- name: approve
run: [ "curl -o tea https://dl.gitea.com/tea/main/tea-main-linux-amd64",
"chmod +x ./tea",
"./tea login add --name unistack --token ${{ secrets.GITHUB_TOKEN }} --url https://git.unistack.org",
"./tea pr --repo ${{ github.event.repository.name }}"
]
if: github.actor == 'vtolstov'
id: approve
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,53 +0,0 @@
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 }}

View File

@@ -1,94 +0,0 @@
name: sync
on:
schedule:
- cron: '*/5 * * * *'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
jobs:
sync:
if: github.server_url != 'https://github.com'
runs-on: ubuntu-latest
steps:
- name: init
run: |
git config --global user.email "vtolstov <vtolstov@users.noreply.github.com>"
git config --global user.name "github-actions[bot]"
echo "machine git.unistack.org login vtolstov password ${{ secrets.TOKEN_GITEA }}" >> /root/.netrc
echo "machine github.com login vtolstov password ${{ secrets.TOKEN_GITHUB }}" >> /root/.netrc
- name: check master
id: check_master
run: |
src_hash=$(git ls-remote https://github.com/${GITHUB_REPOSITORY} refs/heads/master | cut -f1)
dst_hash=$(git ls-remote ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} refs/heads/master | cut -f1)
echo "src_hash=$src_hash"
echo "dst_hash=$dst_hash"
if [ "$src_hash" != "$dst_hash" ]; then
echo "sync_needed=true" >> $GITHUB_OUTPUT
else
echo "sync_needed=false" >> $GITHUB_OUTPUT
fi
- name: sync master
if: steps.check_master.outputs.sync_needed == 'true'
run: |
git clone --filter=blob:none --filter=tree:0 --branch master --single-branch ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} repo
cd repo
git remote add --no-tags --fetch --track master upstream https://github.com/${GITHUB_REPOSITORY}
git pull --rebase upstream master
git push upstream master --progress
git push origin master --progress
cd ../
rm -rf repo
- name: check v3
id: check_v3
run: |
src_hash=$(git ls-remote https://github.com/${GITHUB_REPOSITORY} refs/heads/v3 | cut -f1)
dst_hash=$(git ls-remote ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} refs/heads/v3 | cut -f1)
echo "src_hash=$src_hash"
echo "dst_hash=$dst_hash"
if [ "$src_hash" != "$dst_hash" ]; then
echo "sync_needed=true" >> $GITHUB_OUTPUT
else
echo "sync_needed=false" >> $GITHUB_OUTPUT
fi
- name: sync v3
if: steps.check_v3.outputs.sync_needed == 'true'
run: |
git clone --filter=blob:none --filter=tree:0 --branch v3 --single-branch ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} repo
cd repo
git remote add --no-tags --fetch --track v3 upstream https://github.com/${GITHUB_REPOSITORY}
git pull --rebase upstream v3
git push upstream v3 --progress
git push origin v3 --progress
cd ../
rm -rf repo
- name: check v4
id: check_v4
run: |
src_hash=$(git ls-remote https://github.com/${GITHUB_REPOSITORY} refs/heads/v4 | cut -f1)
dst_hash=$(git ls-remote ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} refs/heads/v4 | cut -f1)
echo "src_hash=$src_hash"
echo "dst_hash=$dst_hash"
if [ "$src_hash" != "$dst_hash" ]; then
echo "sync_needed=true" >> $GITHUB_OUTPUT
else
echo "sync_needed=false" >> $GITHUB_OUTPUT
fi
- name: sync v4
if: steps.check_v4.outputs.sync_needed == 'true'
run: |
git clone --filter=blob:none --filter=tree:0 --branch v4 --single-branch ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} repo
cd repo
git remote add --no-tags --fetch --track v4 upstream https://github.com/${GITHUB_REPOSITORY}
git pull --rebase upstream v4
git push upstream v4 --progress
git push origin v4 --progress
cd ../
rm -rf repo

View File

@@ -1,5 +1,5 @@
run: run:
concurrency: 8 concurrency: 8
timeout: 5m deadline: 5m
issues-exit-code: 1 issues-exit-code: 1
tests: true tests: true

View File

@@ -1,2 +0,0 @@
# micro-meter-prometheus
![Coverage](https://img.shields.io/badge/Coverage-31.9%25-yellow)

2
go.mod
View File

@@ -8,7 +8,7 @@ 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
github.com/prometheus/common v0.62.0 github.com/prometheus/common v0.62.0
go.unistack.org/micro/v4 v4.1.2 go.unistack.org/micro/v3 v3.11.41
) )
require ( require (

4
go.sum
View File

@@ -22,8 +22,8 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
go.unistack.org/micro/v4 v4.1.2 h1:9SOlPYyPNNFpg1A7BsvhDyQm3gysLH1AhWbDCp1hyoY= go.unistack.org/micro/v3 v3.11.41 h1:dP4sBLIZpMo+MWGe5bbESewK8wBzYm4Yik/67x4dEtQ=
go.unistack.org/micro/v4 v4.1.2/go.mod h1:lr3oYED8Ay1vjK68QqRw30QOtdk/ffpZqMFDasOUhKw= go.unistack.org/micro/v3 v3.11.41/go.mod h1:POGU5hstnAT9LH70m8FalyQSNi2GfIew71K75JenIZk=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=

View File

@@ -5,7 +5,6 @@ import (
"hash/fnv" "hash/fnv"
"io" "io"
"regexp" "regexp"
"strings"
"sync" "sync"
"time" "time"
@@ -13,7 +12,7 @@ import (
"github.com/prometheus/client_golang/prometheus/collectors" "github.com/prometheus/client_golang/prometheus/collectors"
dto "github.com/prometheus/client_model/go" dto "github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt" "github.com/prometheus/common/expfmt"
"go.unistack.org/micro/v4/meter" "go.unistack.org/micro/v3/meter"
) )
var _ meter.Meter = &prometheusMeter{} var _ meter.Meter = &prometheusMeter{}
@@ -26,7 +25,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
mu *sync.Mutex sync.Mutex
} }
type counters struct { type counters struct {
@@ -61,15 +60,6 @@ func newString(v string) *string {
return &nv return &nv
} }
func newName(name string) *string {
idx := strings.Index(name, "{")
if idx <= 0 {
return newString(name)
}
return newString(name[:idx])
}
func NewMeter(opts ...meter.Option) *prometheusMeter { func NewMeter(opts ...meter.Option) *prometheusMeter {
return &prometheusMeter{ return &prometheusMeter{
set: prometheus.NewRegistry(), // prometheus.DefaultRegisterer, set: prometheus.NewRegistry(), // prometheus.DefaultRegisterer,
@@ -79,7 +69,6 @@ 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{},
} }
} }
@@ -101,8 +90,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.mu.Lock() m.Lock()
defer m.mu.Unlock() defer m.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]
@@ -124,8 +113,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.mu.Lock() m.Lock()
defer m.mu.Unlock() defer m.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]
@@ -147,8 +136,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.mu.Lock() m.Lock()
defer m.mu.Unlock() defer m.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]
@@ -170,8 +159,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.mu.Lock() m.Lock()
defer m.mu.Unlock() defer m.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]
@@ -193,8 +182,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.mu.Lock() m.Lock()
defer m.mu.Unlock() defer m.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]
@@ -216,8 +205,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.mu.Lock() m.Lock()
defer m.mu.Unlock() defer m.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]
@@ -278,11 +267,9 @@ 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: newString(name),
Type: dto.MetricType_GAUGE.Enum(), Type: dto.MetricType_GAUGE.Enum(),
Metric: make([]*dto.Metric, 0, len(metrics.cs)), Metric: make([]*dto.Metric, 0, len(metrics.cs)),
} }
@@ -297,7 +284,7 @@ func (m *prometheusMeter) Write(w io.Writer, opts ...meter.Option) error {
for name, metrics := range m.gauge { for name, metrics := range m.gauge {
mf := &dto.MetricFamily{ mf := &dto.MetricFamily{
Name: newName(name), Name: newString(name),
Type: dto.MetricType_GAUGE.Enum(), Type: dto.MetricType_GAUGE.Enum(),
Metric: make([]*dto.Metric, 0, len(metrics.cs)), Metric: make([]*dto.Metric, 0, len(metrics.cs)),
} }
@@ -312,7 +299,7 @@ func (m *prometheusMeter) Write(w io.Writer, opts ...meter.Option) error {
for name, metrics := range m.floatCounter { for name, metrics := range m.floatCounter {
mf := &dto.MetricFamily{ mf := &dto.MetricFamily{
Name: newName(name), Name: newString(name),
Type: dto.MetricType_GAUGE.Enum(), Type: dto.MetricType_GAUGE.Enum(),
Metric: make([]*dto.Metric, 0, len(metrics.cs)), Metric: make([]*dto.Metric, 0, len(metrics.cs)),
} }
@@ -327,7 +314,7 @@ func (m *prometheusMeter) Write(w io.Writer, opts ...meter.Option) error {
for name, metrics := range m.histogram { for name, metrics := range m.histogram {
mf := &dto.MetricFamily{ mf := &dto.MetricFamily{
Name: newName(name), Name: newString(name),
Type: dto.MetricType_HISTOGRAM.Enum(), Type: dto.MetricType_HISTOGRAM.Enum(),
Metric: make([]*dto.Metric, 0, len(metrics.cs)), Metric: make([]*dto.Metric, 0, len(metrics.cs)),
} }
@@ -342,7 +329,7 @@ func (m *prometheusMeter) Write(w io.Writer, opts ...meter.Option) error {
for name, metrics := range m.summary { for name, metrics := range m.summary {
mf := &dto.MetricFamily{ mf := &dto.MetricFamily{
Name: newName(name), Name: newString(name),
Type: dto.MetricType_SUMMARY.Enum(), Type: dto.MetricType_SUMMARY.Enum(),
Metric: make([]*dto.Metric, 0, len(metrics.cs)), Metric: make([]*dto.Metric, 0, len(metrics.cs)),
} }
@@ -355,8 +342,6 @@ 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)
} }
@@ -375,7 +360,6 @@ 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,

View File

@@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"testing" "testing"
"go.unistack.org/micro/v4/meter" "go.unistack.org/micro/v3/meter"
) )
func TestStd(t *testing.T) { func TestStd(t *testing.T) {