Compare commits
	
		
			16 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 17593e466c | |||
|  | 6f996f3cc4 | ||
| 9955afc90d | |||
| 12fd9c04f5 | |||
| 0579d5df86 | |||
| 64703bb6f3 | |||
| 1f916abc1d | |||
|  | 3a953fbf61 | ||
|  | 7949bb3f1f | ||
|  | b88480bc51 | ||
| b2b7e9b1a2 | |||
| 5cbaca0068 | |||
|  | c2ea781b28 | ||
| c1e2eda3e5 | |||
| 88a553d931 | |||
| b56bb7f834 | 
							
								
								
									
										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}} |  | ||||||
							
								
								
									
										53
									
								
								.github/workflows/job_coverage.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										53
									
								
								.github/workflows/job_coverage.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,53 @@ | |||||||
|  | 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@v3 | ||||||
|  |       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 }} | ||||||
							
								
								
									
										29
									
								
								.github/workflows/job_lint.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								.github/workflows/job_lint.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | |||||||
|  | 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' | ||||||
							
								
								
									
										94
									
								
								.github/workflows/job_sync.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								.github/workflows/job_sync.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,94 @@ | |||||||
|  | name: sync | ||||||
|  |  | ||||||
|  | on: | ||||||
|  |   schedule: | ||||||
|  |     - cron: '*/5 * * * *' | ||||||
|  |   # Allows you to run this workflow manually from the Actions tab | ||||||
|  |   workflow_dispatch: | ||||||
|  |  | ||||||
|  | jobs: | ||||||
|  |   sync: | ||||||
|  |     if: github.server_url != 'https://github.com' | ||||||
|  |     runs-on: ubuntu-latest | ||||||
|  |     steps: | ||||||
|  |     - name: init | ||||||
|  |       run: | | ||||||
|  |         git config --global user.email "vtolstov <vtolstov@users.noreply.github.com>" | ||||||
|  |         git config --global user.name "github-actions[bot]" | ||||||
|  |         echo "machine git.unistack.org login vtolstov password ${{ secrets.TOKEN_GITEA }}" >> /root/.netrc | ||||||
|  |         echo "machine github.com login vtolstov password ${{ secrets.TOKEN_GITHUB }}" >> /root/.netrc | ||||||
|  |  | ||||||
|  |     - name: check master | ||||||
|  |       id: check_master | ||||||
|  |       run: | | ||||||
|  |         src_hash=$(git ls-remote https://github.com/${GITHUB_REPOSITORY} refs/heads/master | cut -f1) | ||||||
|  |         dst_hash=$(git ls-remote ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} refs/heads/master | cut -f1) | ||||||
|  |         echo "src_hash=$src_hash" | ||||||
|  |         echo "dst_hash=$dst_hash" | ||||||
|  |         if [ "$src_hash" != "$dst_hash" ]; then | ||||||
|  |           echo "sync_needed=true" >> $GITHUB_OUTPUT | ||||||
|  |         else | ||||||
|  |           echo "sync_needed=false" >> $GITHUB_OUTPUT | ||||||
|  |         fi | ||||||
|  |  | ||||||
|  |     - name: sync master | ||||||
|  |       if: steps.check_master.outputs.sync_needed == 'true' | ||||||
|  |       run: | | ||||||
|  |         git clone --filter=blob:none --filter=tree:0 --branch master --single-branch ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} repo | ||||||
|  |         cd repo | ||||||
|  |         git remote add --no-tags --fetch --track master upstream https://github.com/${GITHUB_REPOSITORY} | ||||||
|  |         git pull --rebase upstream master | ||||||
|  |         git push upstream master --progress | ||||||
|  |         git push origin master --progress | ||||||
|  |         cd ../ | ||||||
|  |         rm -rf repo | ||||||
|  |  | ||||||
|  |     - name: check v3 | ||||||
|  |       id: check_v3 | ||||||
|  |       run: | | ||||||
|  |         src_hash=$(git ls-remote https://github.com/${GITHUB_REPOSITORY} refs/heads/v3 | cut -f1) | ||||||
|  |         dst_hash=$(git ls-remote ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} refs/heads/v3 | cut -f1) | ||||||
|  |         echo "src_hash=$src_hash" | ||||||
|  |         echo "dst_hash=$dst_hash" | ||||||
|  |         if [ "$src_hash" != "$dst_hash" ]; then | ||||||
|  |           echo "sync_needed=true" >> $GITHUB_OUTPUT | ||||||
|  |         else | ||||||
|  |           echo "sync_needed=false" >> $GITHUB_OUTPUT | ||||||
|  |         fi | ||||||
|  |  | ||||||
|  |     - name: sync v3 | ||||||
|  |       if: steps.check_v3.outputs.sync_needed == 'true' | ||||||
|  |       run: | | ||||||
|  |         git clone --filter=blob:none --filter=tree:0 --branch v3 --single-branch ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} repo | ||||||
|  |         cd repo | ||||||
|  |         git remote add --no-tags --fetch --track v3 upstream https://github.com/${GITHUB_REPOSITORY} | ||||||
|  |         git pull --rebase upstream v3 | ||||||
|  |         git push upstream v3 --progress | ||||||
|  |         git push origin v3 --progress | ||||||
|  |         cd ../ | ||||||
|  |         rm -rf repo | ||||||
|  |  | ||||||
|  |     - name: check v4 | ||||||
|  |       id: check_v4 | ||||||
|  |       run: | | ||||||
|  |         src_hash=$(git ls-remote https://github.com/${GITHUB_REPOSITORY} refs/heads/v4 | cut -f1) | ||||||
|  |         dst_hash=$(git ls-remote ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} refs/heads/v4 | cut -f1) | ||||||
|  |         echo "src_hash=$src_hash" | ||||||
|  |         echo "dst_hash=$dst_hash" | ||||||
|  |         if [ "$src_hash" != "$dst_hash" ]; then | ||||||
|  |           echo "sync_needed=true" >> $GITHUB_OUTPUT | ||||||
|  |         else | ||||||
|  |           echo "sync_needed=false" >> $GITHUB_OUTPUT | ||||||
|  |         fi | ||||||
|  |  | ||||||
|  |     - name: sync v4 | ||||||
|  |       if: steps.check_v4.outputs.sync_needed == 'true' | ||||||
|  |       run: | | ||||||
|  |         git clone --filter=blob:none --filter=tree:0 --branch v4 --single-branch ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} repo | ||||||
|  |         cd repo | ||||||
|  |         git remote add --no-tags --fetch --track v4 upstream https://github.com/${GITHUB_REPOSITORY} | ||||||
|  |         git pull --rebase upstream v4 | ||||||
|  |         git push upstream v4 --progress | ||||||
|  |         git push origin v4 --progress | ||||||
|  |         cd ../ | ||||||
|  |         rm -rf repo | ||||||
							
								
								
									
										31
									
								
								.github/workflows/job_test.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								.github/workflows/job_test.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,31 @@ | |||||||
