Skip to content

Commit 6f82e6b

Browse files
authored
Merge pull request #1 from aldas/code
move code to this repository
2 parents dd0a36f + e96faa2 commit 6f82e6b

File tree

12 files changed

+1220
-0
lines changed

12 files changed

+1220
-0
lines changed

.editorconfig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# EditorConfig coding styles definitions. For more information about the
2+
# properties used in this file, please see the EditorConfig documentation:
3+
# http://editorconfig.org/
4+
5+
# indicate this is the root of the project
6+
root = true
7+
8+
[*]
9+
charset = utf-8
10+
11+
end_of_line = LF
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
15+
indent_style = space
16+
indent_size = 2
17+
18+
[Makefile]
19+
indent_style = tab
20+
21+
[*.md]
22+
trim_trailing_whitespace = false
23+
24+
[*.go]
25+
indent_style = tab

.gitattributes

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Automatically normalize line endings for all text-based files
2+
# http://git-scm.com/docs/gitattributes#_end_of_line_conversion
3+
* text=auto
4+
5+
# For the following file types, normalize line endings to LF on checking and
6+
# prevent conversion to CRLF when they are checked out (this is required in
7+
# order to prevent newline related issues)
8+
.* text eol=lf
9+
*.go text eol=lf
10+
*.yml text eol=lf
11+
*.html text eol=lf
12+
*.md text eol=lf
13+
*.css text eol=lf
14+
*.js text eol=lf
15+
*.json text eol=lf
16+
LICENSE text eol=lf
17+

.github/workflows/checks.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Run checks
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read # to fetch code (actions/checkout)
14+
15+
env:
16+
# run static analysis only with the latest Go version
17+
LATEST_GO_VERSION: "1.26"
18+
19+
jobs:
20+
check:
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout Code
24+
uses: actions/checkout@v5
25+
26+
- name: Set up Go ${{ matrix.go }}
27+
uses: actions/setup-go@v6
28+
with:
29+
go-version: ${{ env.LATEST_GO_VERSION }}
30+
check-latest: true
31+
32+
- name: Run golint
33+
run: |
34+
go install golang.org/x/lint/golint@latest
35+
golint -set_exit_status ./...
36+
37+
- name: Run staticcheck
38+
run: |
39+
go install honnef.co/go/tools/cmd/staticcheck@latest
40+
staticcheck ./...
41+
42+
- name: Run gosec
43+
run: |
44+
go install github.com/securego/gosec/v2/cmd/gosec@master
45+
gosec -exclude-dir=.cache ./...
46+
47+
- name: Run govulncheck
48+
run: |
49+
go version
50+
go install golang.org/x/vuln/cmd/govulncheck@latest
51+
govulncheck ./...

.github/workflows/echo.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Run Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read # to fetch code (actions/checkout)
14+
15+
env:
16+
# run coverage and benchmarks only with the latest Go version
17+
LATEST_GO_VERSION: "1.26"
18+
19+
jobs:
20+
test:
21+
strategy:
22+
matrix:
23+
os: [ ubuntu-latest, macos-latest, windows-latest ]
24+
# Each major Go release is supported until there are two newer major releases. https://golang.org/doc/devel/release.html#policy
25+
# Echo tests with last four major releases (unless there are pressing vulnerabilities)
26+
# As we depend on `golang.org/x/` libraries which only support last 2 Go releases we could have situations when
27+
# we derive from last four major releases promise.
28+
go: [ "1.25", "1.26" ]
29+
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
30+
runs-on: ${{ matrix.os }}
31+
steps:
32+
- name: Checkout Code
33+
uses: actions/checkout@v5
34+
35+
- name: Set up Go ${{ matrix.go }}
36+
uses: actions/setup-go@v6
37+
with:
38+
go-version: ${{ matrix.go }}
39+
40+
- name: Run Tests
41+
run: go test -race --coverprofile=coverage.coverprofile --covermode=atomic ./...
42+
43+
- name: Upload coverage to Codecov
44+
if: success() && matrix.go == env.LATEST_GO_VERSION && matrix.os == 'ubuntu-latest'
45+
uses: codecov/codecov-action@v5
46+
with:
47+
token:
48+
fail_ci_if_error: false
49+
50+
benchmark:
51+
needs: test
52+
name: Benchmark comparison
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Checkout Code (Previous)
56+
uses: actions/checkout@v4
57+
with:
58+
ref: ${{ github.base_ref }}
59+
path: previous
60+
61+
- name: Checkout Code (New)
62+
uses: actions/checkout@v5
63+
with:
64+
path: new
65+
66+
- name: Set up Go ${{ matrix.go }}
67+
uses: actions/setup-go@v6
68+
with:
69+
go-version: ${{ env.LATEST_GO_VERSION }}
70+
71+
- name: Install Dependencies
72+
run: go install golang.org/x/perf/cmd/benchstat@latest
73+
74+
- name: Run Benchmark (Previous)
75+
run: |
76+
cd previous
77+
go test -run="-" -bench=".*" -count=8 ./... > benchmark.txt
78+
79+
- name: Run Benchmark (New)
80+
run: |
81+
cd new
82+
go test -run="-" -bench=".*" -count=8 ./... > benchmark.txt
83+
84+
- name: Run Benchstat
85+
run: |
86+
benchstat previous/benchmark.txt new/benchmark.txt

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
coverage.txt
3+
_test
4+
vendor
5+
.idea
6+
*.iml
7+
*.out
8+
.vscode

