Compare commits
9 Commits
Author | SHA1 | Date | |
---|---|---|---|
a8b6d67344 | |||
3f589b20c4 | |||
78571b68ab | |||
e1f18b0a9b | |||
279853ccb5 | |||
ec4f5f084f | |||
|
a6707dcac4 | ||
088a00dc79 | |||
|
fdc0017341 |
@ -1,29 +0,0 @@
|
||||
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'
|
@ -1,34 +0,0 @@
|
||||
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 ./...
|
@ -1,53 +0,0 @@
|
||||
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
Normal file
19
.github/dependabot.yml
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# 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
Normal file
20
.github/workflows/autoapprove.yml
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
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
Normal file
21
.github/workflows/automerge.yml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
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
Normal file
47
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
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
Normal file
78
.github/workflows/codeql-analysis.yml
vendored
Normal file
@ -0,0 +1,78 @@
|
||||
# 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
Normal file
27
.github/workflows/dependabot-automerge.yml
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
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
Normal file
47
.github/workflows/pr.yml
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
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
|
@ -1,5 +0,0 @@
|
||||
run:
|
||||
concurrency: 8
|
||||
deadline: 5m
|
||||
issues-exit-code: 1
|
||||
tests: true
|
12
go.mod
12
go.mod
@ -1,16 +1,14 @@
|
||||
module go.unistack.org/micro-meter-victoriametrics/v3
|
||||
module go.unistack.org/micro-meter-victoriametrics/v4
|
||||
|
||||
go 1.22
|
||||
|
||||
toolchain go1.23.2
|
||||
go 1.20
|
||||
|
||||
require (
|
||||
go.unistack.org/metrics v0.0.1
|
||||
go.unistack.org/micro/v3 v3.10.100
|
||||
github.com/VictoriaMetrics/metrics v1.24.0
|
||||
go.unistack.org/micro/v4 v4.0.7
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/valyala/fastrand v1.1.0 // indirect
|
||||
github.com/valyala/histogram v1.2.0 // indirect
|
||||
golang.org/x/sys v0.27.0 // indirect
|
||||
golang.org/x/sys v0.11.0 // indirect
|
||||
)
|
||||
|
15
go.sum
15
go.sum
@ -1,10 +1,13 @@
|
||||
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/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=
|
||||
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=
|
||||
|
@ -4,129 +4,118 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"go.unistack.org/metrics"
|
||||
"go.unistack.org/micro/v3/meter"
|
||||
"github.com/VictoriaMetrics/metrics"
|
||||
"go.unistack.org/micro/v4/meter"
|
||||
"go.unistack.org/micro/v4/options"
|
||||
)
|
||||
|
||||
type victoriametricsMeter struct {
|
||||
set *metrics.Set
|
||||
opts meter.Options
|
||||
prometheusCompat bool
|
||||
set *metrics.Set
|
||||
opts meter.Options
|
||||
}
|
||||
|
||||
type prometheusCompatKey struct{}
|
||||
|
||||
func PrometheusCompat(b bool) meter.Option {
|
||||
return meter.SetOption(prometheusCompatKey{}, b)
|
||||
func NewMeter(opts ...options.Option) meter.Meter {
|
||||
return &victoriametricsMeter{set: metrics.NewSet(), opts: meter.NewOptions(opts...)}
|
||||
}
|
||||
|
||||
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) Name() string {
|
||||
return r.opts.Name
|
||||
}
|
||||
|
||||
func (m *victoriametricsMeter) Name() string {
|
||||
return m.opts.Name
|
||||
}
|
||||
|
||||
func (m *victoriametricsMeter) Clone(opts ...meter.Option) meter.Meter {
|
||||
options := m.opts
|
||||
func (r *victoriametricsMeter) Clone(opts ...options.Option) meter.Meter {
|
||||
options := r.opts
|
||||
for _, o := range opts {
|
||||
o(&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
|
||||
return &victoriametricsMeter{set: r.set, opts: options}
|
||||
}
|
||||
|
||||
func (m *victoriametricsMeter) buildName(name string, labels ...string) string {
|
||||
nl := len(m.opts.Labels) + len(labels)
|
||||
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)
|
||||
if nl == 0 {
|
||||
return name
|
||||
}
|
||||
|
||||
nlabels := make([]string, 0, nl)
|
||||
nlabels = append(nlabels, m.opts.Labels...)
|
||||
nlabels = append(nlabels, r.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 (m *victoriametricsMeter) Counter(name string, labels ...string) meter.Counter {
|
||||
return m.set.GetOrCreateCounter(m.buildName(name, labels...))
|
||||
func (r *victoriametricsMeter) Counter(name string, labels ...string) meter.Counter {
|
||||
return r.set.GetOrCreateCounter(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) FloatCounter(name string, labels ...string) meter.FloatCounter {
|
||||
return r.set.GetOrCreateFloatCounter(r.buildName(name, labels...))
|
||||
}
|
||||
|
||||
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) Gauge(name string, f func() float64, labels ...string) meter.Gauge {
|
||||
return r.set.GetOrCreateGauge(r.buildName(name, labels...), f)
|
||||
}
|
||||
|
||||
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) Histogram(name string, labels ...string) meter.Histogram {
|
||||
return r.set.GetOrCreateHistogram(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) Summary(name string, labels ...string) meter.Summary {
|
||||
return r.set.GetOrCreateSummary(r.buildName(name, labels...))
|
||||
}
|
||||
|
||||
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) 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) 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 {
|
||||
func (r *victoriametricsMeter) Set(opts ...options.Option) meter.Meter {
|
||||
m := &victoriametricsMeter{opts: r.opts}
|
||||
for _, o := range opts {
|
||||
o(&m.opts)
|
||||
}
|
||||
if v, ok := m.opts.Context.Value(prometheusCompatKey{}).(bool); ok {
|
||||
m.prometheusCompat = v
|
||||
m.set = metrics.NewSet()
|
||||
return m
|
||||
}
|
||||
|
||||
func (r *victoriametricsMeter) Init(opts ...options.Option) error {
|
||||
for _, o := range opts {
|
||||
o(&r.opts)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *victoriametricsMeter) Write(w io.Writer, opts ...meter.Option) error {
|
||||
options := m.opts
|
||||
func (r *victoriametricsMeter) Write(w io.Writer, opts ...options.Option) error {
|
||||
options := r.opts
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
m.set.WritePrometheus(w)
|
||||
r.set.WritePrometheus(w)
|
||||
if options.WriteProcessMetrics {
|
||||
metrics.WriteProcessMetrics(w)
|
||||
}
|
||||
if options.WriteFDMetrics {
|
||||
metrics.WriteFDMetrics(w)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *victoriametricsMeter) Options() meter.Options {
|
||||
return m.opts
|
||||
func (r *victoriametricsMeter) Options() meter.Options {
|
||||
return r.opts
|
||||
}
|
||||
|
||||
func (m *victoriametricsMeter) String() string {
|
||||
func (r *victoriametricsMeter) String() string {
|
||||
return "victoriametrics"
|
||||
}
|
||||
|
@ -2,14 +2,20 @@ 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("micro_foo", "micro_bar", "baz", "micro_aaa", "b", "micro_ccc", "d")
|
||||
name := im.buildName("foo", "bar", "baz", "aaa", "b", "ccc", "d")
|
||||
if name != check {
|
||||
t.Fatalf("metric name error: %s != %s", name, check)
|
||||
}
|
||||
@ -18,12 +24,29 @@ func TestBuildName(t *testing.T) {
|
||||
cnt.Inc()
|
||||
}
|
||||
|
||||
func TestPrometheusCompat(t *testing.T) {
|
||||
m := NewMeter(PrometheusCompat(true))
|
||||
m.Histogram("foo", "key", "val").Update(15)
|
||||
func TestWrapper(t *testing.T) {
|
||||
m := NewMeter() // meter.Labels("test_key", "test_val"))
|
||||
|
||||
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)
|
||||
t.Logf("\n%s", buf.Bytes())
|
||||
_ = 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())
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user