|  | 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 ./... | ||||||
							
								
								
									
										50
									
								
								.github/workflows/job_tests.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								.github/workflows/job_tests.yml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @@ -0,0 +1,50 @@ | |||||||
|  | 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
									
									
								
							
							
						
						
									
										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 | ||||||
|  |   timeout: 5m | ||||||
|  |   issues-exit-code: 1 | ||||||
|  |   tests: true | ||||||
| @@ -1,4 +1,5 @@ | |||||||
| # VictoriaMetrics | # VictoriaMetrics | ||||||
|  |  | ||||||
|  |  | ||||||
| Wrappers are a form of middleware that can be used with go-micro services. They can wrap both the Client and Server handlers.  | Wrappers are a form of middleware that can be used with go-micro services. They can wrap both the Client and Server handlers.  | ||||||
| This plugin implements the HandlerWrapper interface to provide automatic prometheus metric handling | This plugin implements the HandlerWrapper interface to provide automatic prometheus metric handling | ||||||
|   | |||||||
							
								
								
									
										17
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								go.mod
									
									
									
									
									
								
							| @@ -1,16 +1,23 @@ | |||||||
| module go.unistack.org/micro-meter-victoriametrics/v4 | module go.unistack.org/micro-meter-victoriametrics/v4 | ||||||
|  |  | ||||||
| go 1.22.0 | go 1.24.0 | ||||||
|  |  | ||||||
|  | toolchain go1.24.4 | ||||||
|  |  | ||||||
| require ( | require ( | ||||||
| 	github.com/VictoriaMetrics/metrics v1.35.2 | 	github.com/VictoriaMetrics/metrics v1.40.2 | ||||||
| 	go.unistack.org/micro/v4 v4.1.2 | 	go.unistack.org/micro/v4 v4.1.23 | ||||||
| ) | ) | ||||||
|  |  | ||||||
| require ( | require ( | ||||||
| 	github.com/spf13/cast v1.7.1 // indirect | 	github.com/google/uuid v1.6.0 // indirect | ||||||
|  | 	github.com/matoous/go-nanoid v1.5.1 // indirect | ||||||
|  | 	github.com/spf13/cast v1.8.0 // indirect | ||||||
| 	github.com/valyala/fastrand v1.1.0 // indirect | 	github.com/valyala/fastrand v1.1.0 // indirect | ||||||
| 	github.com/valyala/histogram v1.2.0 // indirect | 	github.com/valyala/histogram v1.2.0 // indirect | ||||||
| 	golang.org/x/sys v0.30.0 // indirect | 	go.unistack.org/micro-proto/v4 v4.1.0 // indirect | ||||||
|  | 	golang.org/x/sys v0.37.0 // indirect | ||||||
|  | 	google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a // indirect | ||||||
|  | 	google.golang.org/grpc v1.72.0 // indirect | ||||||
|  | 	google.golang.org/protobuf v1.36.6 // indirect | ||||||
| ) | ) | ||||||
|   | |||||||
							
								
								
									
										67
									
								
								go.sum
									
									
									
									
									
								
							
							
						
						
									
										67
									
								
								go.sum
									
									
									
									
									
								
							| @@ -1,27 +1,48 @@ | |||||||
