3 Commits
v3 ... v4.0.0

Author SHA1 Message Date
bd8eca5f5e Merge pull request 'move to micro v4' (#106) from v4 into master
Some checks failed
build / test (push) Failing after 4s
build / lint (push) Failing after 5s
codeql / analyze (go) (push) Failing after 7s
Reviewed-on: #106
2023-05-07 19:36:08 +03:00
04d67b540c move to micro v4
Some checks failed
autoapprove / autoapprove (pull_request) Failing after 3s
automerge / automerge (pull_request) Failing after 7s
dependabot-automerge / automerge (pull_request) Has been skipped
codeql / analyze (go) (pull_request) Failing after 9s
prbuild / test (pull_request) Failing after 1m0s
prbuild / lint (pull_request) Failing after 5s
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-05-07 19:35:39 +03:00
44b2cb9572 Merge branch 'v3'
Some checks failed
build / test (push) Failing after 6s
build / lint (push) Failing after 4s
codeql / analyze (go) (push) Failing after 5s
2023-05-07 19:34:13 +03:00
20 changed files with 421 additions and 334 deletions

View File

@@ -1,6 +1,6 @@
--- ---
name: Bug report name: Bug report
about: For reporting bugs in micro about: For reporting bugs in go-micro
title: "[BUG]" title: "[BUG]"
labels: '' labels: ''
assignees: '' assignees: ''
@@ -16,3 +16,9 @@ assignees: ''
**How to reproduce the bug:** **How to reproduce the bug:**
If possible, please include a minimal code snippet here. If possible, please include a minimal code snippet here.
**Environment:**
Go Version: please paste `go version` output here
```
please paste `go env` output here
```

View File

@@ -1,6 +1,6 @@
--- ---
name: Feature request / Enhancement name: Feature request / Enhancement
about: If you have a need not served by micro about: If you have a need not served by go-micro
title: "[FEATURE]" title: "[FEATURE]"
labels: '' labels: ''
assignees: '' assignees: ''

View File

@@ -1,8 +1,14 @@
--- ---
name: Question name: Question
about: Ask a question about micro about: Ask a question about go-micro
title: '' title: ''
labels: '' labels: ''
assignees: '' assignees: ''
--- ---
Before asking, please check if your question has already been answered:
1. Check the documentation - https://micro.mu/docs/
2. Check the examples and plugins - https://github.com/micro/examples & https://github.com/micro/go-plugins
3. Search existing issues

19
.github/dependabot.yml vendored Normal file
View 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
View 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@v3
if: github.actor == 'vtolstov' || github.actor == 'dependabot[bot]'
id: approve
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

21
.github/workflows/automerge.yml vendored Normal file
View 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
View 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@v3
with:
go-version: 1.17
- name: checkout
uses: actions/checkout@v3
- name: cache
uses: actions/cache@v3
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.4.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
View 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@v3
with:
go-version: 1.17
# Initializes the CodeQL tools for scanning.
- name: init
uses: github/codeql-action/init@v2
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@v2
# 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@v2

View 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.6
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}}

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,29 +0,0 @@
name: lint
on:
pull_request:
types: [opened, reopened, synchronize]
branches: [ master, v3, v4 ]
paths-ignore:
- '.github/**'
- '.gitea/**'
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: golangci/golangci-lint-action@v6
with:
version: 'latest'

View File

@@ -1,31 +0,0 @@
name: test
on:
pull_request:
types: [opened, reopened, synchronize]
branches: [ master, v3, v4 ]
push:
branches: [ master, v3, v4 ]
paths-ignore:
- '.github/**'
- '.gitea/**'
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 ./...

View File

@@ -1,50 +0,0 @@
name: test
on:
pull_request:
types: [opened, reopened, synchronize]
branches: [ master, v3, v4 ]
push:
branches: [ master, v3, v4 ]
paths-ignore:
- '.github/**'
- '.gitea/**'
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: ${{ github.workspace }}/go.work
run: |
go work init
go work use .
go work use micro-tests
- name: setup deps
env:
GOWORK: ${{ github.workspace }}/go.work
run: go get -v ./...
- name: run tests
env:
INTEGRATION_TESTS: yes
GOWORK: ${{ github.workspace }}/go.work
run: |
cd micro-tests
go test -mod readonly -v ./... || true

47
.github/workflows/pr.yml vendored Normal file
View 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@v3
with:
go-version: 1.17
- name: checkout
uses: actions/checkout@v3
- name: cache
uses: actions/cache@v3
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.4.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

View File

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

View File

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

23
go.mod
View File