Makefile

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
PKG := "github.com/labstack/echo-prometheus"
2+
PKG_LIST := $(shell go list ${PKG}/...)
3+
4+
.DEFAULT_GOAL := check
5+
check: lint vet security race ## Check project
6+
7+
8+
init:
9+
@go install golang.org/x/lint/golint@latest
10+
@go install honnef.co/go/tools/cmd/staticcheck@latest
11+
@go install github.com/securego/gosec/v2/cmd/gosec@latest
12+
13+
lint: ## Lint the files
14+
@staticcheck ${PKG_LIST}
15+
@golint -set_exit_status ${PKG_LIST}
16+
17+
vet: ## Vet the files
18+
@go vet ${PKG_LIST}
19+
20+
security: ## Run Gosec static code security analyzer
21+
@gosec -quiet -exclude-dir=.cache ./...
22+
23+
test: ## Run tests
24+
@go test -short ${PKG_LIST}
25+
26+
race: ## Run tests with data race detector
27+
@go test -race ${PKG_LIST}
28+
29+
benchmark: ## Run benchmarks
30+
@go test -run="-" -bench=".*" ${PKG_LIST}
31+
32+
format: ## Format the source code
33+
@find ./ -type f -name "*.go" -exec gofmt -w {} \;
34+
35+
help: ## Display this help screen
36+
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
37+
38+
goversion ?= "1.26"
39+
test_version: ## Run tests inside Docker with given version (defaults to 1.26 oldest supported). Example: make test_version goversion=1.26
40+
@docker run --rm -it -v $(shell pwd):/project golang:$(goversion) /bin/sh -c "cd /project && make race"

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
[![Sourcegraph](https://sourcegraph.com/github.com/labstack/echo-prometheus/-/badge.svg?style=flat-square)](https://sourcegraph.com/github.com/labstack/echo-prometheus?badge)
2+
[![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/labstack/echo-prometheus)
3+
[![Go Report Card](https://goreportcard.com/badge/github.com/labstack/echo-prometheus?style=flat-square)](https://goreportcard.com/report/github.com/labstack/echo-prometheus)
4+
[![License](http://img.shields.io/badge/license-mit-blue.svg?style=flat-square)](https://raw.githubusercontent.com/labstack/echo-prometheus/main/LICENSE)
5+
6+
# Echo Prometheus metrics and monitoring middleware
7+
8+
[Prometheus](https://prometheus.io/) middleware for [Echo](https://github.com/labstack/echo) framework.
9+
10+
## Versioning
11+
12+
* version `v0.x.y` tracks the latest Echo version (`v5`).
13+
* `main` branch is compatible with the latest Echo version (`v5`).
14+
15+
## Usage
16+
17+
Add Prometheus middleware dependency
18+
19+
```bash
20+
go get github.com/labstack/echo-prometheus
21+
```
22+
23+
Use as an import statement
24+
25+
```go
26+
import echoprometheus "github.com/labstack/echo-prometheus"
27+
```
28+
29+
Add middleware to your Echo instance
30+
```go
31+
e.Use(echoprometheus.NewMiddleware("myapp"))
32+
```
33+
or with config
34+
```go
35+
e.Use(echoprometheus.NewMiddlewareWithConfig(echoprometheus.MiddlewareConfig{
36+
Subsystem: "myapp",
37+
}))
38+
```
39+
40+
Add handler to your Echo instance to expose metrics
41+
```go
42+
e.GET("/metrics", echoprometheus.NewHandler())
43+
```
44+
45+
## Full example
46+
47+
See [example](example/main.go)

example/main.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"log/slog"
5+
"net/http"
6+
7+
echoprometheus "github.com/labstack/echo-prometheus"
8+
"github.com/labstack/echo/v5"
9+
)
10+
11+
func main() {
12+
e := echo.New()
13+
14+
// Enable metrics middleware
15+
e.Use(echoprometheus.NewMiddleware("myapp"))
16+
e.GET("/metrics", echoprometheus.NewHandler()) // expose metrics for scraping
17+
18+
e.GET("/health", func(c *echo.Context) error {
19+
return c.String(http.StatusOK, "ok")
20+
})
21+
22+
if err := e.Start(":8080"); err != nil {
23+
slog.Error("failed to start server", "error", err)
24+
}
25+
}

go.mod

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module github.com/labstack/echo-prometheus
2+
3+
go 1.25.0
4+
5+
require (
6+
github.com/labstack/echo/v5 v5.0.4
7+
github.com/prometheus/client_golang v1.23.2
8+
github.com/prometheus/common v0.67.5
9+
github.com/stretchr/testify v1.11.1
10+
)
11+
12+
require (
13+
github.com/beorn7/perks v1.0.1 // indirect
14+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
15+
github.com/davecgh/go-spew v1.1.1 // indirect
16+
github.com/kr/text v0.2.0 // indirect
17+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
18+
github.com/pmezard/go-difflib v1.0.0 // indirect
19+
github.com/prometheus/client_model v0.6.2 // indirect
20+
github.com/prometheus/procfs v0.19.2 // indirect
21+
go.yaml.in/yaml/v2 v2.4.3 // indirect
22+
golang.org/x/sys v0.41.0 // indirect
23+
golang.org/x/time v0.14.0 // indirect
24+
google.golang.org/protobuf v1.36.11 // indirect
25+
gopkg.in/yaml.v3 v3.0.1 // indirect
26+
)

go.sum

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
2+
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
3+
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
4+
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
5+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
6+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
7+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8+
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
9+
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
10+
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
11+
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
12+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
13+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
14+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
15+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
16+
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
17+
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
18+
github.com/labstack/echo/v5 v5.0.4 h1:ll3I/O8BifjMztj9dD1vx/peZQv8cR2CTUdQK6QxGGc=
19+
github.com/labstack/echo/v5 v5.0.4/go.mod h1:SyvlSdObGjRXeQfCCXW/sybkZdOOQZBmpKF0bvALaeo=
20+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
21+
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
22+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
23+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
24+
github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o=
25+
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
26+
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
27+
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
28+
github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4=
29+
github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw=
30+
github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws=
31+
github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw=
32+
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
33+
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
34+
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
35+
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
36+
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
37+
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
38+
go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
39+
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
40+
golang.org/x/net v0.49.0 h1:eeHFmOGUTtaaPSGNmjBKpbng9MulQsJURQUAfUwY++o=
41+
golang.org/x/net v0.49.0/go.mod h1:/ysNB2EvaqvesRkuLAyjI1ycPZlQHM3q01F02UY/MV8=
42+
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
43+
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
44+
golang.org/x/text v0.33.0 h1:B3njUFyqtHDUI5jMn1YIr5B0IE2U0qck04r6d4KPAxE=
45+
golang.org/x/text v0.33.0/go.mod h1:LuMebE6+rBincTi9+xWTY8TztLzKHc/9C1uBCG27+q8=
46+
golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI=
47+
golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4=
48+
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
49+
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
50+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
51+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
52+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
53+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
54+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)