| github.com/VictoriaMetrics/metrics v1.23.1 h1:/j8DzeJBxSpL2qSIdqnRFLvQQhbJyJbbEi22yMm7oL0= | github.com/VictoriaMetrics/metrics v1.40.2 h1:OVSjKcQEx6JAwGeu8/KQm9Su5qJ72TMEW4xYn5vw3Ac= | ||||||
| github.com/VictoriaMetrics/metrics v1.24.0 h1:ILavebReOjYctAGY5QU2F9X0MYvkcrG3aEn2RKa1Zkw= | github.com/VictoriaMetrics/metrics v1.40.2/go.mod h1:XE4uudAAIRaJE614Tl5HMrtoEU6+GDZO4QTnNSsZRuA= | ||||||
| github.com/VictoriaMetrics/metrics v1.24.0/go.mod h1:eFT25kvsTidQFHb6U0oa0rTrDRdz4xTYjpL8+UPohys= | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= | ||||||
| github.com/VictoriaMetrics/metrics v1.35.1 h1:o84wtBKQbzLdDy14XeskkCZih6anG+veZ1SwJHFGwrU= | github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||||
| github.com/VictoriaMetrics/metrics v1.35.1/go.mod h1:r7hveu6xMdUACXvB8TYdAj8WEsKzWB0EkpJN+RDtOf8= | github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= | ||||||
| github.com/VictoriaMetrics/metrics v1.35.2 h1:Bj6L6ExfnakZKYPpi7mGUnkJP4NGQz2v5wiChhXNyWQ= | github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= | ||||||
| github.com/VictoriaMetrics/metrics v1.35.2/go.mod h1:r7hveu6xMdUACXvB8TYdAj8WEsKzWB0EkpJN+RDtOf8= | github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= | ||||||
| github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y= | github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= | ||||||
| github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= | ||||||
|  | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||||||
|  | github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||||||
|  | github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||||||
|  | github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= | ||||||
|  | github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= | ||||||
|  | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= | ||||||
|  | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= | ||||||
|  | github.com/matoous/go-nanoid v1.5.1 h1:aCjdvTyO9LLnTIi0fgdXhOPPvOHjpXN6Ik9DaNjIct4= | ||||||
|  | github.com/matoous/go-nanoid v1.5.1/go.mod h1:zyD2a71IubI24efhpvkJz+ZwfwagzgSO6UNiFsZKN7U= | ||||||
|  | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= | ||||||
|  | github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||||||
|  | github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII= | ||||||
|  | github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o= | ||||||
|  | github.com/spf13/cast v1.8.0 h1:gEN9K4b8Xws4EX0+a0reLmhq8moKn7ntRlQYgjPeCDk= | ||||||
|  | github.com/spf13/cast v1.8.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= | ||||||
|  | github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= | ||||||
|  | github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= | ||||||
| github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8= | github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8= | ||||||
| github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ= | 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 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OLoQ= | ||||||
| github.com/valyala/histogram v1.2.0/go.mod h1:Hb4kBwb4UxsaNbbbh+RRz8ZR6pdodR57tzWUS3BUzXY= | 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-proto/v4 v4.1.0 h1:qPwL2n/oqh9RE3RTTDgt28XK3QzV597VugQPaw9lKUk= | ||||||
| go.unistack.org/micro/v4 v4.0.1/go.mod h1:p/J5UcSJjfHsWGT31uKoghQ5rUQZzQJBAFy+Z4+ZVMs= | go.unistack.org/micro-proto/v4 v4.1.0/go.mod h1:ArmK7o+uFvxSY3dbJhKBBX4Pm1rhWdLEFf3LxBrMtec= | ||||||
| go.unistack.org/micro/v4 v4.0.7 h1:2lwtZlHcSwgkahhFbkI4x1lOS79lw8uLHtcEhlFF+AM= | go.unistack.org/micro/v4 v4.1.23 h1:T9O1O1mN60JHqIAIw+XkNik8xb0h90O9fJ55uQMb8VU= | ||||||
| go.unistack.org/micro/v4 v4.0.7/go.mod h1:bVEYTlPi0EsdgZZt311bIroDg9ict7ky3C87dSCCAGk= | go.unistack.org/micro/v4 v4.1.23/go.mod h1:nlBXTbx0rQrSZX4HPp2m57PHmpuGPWUd0O+jpUIiPto= | ||||||
| go.unistack.org/micro/v4 v4.0.20 h1:+DzI0l4L3pItOPWrM5oqiJP/hSpfS5kKKePmWXzDw0I= | golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= | ||||||
| go.unistack.org/micro/v4 v4.0.20/go.mod h1:5+da5r835gP0WnNZbYUJDCvWpJ9Xc3IEGyp62e8o8R4= | golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= | ||||||
| go.unistack.org/micro/v4 v4.1.2 h1:9SOlPYyPNNFpg1A7BsvhDyQm3gysLH1AhWbDCp1hyoY= | golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= | ||||||
| go.unistack.org/micro/v4 v4.1.2/go.mod h1:lr3oYED8Ay1vjK68QqRw30QOtdk/ffpZqMFDasOUhKw= | golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= | ||||||
| golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= | golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= | ||||||
| golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= | ||||||
| golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= | google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a h1:51aaUVRocpvUOSQKM6Q7VuoaktNIaMCLuhZB6DKksq4= | ||||||
| golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | google.golang.org/genproto/googleapis/rpc v0.0.0-20250218202821-56aae31c358a/go.mod h1:uRxBH1mhmO8PGhU89cMcHaXKZqO+OfakD8QQO0oYwlQ= | ||||||
| golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= | google.golang.org/grpc v1.72.0 h1:S7UkcVa60b5AAQTaO6ZKamFp1zMZSU0fGDK2WZLbBnM= | ||||||
| golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | google.golang.org/grpc v1.72.0/go.mod h1:wH5Aktxcg25y1I3w7H69nHfXdOG3UiadoBtjh3izSDM= | ||||||
|  | google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY= | ||||||
|  | google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY= | ||||||
|  | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||||||
|  | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= | ||||||
|   | |||||||
| @@ -11,22 +11,35 @@ import ( | |||||||
| type victoriametricsMeter struct { | type victoriametricsMeter struct { | ||||||
| 	set              *metrics.Set | 	set              *metrics.Set | ||||||
| 	opts             meter.Options | 	opts             meter.Options | ||||||
|  | 	prometheusCompat bool | ||||||
| } | } | ||||||
|  |  | ||||||
| func NewMeter(opts ...meter.Option) meter.Meter { | func NewMeter(opts ...meter.Option) meter.Meter { | ||||||
| 	return &victoriametricsMeter{set: metrics.NewSet(), opts: meter.NewOptions(opts...)} | 	m := &victoriametricsMeter{set: metrics.NewSet(), opts: meter.NewOptions(opts...)} | ||||||
|  | 	if v, ok := m.opts.Context.Value(prometheusCompatKey{}).(bool); ok && v { | ||||||
|  | 		m.prometheusCompat = v | ||||||
|  | 	} | ||||||
|  | 	return m | ||||||
| } | } | ||||||
|  |  | ||||||
| func (r *victoriametricsMeter) Name() string { | func (r *victoriametricsMeter) Name() string { | ||||||
| 	return r.opts.Name | 	return r.opts.Name | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func (r *victoriametricsMeter) Unregister(name string, labels ...string) bool { | ||||||
|  | 	return r.set.UnregisterMetric(r.buildName(name, labels...)) | ||||||
|  | } | ||||||
|  |  | ||||||
| func (r *victoriametricsMeter) Clone(opts ...meter.Option) meter.Meter { | func (r *victoriametricsMeter) Clone(opts ...meter.Option) meter.Meter { | ||||||
| 	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} | 	m := &victoriametricsMeter{set: r.set, opts: options} | ||||||
|  | 	if v, ok := m.opts.Context.Value(prometheusCompatKey{}).(bool); ok && v { | ||||||
|  | 		m.prometheusCompat = v | ||||||
|  | 	} | ||||||
|  | 	return m | ||||||
| } | } | ||||||
|  |  | ||||||
| func (r *victoriametricsMeter) buildName(name string, labels ...string) string { | func (r *victoriametricsMeter) buildName(name string, labels ...string) string { | ||||||
| @@ -55,6 +68,16 @@ func (r *victoriametricsMeter) Gauge(name string, f func() float64, labels ...st | |||||||
| } | } | ||||||
|  |  | ||||||
| func (r *victoriametricsMeter) Histogram(name string, labels ...string) meter.Histogram { | func (r *victoriametricsMeter) Histogram(name string, labels ...string) meter.Histogram { | ||||||
|  | 	if r.prometheusCompat { | ||||||
|  | 		return r.set.GetOrCreatePrometheusHistogramExt(r.buildName(name, labels...), r.opts.Quantiles) | ||||||
|  | 	} | ||||||
|  | 	return r.set.GetOrCreateHistogram(r.buildName(name, labels...)) | ||||||
|  | } | ||||||
|  |  | ||||||
|  | func (r *victoriametricsMeter) HistogramExt(name string, quantiles []float64, labels ...string) meter.Histogram { | ||||||
|  | 	if r.prometheusCompat { | ||||||
|  | 		return r.set.GetOrCreatePrometheusHistogramExt(r.buildName(name, labels...), quantiles) | ||||||
|  | 	} | ||||||
| 	return r.set.GetOrCreateHistogram(r.buildName(name, labels...)) | 	return r.set.GetOrCreateHistogram(r.buildName(name, labels...)) | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -67,7 +90,7 @@ func (r *victoriametricsMeter) SummaryExt(name string, window time.Duration, qua | |||||||
| } | } | ||||||
|  |  | ||||||
| func (r *victoriametricsMeter) Set(opts ...meter.Option) meter.Meter { | func (r *victoriametricsMeter) Set(opts ...meter.Option) meter.Meter { | ||||||
| 	m := &victoriametricsMeter{opts: r.opts} | 	m := &victoriametricsMeter{opts: r.opts, prometheusCompat: r.prometheusCompat} | ||||||
| 	for _, o := range opts { | 	for _, o := range opts { | ||||||
| 		o(&m.opts) | 		o(&m.opts) | ||||||
| 	} | 	} | ||||||
| @@ -79,7 +102,12 @@ func (r *victoriametricsMeter) Init(opts ...meter.Option) error { | |||||||
| 	for _, o := range opts { | 	for _, o := range opts { | ||||||
| 		o(&r.opts) | 		o(&r.opts) | ||||||
| 	} | 	} | ||||||
|  | 	if v, ok := r.opts.Context.Value(prometheusCompatKey{}).(bool); ok && v { | ||||||
|  | 		r.prometheusCompat = v | ||||||
|  | 	} | ||||||
|  | 	if r.opts.Quantiles == nil { | ||||||
|  | 		r.opts.Quantiles = meter.DefaultQuantiles | ||||||
|  | 	} | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -106,3 +134,9 @@ func (r *victoriametricsMeter) Options() meter.Options { | |||||||
| func (r *victoriametricsMeter) String() string { | func (r *victoriametricsMeter) String() string { | ||||||
| 	return "victoriametrics" | 	return "victoriametrics" | ||||||
| } | } | ||||||
|  |  | ||||||
|  | type prometheusCompatKey struct{} | ||||||
|  |  | ||||||
|  | func PrometheusCompat(b bool) meter.Option { | ||||||
|  | 	return meter.SetOption(prometheusCompatKey{}, b) | ||||||
|  | } | ||||||
|   | |||||||
| @@ -10,10 +10,23 @@ import ( | |||||||
| 	"go.unistack.org/micro/v4/meter" | 	"go.unistack.org/micro/v4/meter" | ||||||
| ) | ) | ||||||
|  |  | ||||||
|  | func BenchmarkBuildName(b *testing.B) { | ||||||
|  | 	m := NewMeter(meter.Labels("pod", "xxx")) | ||||||
|  | 	if err := m.Init(); err != nil { | ||||||
|  | 		b.Fatal(err) | ||||||
|  | 	} | ||||||
|  | 	im := m.(*victoriametricsMeter) | ||||||
|  | 	b.ResetTimer() | ||||||
|  | 	for i := 0; i < b.N; i++ { | ||||||
|  | 		name := im.buildName("micro_foo", "bar", "baz", "aaa", "b", "ccc", "d") | ||||||
|  | 		_ = name | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
| func TestBuildName(t *testing.T) { | func TestBuildName(t *testing.T) { | ||||||
| 	m := NewMeter() | 	m := NewMeter() | ||||||
| 	im := m.(*victoriametricsMeter) | 	im := m.(*victoriametricsMeter) | ||||||
| 	check := `micro_foo{aaa="b",bar="baz",ccc="d"}` | 	check := `micro_foo{bar="baz",aaa="b",ccc="d"}` | ||||||
| 	name := im.buildName("micro_foo", "bar", "baz", "aaa", "b", "ccc", "d") | 	name := im.buildName("micro_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) | ||||||
| @@ -40,7 +53,7 @@ func TestWrapper(t *testing.T) { | |||||||
| 	_, _ = rsp, err | 	_, _ = 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_client_request_total{code="500",endpoint="Service.Method",status="failure"} 1`)) { | 	if !bytes.Contains(buf.Bytes(), []byte(`micro_client_request_total{endpoint="Service.Method",status="failure",code="500"} 1`)) { | ||||||
| 		t.Fatalf("invalid metrics output: %s", buf.Bytes()) | 		t.Fatalf("invalid metrics output: %s", buf.Bytes()) | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user