Compare commits
44 Commits
Author | SHA1 | Date | |
---|---|---|---|
a167fd531e | |||
ab247ef9c6 | |||
28ebe788da | |||
7dd349a607 | |||
|
0072481aa7 | ||
|
f2af3ea947 | ||
|
cd985a8a56 | ||
|
aebfa6ffaf | ||
|
071a3ca163 | ||
|
10aec04f04 | ||
6091098955 | |||
37fdf5cc79 | |||
|
4cc0553f96 | ||
|
0966d9c171 | ||
|
601db8f934 | ||
|
fc0839b9e3 | ||
83df476d0f | |||
|
16054ce84b | ||
|
1846fa41ad | ||
5ff0349304 | |||
8ad091b096 | |||
e9a657e895 | |||
6a35c083ad | |||
874552803e | |||
|
e4b207de2a | ||
|
8d07b2df97 | ||
|
6a41fc290a | ||
|
da3ae7f36a | ||
|
6e8c62ee7c | ||
|
d0903a09d9 | ||
|
637056f638 | ||
|
b0a35cc7bc | ||
|
44f16fe156 | ||
|
fd5f71f40c | ||
|
63f7c406c4 | ||
|
026335ade0 | ||
|
4db544153a | ||
|
78a83287fa | ||
|
bdf1e8c5f2 | ||
|
94ae7b1b17 | ||
|
96ecdd862c | ||
|
821880743c | ||
|
790c5ec04e | ||
|
851839a3ad |
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/renovate.json
vendored
20
.github/renovate.json
vendored
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": [
|
|
||||||
"config:base"
|
|
||||||
],
|
|
||||||
"postUpdateOptions": ["gomodTidy"],
|
|
||||||
"packageRules": [
|
|
||||||
{
|
|
||||||
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
|
|
||||||
"automerge": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"groupName": "all deps",
|
|
||||||
"separateMajorMinor": true,
|
|
||||||
"groupSlug": "all",
|
|
||||||
"packagePatterns": [
|
|
||||||
"*"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
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@v2
|
||||||
|
- 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
|
31
.github/workflows/dependabot-automerge.yml
vendored
Normal file
31
.github/workflows/dependabot-automerge.yml
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
name: "prautomerge"
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request_target:
|
||||||
|
types: [assigned, opened, synchronize, reopened]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
pull-requests: write
|
||||||
|
contents: write
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
dependabot:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: ${{ github.actor == 'dependabot[bot]' }}
|
||||||
|
steps:
|
||||||
|
- name: metadata
|
||||||
|
id: metadata
|
||||||
|
uses: dependabot/fetch-metadata@v1.1.1
|
||||||
|
with:
|
||||||
|
github-token: "${{ secrets.TOKEN }}"
|
||||||
|
- name: approve
|
||||||
|
run: gh pr review --approve "$PR_URL"
|
||||||
|
env:
|
||||||
|
PR_URL: ${{github.event.pull_request.html_url}}
|
||||||
|
GITHUB_TOKEN: ${{secrets.TOKEN}}
|
||||||
|
- name: 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}}
|
6
go.mod
6
go.mod
@@ -1,8 +1,8 @@
|
|||||||
module github.com/unistack-org/micro-meter-victoriametrics/v3
|
module go.unistack.org/micro-meter-victoriametrics/v3
|
||||||
|
|
||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/VictoriaMetrics/metrics v1.15.2
|
github.com/VictoriaMetrics/metrics v1.18.0
|
||||||
github.com/unistack-org/micro/v3 v3.2.22
|
go.unistack.org/micro/v3 v3.8.6
|
||||||
)
|
)
|
||||||
|
38
go.sum
38
go.sum
@@ -1,23 +1,33 @@
|
|||||||
github.com/VictoriaMetrics/metrics v1.15.2 h1:w/GD8L9tm+gvx1oZvAofRRXwammiicdI0jgLghA2Gdo=
|
github.com/VictoriaMetrics/metrics v1.18.0 h1:vov5NxDHRSXFbdiH4dYLYEjKLoAXXSQ7hcnG8TSD9JQ=
|
||||||
github.com/VictoriaMetrics/metrics v1.15.2/go.mod h1:Z1tSfPfngDn12bTfZSCqArT3OPY3u88J12hSoOhuiRE=
|
github.com/VictoriaMetrics/metrics v1.18.0/go.mod h1:ArjwVz7WpgpegX/JpB0zpNF2h2232kErkEnzH1sxMmA=
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
|
||||||
github.com/ef-ds/deque v1.0.4/go.mod h1:gXDnTC3yqvBcHbq2lcExjtAcVrOnJCbMcZXmuj8Z4tg=
|
github.com/ef-ds/deque v1.0.4/go.mod h1:gXDnTC3yqvBcHbq2lcExjtAcVrOnJCbMcZXmuj8Z4tg=
|
||||||
github.com/google/uuid v1.2.0 h1:qJYtXnJRWmpe7m/3XlyhrsLrEURqHRM2kxzoxXqyUDs=
|
github.com/golang-jwt/jwt/v4 v4.1.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
|
||||||
github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||||
|
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||||
|
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
|
||||||
github.com/silas/dag v0.0.0-20210121180416-41cf55125c34/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
github.com/silas/dag v0.0.0-20210626123444-3804bac2d6d4/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
|
||||||
github.com/unistack-org/micro/v3 v3.2.22 h1:AXyLtRpfcPGczhaA1f9KR0ctK+1Zpqvb+rBJrZtp3Oo=
|
github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8=
|
||||||
github.com/unistack-org/micro/v3 v3.2.22/go.mod h1:oI8H/uGq1h4i5cvUycEoFKJQC7G8yChZQNIDNWGSLRU=
|
github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ=
|
||||||
github.com/valyala/fastrand v1.0.0 h1:LUKT9aKer2dVQNUi3waewTbKV+7H17kvWFNKs2ObdkI=
|
github.com/valyala/histogram v1.2.0 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OLoQ=
|
||||||
github.com/valyala/fastrand v1.0.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ=
|
github.com/valyala/histogram v1.2.0/go.mod h1:Hb4kBwb4UxsaNbbbh+RRz8ZR6pdodR57tzWUS3BUzXY=
|
||||||
github.com/valyala/histogram v1.1.2 h1:vOk5VrGjMBIoPR5k6wA8vBaC8toeJ8XO0yfRjFEc1h8=
|
go.unistack.org/micro-proto/v3 v3.1.0 h1:q39FwjFiRZn+Ux/tt+d3bJTmDtsQQWa+3SLYVo1vLfA=
|
||||||
github.com/valyala/histogram v1.1.2/go.mod h1:CZAr6gK9dbD7hYx2s8WSPh0p5x5wETjC+2b3PJVtEdg=
|
go.unistack.org/micro-proto/v3 v3.1.0/go.mod h1:DpRhYCBXlmSJ/AAXTmntvlh7kQkYU6eFvlmYAx4BQS8=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
go.unistack.org/micro/v3 v3.8.6 h1:nU6dpNRF7iF8dtcTTfzdPan8RkhiDuTsfMrXBmpzG/g=
|
||||||
|
go.unistack.org/micro/v3 v3.8.6/go.mod h1:KMMmOmbgo/D52/rCAbqeKbBsgEEbSKM69he54J3ZIuA=
|
||||||
|
golang.org/x/net v0.0.0-20210928044308-7d9f5e0b762b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||||
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||||
|
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||||
|
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
@@ -2,11 +2,10 @@ package victoriametrics
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/VictoriaMetrics/metrics"
|
"github.com/VictoriaMetrics/metrics"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
)
|
)
|
||||||
|
|
||||||
type victoriametricsMeter struct {
|
type victoriametricsMeter struct {
|
||||||
@@ -22,69 +21,69 @@ func (r *victoriametricsMeter) Name() string {
|
|||||||
return r.opts.Name
|
return r.opts.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *victoriametricsMeter) buildName(name string, opts ...meter.Option) string {
|
func (r *victoriametricsMeter) Clone(opts ...meter.Option) meter.Meter {
|
||||||
var b strings.Builder
|
|
||||||
|
|
||||||
options := r.opts
|
options := r.opts
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&options)
|
o(&options)
|
||||||
}
|
}
|
||||||
|
return &victoriametricsMeter{set: r.set, opts: options}
|
||||||
if len(options.MetricPrefix) > 0 {
|
|
||||||
_, _ = b.WriteString(options.MetricPrefix)
|
|
||||||
}
|
|
||||||
labelPrefix := false
|
|
||||||
if len(options.LabelPrefix) > 0 {
|
|
||||||
labelPrefix = true
|
|
||||||
}
|
|
||||||
_, _ = b.WriteString(name)
|
|
||||||
if len(options.Labels) > 0 {
|
|
||||||
meter.Sort(&options.Labels)
|
|
||||||
_, _ = b.WriteRune('{')
|
|
||||||
for idx := 0; idx < len(options.Labels); idx += 2 {
|
|
||||||
if idx > 0 {
|
|
||||||
_, _ = b.WriteRune(',')
|
|
||||||
}
|
|
||||||
if labelPrefix {
|
|
||||||
_, _ = b.WriteString(options.LabelPrefix)
|
|
||||||
}
|
|
||||||
_, _ = b.WriteString(options.Labels[idx])
|
|
||||||
_, _ = b.WriteString(`="`)
|
|
||||||
_, _ = b.WriteString(options.Labels[idx+1])
|
|
||||||
_, _ = b.WriteString(`"`)
|
|
||||||
}
|
|
||||||
_, _ = b.WriteRune('}')
|
|
||||||
}
|
|
||||||
|
|
||||||
return b.String()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *victoriametricsMeter) Counter(name string, opts ...meter.Option) meter.Counter {
|
func (r *victoriametricsMeter) buildName(name string, labels ...string) string {
|
||||||
return r.set.GetOrCreateCounter(r.buildName(name, opts...))
|
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, r.opts.Labels...)
|
||||||
|
nlabels = append(nlabels, labels...)
|
||||||
|
|
||||||
|
if len(r.opts.LabelPrefix) == 0 {
|
||||||
|
return meter.BuildName(name, nlabels...)
|
||||||
|
}
|
||||||
|
|
||||||
|
for idx := 0; idx <= len(nlabels)/2; idx += 2 {
|
||||||
|
nlabels[idx] = r.opts.LabelPrefix + nlabels[idx]
|
||||||
|
}
|
||||||
|
|
||||||
|
return meter.BuildName(name, nlabels...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *victoriametricsMeter) FloatCounter(name string, opts ...meter.Option) meter.FloatCounter {
|
func (r *victoriametricsMeter) Counter(name string, labels ...string) meter.Counter {
|
||||||
return r.set.GetOrCreateFloatCounter(r.buildName(name, opts...))
|
return r.set.GetOrCreateCounter(r.buildName(name, labels...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *victoriametricsMeter) Gauge(name string, f func() float64, opts ...meter.Option) meter.Gauge {
|
func (r *victoriametricsMeter) FloatCounter(name string, labels ...string) meter.FloatCounter {
|
||||||
return r.set.GetOrCreateGauge(r.buildName(name, opts...), f)
|
return r.set.GetOrCreateFloatCounter(r.buildName(name, labels...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *victoriametricsMeter) Histogram(name string, opts ...meter.Option) meter.Histogram {
|
func (r *victoriametricsMeter) Gauge(name string, f func() float64, labels ...string) meter.Gauge {
|
||||||
return r.set.GetOrCreateHistogram(r.buildName(name, opts...))
|
return r.set.GetOrCreateGauge(r.buildName(name, labels...), f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *victoriametricsMeter) Summary(name string, opts ...meter.Option) meter.Summary {
|
func (r *victoriametricsMeter) Histogram(name string, labels ...string) meter.Histogram {
|
||||||
return r.set.GetOrCreateSummary(r.buildName(name, opts...))
|
return r.set.GetOrCreateHistogram(r.buildName(name, labels...))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *victoriametricsMeter) SummaryExt(name string, window time.Duration, quantiles []float64, opts ...meter.Option) meter.Summary {
|
func (r *victoriametricsMeter) Summary(name string, labels ...string) meter.Summary {
|
||||||
return r.set.GetOrCreateSummaryExt(r.buildName(name, opts...), window, quantiles)
|
return r.set.GetOrCreateSummary(r.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 (r *victoriametricsMeter) Set(opts ...meter.Option) meter.Meter {
|
func (r *victoriametricsMeter) Set(opts ...meter.Option) meter.Meter {
|
||||||
m := &victoriametricsMeter{opts: meter.NewOptions(opts...), set: metrics.NewSet()}
|
m := &victoriametricsMeter{opts: r.opts}
|
||||||
|
for _, o := range opts {
|
||||||
|
o(&m.opts)
|
||||||
|
}
|
||||||
|
m.set = metrics.NewSet()
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,31 +1,31 @@
|
|||||||
package victoriametrics
|
package victoriametrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"go.unistack.org/micro/v3/client"
|
||||||
"github.com/unistack-org/micro/v3/codec"
|
"go.unistack.org/micro/v3/codec"
|
||||||
"github.com/unistack-org/micro/v3/meter"
|
"go.unistack.org/micro/v3/meter"
|
||||||
"github.com/unistack-org/micro/v3/meter/wrapper"
|
"go.unistack.org/micro/v3/meter/wrapper"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuildName(t *testing.T) {
|
func TestBuildName(t *testing.T) {
|
||||||
m := NewMeter()
|
m := NewMeter()
|
||||||
im := m.(*victoriametricsMeter)
|
im := m.(*victoriametricsMeter)
|
||||||
check := `micro_foo{micro_aaa="b",micro_bar="baz"}`
|
check := `micro_foo{micro_aaa="b",micro_bar="baz"}`
|
||||||
name := im.buildName("foo", meter.Labels("bar", "baz", "aaa", "b"))
|
name := im.buildName("foo", "bar", "baz", "aaa", "b")
|
||||||
if name != check {
|
if name != check {
|
||||||
t.Fatalf("metric name error: %s != %s", name, check)
|
t.Fatalf("metric name error: %s != %s", name, check)
|
||||||
}
|
}
|
||||||
|
|
||||||
cnt := m.Counter("counter", meter.Labels("key", "val"))
|
cnt := m.Counter("counter", "key", "val")
|
||||||
cnt.Inc()
|
cnt.Inc()
|
||||||
//m.Write(os.Stdout, meter.WriteProcessMetrics(true), meter.WriteFDMetrics(true))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWrapper(t *testing.T) {
|
func TestWrapper(t *testing.T) {
|
||||||
m := NewMeter()
|
m := NewMeter() // meter.Labels("test_key", "test_val"))
|
||||||
|
|
||||||
w := wrapper.NewClientWrapper(
|
w := wrapper.NewClientWrapper(
|
||||||
wrapper.ServiceName("svc1"),
|
wrapper.ServiceName("svc1"),
|
||||||
@@ -44,5 +44,9 @@ func TestWrapper(t *testing.T) {
|
|||||||
req := &codec.Frame{}
|
req := &codec.Frame{}
|
||||||
err := c.Call(ctx, c.NewRequest("svc2", "Service.Method", req), rsp)
|
err := c.Call(ctx, c.NewRequest("svc2", "Service.Method", req), rsp)
|
||||||
_, _ = rsp, err
|
_, _ = rsp, err
|
||||||
//m.Write(os.Stdout, meter.WriteProcessMetrics(true), meter.WriteFDMetrics(true))
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user