@@ -1,19 +1,20 @@
module go.unistack.org/micro-meter-prometheus/v3 module go.unistack.org/micro-meter-prometheus/v4
go 1.22.0 go 1.20
require ( require (
github.com/prometheus/client_golang v1.21.0 github.com/prometheus/client_golang v1.14.0
github.com/prometheus/client_model v0.6.1 github.com/prometheus/client_model v0.3.0
github.com/prometheus/common v0.62.0 github.com/prometheus/common v0.39.0
go.unistack.org/micro/v3 v3.11.41 go.unistack.org/micro/v4 v4.0.1
) )
require ( require (
github.com/beorn7/perks v1.0.1 // indirect github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/prometheus/procfs v0.15.1 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
golang.org/x/sys v0.30.0 // indirect github.com/prometheus/procfs v0.8.0 // indirect
google.golang.org/protobuf v1.36.5 // indirect golang.org/x/sys v0.3.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
) )

59
go.sum
View File

@@ -1,32 +1,31 @@
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw=
github.com/prometheus/client_golang v1.21.0 h1:DIsaGmiaBkSangBgMtWdNfxbMNdku5IK6iNhrEqWvdA= github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
github.com/prometheus/client_golang v1.21.0/go.mod h1:U9NM32ykUErtVBxdvD3zfi+EuFkkaBvMb09mIfe0Zgg= github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.39.0 h1:oOyhkDq05hPZKItWVBkJ6g6AtGxi+fy7F4JvUV8uhsI=
github.com/prometheus/common v0.62.0 h1:xasJaQlnWAeyHdUBeGjXmutelfJHWMRr+Fg4QszZ2Io= github.com/prometheus/common v0.39.0/go.mod h1:6XBZ7lYdLCbkAVhwRsWTZn+IN5AB9F/NXd5w0BbEX0Y=
github.com/prometheus/common v0.62.0/go.mod h1:vyBcEuLSvWos9B1+CyL7JZ2up+uFzXhkqml0W5zIY1I= github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo=
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= go.unistack.org/micro/v4 v4.0.1 h1:xo1IxbVfgh8i0eY0VeYa3cbb13u5n/Mxnp3FOgWD4Jo=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= go.unistack.org/micro/v4 v4.0.1/go.mod h1:p/J5UcSJjfHsWGT31uKoghQ5rUQZzQJBAFy+Z4+ZVMs=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
go.unistack.org/micro/v3 v3.11.41 h1:dP4sBLIZpMo+MWGe5bbESewK8wBzYm4Yik/67x4dEtQ= golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
go.unistack.org/micro/v3 v3.11.41/go.mod h1:POGU5hstnAT9LH70m8FalyQSNi2GfIew71K75JenIZk= golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -4,8 +4,6 @@ import (
"fmt" "fmt"
"hash/fnv" "hash/fnv"
"io" "io"
"regexp"
"strings"
"sync" "sync"
"time" "time"
@@ -13,7 +11,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/v3/meter" "go.unistack.org/micro/v4/meter"
) )
var _ meter.Meter = &prometheusMeter{} var _ meter.Meter = &prometheusMeter{}
@@ -26,7 +24,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 {
@@ -49,27 +47,16 @@ type floatCounters struct {
cs map[uint64]*prometheusFloatCounter cs map[uint64]*prometheusFloatCounter
} }
/*
func newFloat64(v float64) *float64 { func newFloat64(v float64) *float64 {
nv := v nv := v
return &nv return &nv
} }
*/
func newString(v string) *string { func newString(v string) *string {
nv := v nv := v
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,11 +66,14 @@ 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{},
} }
} }
func (m *prometheusMeter) buildMetric(name string, labels ...string) string { func (m *prometheusMeter) buildMetric(name string, labels ...string) string {
if len(m.opts.MetricPrefix) > 0 {
name = m.opts.MetricPrefix + name
}
nl := len(m.opts.Labels) + len(labels) nl := len(m.opts.Labels) + len(labels)
if nl == 0 { if nl == 0 {
return name return name
@@ -93,7 +83,36 @@ func (m *prometheusMeter) buildMetric(name string, labels ...string) string {
nlabels = append(nlabels, m.opts.Labels...) nlabels = append(nlabels, m.opts.Labels...)
nlabels = append(nlabels, labels...) nlabels = append(nlabels, labels...)
if len(m.opts.LabelPrefix) == 0 {
return meter.BuildName(name, nlabels...) return meter.BuildName(name, nlabels...)
}
for idx := 0; idx < nl; idx += 2 {
nlabels[idx] = m.opts.LabelPrefix + nlabels[idx]
}
return meter.BuildName(name, nlabels...)
}
func (m *prometheusMeter) buildName(name string) string {
if len(m.opts.MetricPrefix) > 0 {
name = m.opts.MetricPrefix + name
}
return name
}
func (m *prometheusMeter) buildLabels(labels ...string) []string {
nl := len(labels)
if nl == 0 {
return nil
}
nlabels := make([]string, 0, nl)
for idx := 0; idx < nl; idx += 2 {
nlabels = append(nlabels, m.opts.LabelPrefix+labels[idx])
nlabels = append(nlabels, labels[idx+1])
}
return nlabels
} }
func (m *prometheusMeter) Name() string { func (m *prometheusMeter) Name() string {
@@ -101,10 +120,10 @@ 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.buildName(name)
labels = append(m.opts.Labels, labels...) labels = m.buildLabels(append(m.opts.Labels, labels...)...)
cd, ok := m.counter[nm] cd, ok := m.counter[nm]
h := newHash(labels) h := newHash(labels)
if !ok { if !ok {
@@ -124,10 +143,10 @@ 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.buildName(name)
labels = append(m.opts.Labels, labels...) labels = m.buildLabels(append(m.opts.Labels, labels...)...)
cd, ok := m.floatCounter[nm] cd, ok := m.floatCounter[nm]
h := newHash(labels) h := newHash(labels)
if !ok { if !ok {
@@ -147,10 +166,10 @@ 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.buildName(name)
labels = append(m.opts.Labels, labels...) labels = m.buildLabels(append(m.opts.Labels, labels...)...)
cd, ok := m.gauge[nm] cd, ok := m.gauge[nm]
h := newHash(labels) h := newHash(labels)
if !ok { if !ok {
@@ -170,10 +189,10 @@ 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.buildName(name)
labels = append(m.opts.Labels, labels...) labels = m.buildLabels(append(m.opts.Labels, labels...)...)
cd, ok := m.histogram[nm] cd, ok := m.histogram[nm]
h := newHash(labels) h := newHash(labels)
if !ok { if !ok {
@@ -193,10 +212,10 @@ 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.buildName(name)
labels = append(m.opts.Labels, labels...) labels = m.buildLabels(append(m.opts.Labels, labels...)...)
cd, ok := m.summary[nm] cd, ok := m.summary[nm]
h := newHash(labels) h := newHash(labels)
if !ok { if !ok {
@@ -216,10 +235,10 @@ 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.buildName(name)
labels = append(m.opts.Labels, labels...) labels = m.buildLabels(append(m.opts.Labels, labels...)...)
cd, ok := m.summary[nm] cd, ok := m.summary[nm]
h := newHash(labels) h := newHash(labels)
if !ok { if !ok {
@@ -260,10 +279,8 @@ func (m *prometheusMeter) Write(w io.Writer, opts ...meter.Option) error {
} }
if options.WriteProcessMetrics || options.WriteFDMetrics { if options.WriteProcessMetrics || options.WriteFDMetrics {
pc := collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}) c := collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})
_ = m.set.Register(pc) _ = m.set.Register(c)
gc := collectors.NewGoCollector(collectors.WithGoCollectorRuntimeMetrics(collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/.*")}))
_ = m.set.Register(gc)
} }
g, ok := m.set.(prometheus.Gatherer) g, ok := m.set.(prometheus.Gatherer)
@@ -276,13 +293,11 @@ func (m *prometheusMeter) Write(w io.Writer, opts ...meter.Option) error {
return err return err
} }
enc := expfmt.NewEncoder(w, expfmt.NewFormat(expfmt.TypeTextPlain)) enc := expfmt.NewEncoder(w, expfmt.FmtText)
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 +312,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 +327,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 +342,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 +357,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 +370,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 +388,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,
@@ -500,6 +512,7 @@ func (c prometheusSummary) UpdateDuration(n time.Time) {
} }
func newHash(labels []string) uint64 { func newHash(labels []string) uint64 {
labels = meter.BuildLabels(labels...)
h := fnv.New64a() h := fnv.New64a()
for _, l := range labels { for _, l := range labels {
h.Write([]byte(l)) h.Write([]byte(l))

View File

@@ -2,54 +2,19 @@ package prometheus
import ( import (
"bytes" "bytes"
"fmt" "context"
"testing" "testing"
"go.unistack.org/micro/v3/meter" "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 TestBuildMetric(t *testing.T) {
m := NewMeter(meter.Labels("service_name", "test", "service_version", "0.0.0.1"))
if err := m.Init(); err != nil {
t.Fatal(err)
}
name := m.buildMetric("micro_server")
if name != `micro_server{service_name="test",service_version="0.0.0.1"}` {
t.Fatal("invalid name")
}
}
func TestWithDefaultLabels(t *testing.T) {
m := NewMeter(meter.Labels("service_name", "test", "service_version", "0.0.0.1"))
if err := m.Init(); err != nil {
t.Fatal(err)
}
m.Counter("micro_server", "endpoint", "ep3", "path", "/path3", "status", "success").Inc()
buf := bytes.NewBuffer(nil)
_ = m.Write(buf, meter.WriteProcessMetrics(false), meter.WriteFDMetrics(false))
if !bytes.Contains(buf.Bytes(), []byte(`micro_server{service_name="test",service_version="0.0.0.1",endpoint="ep3",path="/path3",status="success"} 1`)) {
t.Fatalf("invalid metrics output: %s", buf.Bytes())
}
}
func TestStd(t *testing.T) {
m := NewMeter(meter.WriteProcessMetrics(true), meter.WriteFDMetrics(true))
if err := m.Init(); err != nil {
t.Fatal(err)
}
buf := bytes.NewBuffer(nil)
_ = m.Write(buf)
if !bytes.Contains(buf.Bytes(), []byte(`go_goroutine`)) {
t.Fatalf("invalid metrics output: %s", buf.Bytes())
}
}
func TestBuildName(t *testing.T) { func TestBuildName(t *testing.T) {
m := NewMeter() m := NewMeter()
check := `micro_foo{aaa="b",bar="baz",ccc="d"}` check := `micro_foo{micro_aaa="b",micro_bar="baz",micro_ccc="d"}`
name := m.buildMetric("micro_foo", "bar", "baz", "aaa", "b", "ccc", "d") name := m.buildMetric("foo", "bar", "baz", "aaa", "b", "ccc", "d")
if name != check { if name != check {
t.Fatalf("metric name error: %s != %s", name, check) t.Fatalf("metric name error: %s != %s", name, check)
} }
@@ -58,40 +23,48 @@ func TestBuildName(t *testing.T) {
cnt.Inc() cnt.Inc()
} }
func TestMultiple(t *testing.T) { func TestWrapper(t *testing.T) {
m := NewMeter() // meter.Labels("test_key", "test_val")) m := NewMeter() // meter.Labels("test_key", "test_val"))
m.Counter("micro_server", "endpoint", "ep1", "path", "/path1").Inc() w := wrapper.NewClientWrapper(
m.Counter("micro_server", "endpoint", "ep1", "path", "/path1").Inc() wrapper.ServiceName("svc1"),
wrapper.ServiceVersion("0.0.1"),
wrapper.ServiceID("12345"),
wrapper.Meter(m),
)
m.Counter("micro_server", "endpoint", "ep2", "path", "/path2").Inc() ctx := context.Background()
m.Counter("micro_server", "endpoint", "ep2", "path", "/path2").Inc()
m.Counter("micro_server", "endpoint", "ep3", "path", "/path3", "status", "success").Inc()
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) buf := bytes.NewBuffer(nil)
_ = m.Write(buf, meter.WriteProcessMetrics(false), meter.WriteFDMetrics(false)) _ = m.Write(buf, meter.WriteProcessMetrics(false), meter.WriteFDMetrics(false))
if !bytes.Contains(buf.Bytes(), []byte(`micro_server{endpoint="ep1",path="/path1"} 2`)) { if !bytes.Contains(buf.Bytes(), []byte(`micro_client_request_inflight{micro_endpoint="svc2.Service.Method"} 0`)) {
t.Fatalf("invalid metrics output: %s", buf.Bytes()) t.Fatalf("invalid metrics output: %s", buf.Bytes())
} }
} }
func TestCounterSet(t *testing.T) { func TestMultiple(t *testing.T) {
m := NewMeter() m := NewMeter() // meter.Labels("test_key", "test_val"))
value := uint64(42) m.Counter("server", "endpoint", "ep1", "path", "/path1").Inc()
m.Counter("server", "endpoint", "ep1", "path", "/path1").Inc()
m.Counter("forte_accounts_total", "channel_code", "crm").Set(value) m.Counter("server", "endpoint", "ep2", "path", "/path2").Inc()
m.Counter("server", "endpoint", "ep2", "path", "/path2").Inc()
m.Counter("server", "endpoint", "ep3", "path", "/path3", "status", "success").Inc()
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
_ = m.Write(buf, meter.WriteProcessMetrics(false), meter.WriteFDMetrics(false))
_ = m.Write(buf) if !bytes.Contains(buf.Bytes(), []byte(`micro_server{micro_endpoint="ep1",micro_path="/path1"} 2`)) {
// t.Fatal("XXXX")
output := buf.String() t.Fatalf("invalid metrics output: %s", buf.Bytes())
expectedOutput := fmt.Sprintf(`%s{channel_code="crm"} %d`, "forte_accounts_total", value)
if !bytes.Contains(buf.Bytes(), []byte(expectedOutput)) {
t.Fatalf("invalid metrics output: expected %q, got %q", expectedOutput, output)
} }
} }