Compare commits
83 Commits
Author | SHA1 | Date | |
---|---|---|---|
b689ebbd0a | |||
|
0fae124bf4 | ||
dbcf52e590 | |||
4fef299e78 | |||
a239f86139 | |||
c187502cd4 | |||
|
0fcf592e87 | ||
74bab50879 | |||
|
8375fd2535 | ||
1381db40c6 | |||
|
7515f2bd9e | ||
5cf43ba9e3 | |||
|
d9a02c1ce1 | ||
5bae6e6b24 | |||
|
c5e6653380 | ||
8befdae5bc | |||
|
6a348a2f9d | ||
7f0bf98b2e | |||
|
edaa545ed4 | ||
7ac92a2249 | |||
|
4d49c925ef | ||
f6b8a429f9 | |||
|
75f20a4962 | ||
3ff4f40026 | |||
|
362e857414 | ||
|
ab384564a6 | ||
|
5119c8b6a3 | ||
|
ebe50db0b8 | ||
3e88c33191 | |||
|
6f1fa39dcf | ||
95b846e975 | |||
|
8d6506ee70 | ||
6b5a3194ca | |||
|
61609271ee | ||
d4c0be717e | |||
|
d64e293877 | ||
b5d9880a8e | |||
|
f63108ea1a | ||
|
7531140dcd | ||
de97bc0d7b | |||
|
dd3c2316e0 | ||
1c5a85b88a | |||
|
5ab95f3f31 | ||
|
d2411e9b79 | ||
931fa9796b | |||
|
03b30c5c19 | ||
607727c907 | |||
|
228a57e4d8 | ||
|
d83f4fb061 | ||
873bfb10b0 | |||
7bd47f03d7 | |||
|
54a7f8baa4 | ||
|
10c9806ebd | ||
|
bedec603a9 | ||
|
6c837b6529 | ||
|
15bc60fedc | ||
098152f58f | |||
|
0499cb0b05 | ||
c4eda1c57b | |||
|
d6cdb67d8b | ||
|
720dab8885 | ||
2413f4bad1 | |||
|
d11c5676c8 | ||
|
d6b9bdef99 | ||
|
8717a4973a | ||
95a1db0b5b | |||
|
57c161cfaf | ||
0db942cfe2 | |||
|
47201a9dea | ||
53d518fa17 | |||
|
5354556d17 | ||
bfd5ac8311 | |||
|
b23bb2d51b | ||
7414ed2587 | |||
|
a6500aa9ea | ||
a8dec8755f | |||
|
ee3b5f115e | ||
b9ab04552f | |||
e73c14e217 | |||
|
5131af242a | ||
fa64ec858c | |||
|
1710561d6a | ||
4e7a852b8b |
29
.gitea/workflows/job_lint.yml
Normal file
29
.gitea/workflows/job_lint.yml
Normal file
@ -0,0 +1,29 @@
|
||||
name: lint
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, synchronize]
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
- v4
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
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: setup deps
|
||||
run: go get -v ./...
|
||||
- name: run lint
|
||||
uses: https://github.com/golangci/golangci-lint-action@v6
|
||||
with:
|
||||
version: 'latest'
|
34
.gitea/workflows/job_test.yml
Normal file
34
.gitea/workflows/job_test.yml
Normal file
@ -0,0 +1,34 @@
|
||||
name: test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, synchronize]
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
- v4
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
- v4
|
||||
|
||||
jobs:
|
||||
test:
|
||||
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: setup deps
|
||||
run: go get -v ./...
|
||||
- name: run test
|
||||
env:
|
||||
INTEGRATION_TESTS: yes
|
||||
run: go test -mod readonly -v ./...
|
53
.gitea/workflows/job_tests.yml
Normal file
53
.gitea/workflows/job_tests.yml
Normal file
@ -0,0 +1,53 @@
|
||||
name: test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, reopened, synchronize]
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
- v4
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
- v4
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout code
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
filter: 'blob:none'
|
||||
- name: checkout tests
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: master
|
||||
filter: 'blob:none'
|
||||
repository: unistack-org/micro-tests
|
||||
path: micro-tests
|
||||
- name: setup go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
cache-dependency-path: "**/*.sum"
|
||||
go-version: 'stable'
|
||||
- name: setup go work
|
||||
env:
|
||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
||||
run: |
|
||||
go work init
|
||||
go work use .
|
||||
go work use micro-tests
|
||||
- name: setup deps
|
||||
env:
|
||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
||||
run: go get -v ./...
|
||||
- name: run tests
|
||||
env:
|
||||
INTEGRATION_TESTS: yes
|
||||
GOWORK: /workspace/${{ github.repository_owner }}/go.work
|
||||
run: |
|
||||
cd micro-tests
|
||||
go test -mod readonly -v ./... || true
|
19
.github/dependabot.yml
vendored
19
.github/dependabot.yml
vendored
@ -1,19 +0,0 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
|
||||
# Maintain dependencies for GitHub Actions
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
|
||||
# Maintain dependencies for Golang
|
||||
- package-ecosystem: "gomod"
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "daily"
|
20
.github/workflows/autoapprove.yml
vendored
20
.github/workflows/autoapprove.yml
vendored
@ -1,20 +0,0 @@
|
||||
name: "autoapprove"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
autoapprove:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: approve
|
||||
uses: hmarr/auto-approve-action@v2
|
||||
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
|
||||
id: approve
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
21
.github/workflows/automerge.yml
vendored
21
.github/workflows/automerge.yml
vendored
@ -1,21 +0,0 @@
|
||||
name: "automerge"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'vtolstov'
|
||||
steps:
|
||||
- name: merge
|
||||
id: merge
|
||||
run: gh pr merge --auto --merge "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
47
.github/workflows/build.yml
vendored
47
.github/workflows/build.yml
vendored
@ -1,47 +0,0 @@
|
||||
name: build
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: ${{ runner.os }}-go-
|
||||
- name: deps
|
||||
run: go get -v -t -d ./...
|
||||
- name: test
|
||||
env:
|
||||
INTEGRATION_TESTS: yes
|
||||
run: go test -mod readonly -v ./...
|
||||
lint:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v3.1.0
|
||||
continue-on-error: true
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
version: v1.30
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
# Optional: golangci-lint command line arguments.
|
||||
# args: --issues-exit-code=0
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
# only-new-issues: true
|
78
.github/workflows/codeql-analysis.yml
vendored
78
.github/workflows/codeql-analysis.yml
vendored
@ -1,78 +0,0 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "codeql"
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["prbuild"]
|
||||
types:
|
||||
- completed
|
||||
push:
|
||||
branches: [ master, v3 ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master, v3 ]
|
||||
schedule:
|
||||
- cron: '34 1 * * 0'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: analyze
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
actions: read
|
||||
contents: read
|
||||
security-events: write
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'go' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||
# Learn more:
|
||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: init
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: analyze
|
||||
uses: github/codeql-action/analyze@v1
|
27
.github/workflows/dependabot-automerge.yml
vendored
27
.github/workflows/dependabot-automerge.yml
vendored
@ -1,27 +0,0 @@
|
||||
name: "dependabot-automerge"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
|
||||
permissions:
|
||||
pull-requests: write
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
automerge:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.actor == 'dependabot[bot]'
|
||||
steps:
|
||||
- name: metadata
|
||||
id: metadata
|
||||
uses: dependabot/fetch-metadata@v1.3.0
|
||||
with:
|
||||
github-token: "${{ secrets.TOKEN }}"
|
||||
- name: merge
|
||||
id: merge
|
||||
if: ${{contains(steps.metadata.outputs.dependency-names, 'go.unistack.org')}}
|
||||
run: gh pr merge --auto --merge "$PR_URL"
|
||||
env:
|
||||
PR_URL: ${{github.event.pull_request.html_url}}
|
||||
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
47
.github/workflows/pr.yml
vendored
47
.github/workflows/pr.yml
vendored
@ -1,47 +0,0 @@
|
||||
name: prbuild
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- v3
|
||||
jobs:
|
||||
test:
|
||||
name: test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: setup
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.16
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/go/pkg/mod
|
||||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||
restore-keys: ${{ runner.os }}-go-
|
||||
- name: deps
|
||||
run: go get -v -t -d ./...
|
||||
- name: test
|
||||
env:
|
||||
INTEGRATION_TESTS: yes
|
||||
run: go test -mod readonly -v ./...
|
||||
lint:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: lint
|
||||
uses: golangci/golangci-lint-action@v3.1.0
|
||||
continue-on-error: true
|
||||
with:
|
||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||
version: v1.30
|
||||
# Optional: working directory, useful for monorepos
|
||||
# working-directory: somedir
|
||||
# Optional: golangci-lint command line arguments.
|
||||
# args: --issues-exit-code=0
|
||||
# Optional: show only new issues if it's a pull request. The default value is `false`.
|
||||
# only-new-issues: true
|
5
.golangci.yml
Normal file
5
.golangci.yml
Normal file
@ -0,0 +1,5 @@
|
||||
run:
|
||||
concurrency: 8
|
||||
deadline: 5m
|
||||
issues-exit-code: 1
|
||||
tests: true
|
12
go.mod
12
go.mod
@ -1,14 +1,16 @@
|
||||
module go.unistack.org/micro-meter-victoriametrics/v4
|
||||
module go.unistack.org/micro-meter-victoriametrics/v3
|
||||
|
||||
go 1.20
|
||||
go 1.22
|
||||
|
||||
toolchain go1.23.2
|
||||
|
||||
require (
|
||||
github.com/VictoriaMetrics/metrics v1.24.0
|
||||
go.unistack.org/micro/v4 v4.0.7
|
||||
go.unistack.org/metrics v0.0.1
|
||||
go.unistack.org/micro/v3 v3.10.100
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/valyala/fastrand v1.1.0 // indirect
|
||||
github.com/valyala/histogram v1.2.0 // indirect
|
||||
golang.org/x/sys v0.11.0 // indirect
|
||||
golang.org/x/sys v0.27.0 // indirect
|
||||
)
|
||||
|
15
go.sum
15
go.sum
@ -1,13 +1,10 @@
|
||||
github.com/VictoriaMetrics/metrics v1.23.1 h1:/j8DzeJBxSpL2qSIdqnRFLvQQhbJyJbbEi22yMm7oL0=
|
||||
github.com/VictoriaMetrics/metrics v1.24.0 h1:ILavebReOjYctAGY5QU2F9X0MYvkcrG3aEn2RKa1Zkw=
|
||||
github.com/VictoriaMetrics/metrics v1.24.0/go.mod h1:eFT25kvsTidQFHb6U0oa0rTrDRdz4xTYjpL8+UPohys=
|
||||
github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8=
|
||||
github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ=
|
||||
github.com/valyala/histogram v1.2.0 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OLoQ=
|
||||
github.com/valyala/histogram v1.2.0/go.mod h1:Hb4kBwb4UxsaNbbbh+RRz8ZR6pdodR57tzWUS3BUzXY=
|
||||
go.unistack.org/micro/v4 v4.0.1 h1:xo1IxbVfgh8i0eY0VeYa3cbb13u5n/Mxnp3FOgWD4Jo=
|
||||
go.unistack.org/micro/v4 v4.0.1/go.mod h1:p/J5UcSJjfHsWGT31uKoghQ5rUQZzQJBAFy+Z4+ZVMs=
|
||||
go.unistack.org/micro/v4 v4.0.7 h1:2lwtZlHcSwgkahhFbkI4x1lOS79lw8uLHtcEhlFF+AM=
|
||||
go.unistack.org/micro/v4 v4.0.7/go.mod h1:bVEYTlPi0EsdgZZt311bIroDg9ict7ky3C87dSCCAGk=
|
||||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
go.unistack.org/metrics v0.0.1 h1:sCnGO059ZccGC/D34iRH121eSk+7ci5+OY9cl5K7GKY=
|
||||
go.unistack.org/metrics v0.0.1/go.mod h1:1FY4R7EKJa9Oz2D6wlGScNerpl6igRs9Cx/3et4Rgs4=
|
||||
go.unistack.org/micro/v3 v3.10.100 h1:yWOaU0ImCGm5k5MUzlIobJUOr+KLfrR/BoDZvcHyKxM=
|
||||
go.unistack.org/micro/v3 v3.10.100/go.mod h1:YzMldzHN9Ei+zy5t/Psu7RUWDZwUfrNYiStSQtTz90g=
|
||||
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
||||
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
|
@ -4,118 +4,129 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/VictoriaMetrics/metrics"
|
||||
"go.unistack.org/micro/v4/meter"
|
||||
"go.unistack.org/micro/v4/options"
|
||||
"go.unistack.org/metrics"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
)
|
||||
|
||||
type victoriametricsMeter struct {
|
||||
set *metrics.Set
|
||||
opts meter.Options
|
||||
set *metrics.Set
|
||||
opts meter.Options
|
||||
prometheusCompat bool
|
||||
}
|
||||
|
||||
func NewMeter(opts ...options.Option) meter.Meter {
|
||||
return &victoriametricsMeter{set: metrics.NewSet(), opts: meter.NewOptions(opts...)}
|
||||
type prometheusCompatKey struct{}
|
||||
|
||||
func PrometheusCompat(b bool) meter.Option {
|
||||
return meter.SetOption(prometheusCompatKey{}, b)
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) Name() string {
|
||||
return r.opts.Name
|
||||
func NewMeter(opts ...meter.Option) meter.Meter {
|
||||
m := &victoriametricsMeter{set: metrics.NewSet(), opts: meter.NewOptions(opts...)}
|
||||
if v, ok := m.opts.Context.Value(prometheusCompatKey{}).(bool); ok {
|
||||
m.prometheusCompat = v
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) Clone(opts ...options.Option) meter.Meter {
|
||||
options := r.opts
|
||||
func (m *victoriametricsMeter) Name() string {
|
||||
return m.opts.Name
|
||||
}
|
||||
|
||||
func (m *victoriametricsMeter) Clone(opts ...meter.Option) meter.Meter {
|
||||
options := m.opts
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
return &victoriametricsMeter{set: r.set, opts: options}
|
||||
nm := &victoriametricsMeter{set: m.set, opts: options, prometheusCompat: m.prometheusCompat}
|
||||
if v, ok := m.opts.Context.Value(prometheusCompatKey{}).(bool); ok {
|
||||
m.prometheusCompat = v
|
||||
}
|
||||
return nm
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) buildName(name string, labels ...string) string {
|
||||
if len(r.opts.MetricPrefix) > 0 {
|
||||
name = r.opts.MetricPrefix + name
|
||||
}
|
||||
|
||||
nl := len(r.opts.Labels) + len(labels)
|
||||
func (m *victoriametricsMeter) buildName(name string, labels ...string) string {
|
||||
nl := len(m.opts.Labels) + len(labels)
|
||||
if nl == 0 {
|
||||
return name
|
||||
}
|
||||
|
||||
nlabels := make([]string, 0, nl)
|
||||
nlabels = append(nlabels, r.opts.Labels...)
|
||||
nlabels = append(nlabels, m.opts.Labels...)
|
||||
nlabels = append(nlabels, labels...)
|
||||
|
||||
if len(r.opts.LabelPrefix) == 0 {
|
||||
return meter.BuildName(name, nlabels...)
|
||||
}
|
||||
|
||||
for idx := 0; idx < nl; idx++ {
|
||||
nlabels[idx] = r.opts.LabelPrefix + nlabels[idx]
|
||||
idx++
|
||||
}
|
||||
return meter.BuildName(name, nlabels...)
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) Counter(name string, labels ...string) meter.Counter {
|
||||
return r.set.GetOrCreateCounter(r.buildName(name, labels...))
|
||||
func (m *victoriametricsMeter) Counter(name string, labels ...string) meter.Counter {
|
||||
return m.set.GetOrCreateCounter(m.buildName(name, labels...))
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) FloatCounter(name string, labels ...string) meter.FloatCounter {
|
||||
return r.set.GetOrCreateFloatCounter(r.buildName(name, labels...))
|
||||
func (m *victoriametricsMeter) FloatCounter(name string, labels ...string) meter.FloatCounter {
|
||||
return m.set.GetOrCreateFloatCounter(m.buildName(name, labels...))
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) Gauge(name string, f func() float64, labels ...string) meter.Gauge {
|
||||
return r.set.GetOrCreateGauge(r.buildName(name, labels...), f)
|
||||
func (m *victoriametricsMeter) Gauge(name string, f func() float64, labels ...string) meter.Gauge {
|
||||
return m.set.GetOrCreateGauge(m.buildName(name, labels...), f)
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) Histogram(name string, labels ...string) meter.Histogram {
|
||||
return r.set.GetOrCreateHistogram(r.buildName(name, labels...))
|
||||
func (m *victoriametricsMeter) Histogram(name string, labels ...string) meter.Histogram {
|
||||
if m.prometheusCompat {
|
||||
return m.set.GetOrCreateCompatibleHistogram(m.buildName(name, labels...))
|
||||
}
|
||||
return m.set.GetOrCreateHistogram(m.buildName(name, labels...))
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) Summary(name string, labels ...string) meter.Summary {
|
||||
return r.set.GetOrCreateSummary(r.buildName(name, labels...))
|
||||
func (m *victoriametricsMeter) Summary(name string, labels ...string) meter.Summary {
|
||||
return m.set.GetOrCreateSummary(m.buildName(name, labels...))
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) SummaryExt(name string, window time.Duration, quantiles []float64, labels ...string) meter.Summary {
|
||||
return r.set.GetOrCreateSummaryExt(r.buildName(name, labels...), window, quantiles)
|
||||
func (m *victoriametricsMeter) SummaryExt(name string, window time.Duration, quantiles []float64, labels ...string) meter.Summary {
|
||||
return m.set.GetOrCreateSummaryExt(m.buildName(name, labels...), window, quantiles)
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) Set(opts ...options.Option) meter.Meter {
|
||||
m := &victoriametricsMeter{opts: r.opts}
|
||||
func (m *victoriametricsMeter) Set(opts ...meter.Option) meter.Meter {
|
||||
nm := &victoriametricsMeter{opts: m.opts}
|
||||
for _, o := range opts {
|
||||
o(&nm.opts)
|
||||
}
|
||||
nm.set = metrics.NewSet()
|
||||
if v, ok := nm.opts.Context.Value(prometheusCompatKey{}).(bool); ok {
|
||||
nm.prometheusCompat = v
|
||||
}
|
||||
return nm
|
||||
}
|
||||
|
||||
func (m *victoriametricsMeter) Init(opts ...meter.Option) error {
|
||||
for _, o := range opts {
|
||||
o(&m.opts)
|
||||
}
|
||||
m.set = metrics.NewSet()
|
||||
return m
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) Init(opts ...options.Option) error {
|
||||
for _, o := range opts {
|
||||
o(&r.opts)
|
||||
if v, ok := m.opts.Context.Value(prometheusCompatKey{}).(bool); ok {
|
||||
m.prometheusCompat = v
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) Write(w io.Writer, opts ...options.Option) error {
|
||||
options := r.opts
|
||||
func (m *victoriametricsMeter) Write(w io.Writer, opts ...meter.Option) error {
|
||||
options := m.opts
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
r.set.WritePrometheus(w)
|
||||
m.set.WritePrometheus(w)
|
||||
if options.WriteProcessMetrics {
|
||||
metrics.WriteProcessMetrics(w)
|
||||
}
|
||||
if options.WriteFDMetrics {
|
||||
metrics.WriteFDMetrics(w)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) Options() meter.Options {
|
||||
return r.opts
|
||||
func (m *victoriametricsMeter) Options() meter.Options {
|
||||
return m.opts
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) String() string {
|
||||
func (m *victoriametricsMeter) String() string {
|
||||
return "victoriametrics"
|
||||
}
|
||||
|
@ -2,20 +2,14 @@ package victoriametrics
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"go.unistack.org/micro/v4/client"
|
||||
"go.unistack.org/micro/v4/codec"
|
||||
"go.unistack.org/micro/v4/meter"
|
||||
"go.unistack.org/micro/v4/meter/wrapper"
|
||||
)
|
||||
|
||||
func TestBuildName(t *testing.T) {
|
||||
m := NewMeter()
|
||||
im := m.(*victoriametricsMeter)
|
||||
check := `micro_foo{micro_aaa="b",micro_bar="baz",micro_ccc="d"}`
|
||||
name := im.buildName("foo", "bar", "baz", "aaa", "b", "ccc", "d")
|
||||
name := im.buildName("micro_foo", "micro_bar", "baz", "micro_aaa", "b", "micro_ccc", "d")
|
||||
if name != check {
|
||||
t.Fatalf("metric name error: %s != %s", name, check)
|
||||
}
|
||||
@ -24,29 +18,12 @@ func TestBuildName(t *testing.T) {
|
||||
cnt.Inc()
|
||||
}
|
||||
|
||||
func TestWrapper(t *testing.T) {
|
||||
m := NewMeter() // meter.Labels("test_key", "test_val"))
|
||||
func TestPrometheusCompat(t *testing.T) {
|
||||
m := NewMeter(PrometheusCompat(true))
|
||||
m.Histogram("foo", "key", "val").Update(15)
|
||||
|
||||
w := wrapper.NewClientWrapper(
|
||||
wrapper.ServiceName("svc1"),
|
||||
wrapper.ServiceVersion("0.0.1"),
|
||||
wrapper.ServiceID("12345"),
|
||||
wrapper.Meter(m),
|
||||
)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
c := client.NewClient(client.Wrap(w))
|
||||
if err := c.Init(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
rsp := &codec.Frame{}
|
||||
req := &codec.Frame{}
|
||||
err := c.Call(ctx, c.NewRequest("svc2", "Service.Method", req), rsp)
|
||||
_, _ = rsp, err
|
||||
buf := bytes.NewBuffer(nil)
|
||||
_ = m.Write(buf, meter.WriteProcessMetrics(false), meter.WriteFDMetrics(false))
|
||||
if !bytes.Contains(buf.Bytes(), []byte(`micro_client_request_inflight{micro_endpoint="svc2.Service.Method"} 0`)) {
|
||||
t.Fatalf("invalid metrics output: %s", buf.Bytes())
|
||||
}
|
||||
|
||||
_ = m.Write(buf)
|
||||
t.Logf("\n%s", buf.Bytes())
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user