Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: slok/go-http-metrics
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.9.0
Choose a base ref
...
head repository: slok/go-http-metrics
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.10.0
Choose a head ref
Loading
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -9,26 +9,26 @@ jobs:
# Execute the checks inside the container instead the VM.
container: golangci/golangci-lint:v1.31.0-alpine
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v2.4.0
- run: golangci-lint run -E goimports

unit-test:
name: Unit test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
- uses: actions/checkout@v2.4.0
- uses: actions/setup-go@v2.1.4
with:
go-version: 1.15
go-version: 1.16
- run: make test

integration-test:
name: Integration test
runs-on: ubuntu-latest
needs: [check, unit-test]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
- uses: actions/checkout@v2.4.0
- uses: actions/setup-go@v2.1.4
with:
go-version: 1.15
go-version: 1.16
- run: make integration-test
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -2,6 +2,17 @@

## [Unreleased]

## [0.10.0] - 2021-11-16

### Added

- Support Fasthttp library.
- Support gorestful v3

### Changed

- Drop support gorestful v2

## [0.9.0] - 2020-10-03

### Added
@@ -100,7 +111,8 @@ Breaking change: The library has been refactored to be more flexible when adding
- HTTP latency requests.
- Prometheus recorder.

[unreleased]: https://github.com/slok/go-http-metrics/compare/v0.9.0...HEAD
[unreleased]: https://github.com/slok/go-http-metrics/compare/v0.10.0...HEAD
[0.10.0]: https://github.com/slok/go-http-metrics/compare/v0.9.0...v0.10.0
[0.9.0]: https://github.com/slok/go-http-metrics/compare/v0.8.0...v0.9.0
[0.8.0]: https://github.com/slok/go-http-metrics/compare/v0.7.0...v0.8.0
[0.7.0]: https://github.com/slok/go-http-metrics/compare/v0.6.1...v0.7.0
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

UNIT_TEST_CMD := go test `go list ./... | grep -v test\/integration` -race -coverprofile=.test_coverage.txt && \
go tool cover -func=.test_coverage.txt | tail -n1 | awk '{print "Total test coverage: " $$3}'
INTEGRATION_TEST_CMD := go test ./test/integration -race -tags='integration'
BENCHMARK_CMD := go test `go list ./... | grep -v vendor` -benchmem -bench=.
INTEGRATION_TEST_CMD := go test ./test/integration -race
BENCHMARK_CMD := go test `go list ./...` -benchmem -bench=.
CHECK_CMD := golangci-lint run -E goimports
DEPS_CMD := go mod tidy
MOCKS_CMD := go generate ./internal/mocks
24 changes: 15 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# go-http-metrics [![Build Status][github-actions-image]][github-actions-url] [![Go Report Card][goreport-image]][goreport-url] [![GoDoc][godoc-image]][godoc-url]

go-http-metrics knows how to measure http metrics in different metric formats a different Go HTTP framework/libs. The metrics measured are based on [RED] and/or [Four golden signals], follow standards and try to be measured in a efficient way.
go-http-metrics knows how to measure http metrics in different metric formats and Go HTTP framework/libs. The metrics measured are based on [RED] and/or [Four golden signals], follow standards and try to be measured in a efficient way.

## Table of contents

@@ -35,16 +35,19 @@ go-http-metrics is easy to extend to different metric backends by implementing `

The middleware is mainly focused to be compatible with Go std library using http.Handler, but it comes with helpers to get middlewares for other frameworks or libraries.

- [Go http.Handler][default-example]
- [Negroni][negroni-example]
- [httprouter][httprouter-example]
- [go-restful][gorestful-example]
- [Gin][gin-example]
**When `go-http-metrics` is imported as a dependency, it will only import the libraries being used, this is safe because each lib/framework is in its own package. More information [here][import-information-1] and [here][import-information-2]**

- [Alice][alice-example]
- [Chi][chi-example]
- [Echo][echo-example]
- [Fasthttp][fasthttp-example]
- [Gin][gin-example]
- [Go http.Handler][default-example]
- [Go-restful][gorestful-example]
- [Goji][goji-example]
- [Chi][chi-example]
- [Alice][alice-example]
- [gorilla][gorilla-example]
- [Gorilla][gorilla-example]
- [Httprouter][httprouter-example]
- [Negroni][negroni-example]

It supports any framework that supports http.Handler provider type middleware `func(http.Handler) http.Handler` (e.g Chi, Alice, Gorilla...). Use [`std.HandlerProvider`][handler-provider-docs]

@@ -225,3 +228,6 @@ This Option is used to unregister the Recorder views before are being registered
[prometheus-recorder]: metrics/prometheus
[opencensus-recorder]: metrics/opencensus
[handler-provider-docs]: https://pkg.go.dev/github.com/slok/go-http-metrics/middleware/std#HandlerProvider
[fasthttp-example]: examples/fasthttp
[import-information-1]: https://github.com/slok/go-http-metrics/issues/46
[import-information-2]: https://github.com/slok/go-http-metrics-imports
62 changes: 62 additions & 0 deletions examples/fasthttp/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"log"
"net/http"
"os"
"os/signal"
"syscall"

fasthttprouter "github.com/fasthttp/router"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/valyala/fasthttp"

metrics "github.com/slok/go-http-metrics/metrics/prometheus"
"github.com/slok/go-http-metrics/middleware"
fasthttpmiddleware "github.com/slok/go-http-metrics/middleware/fasthttp"
)

const (
srvAddr = ":8080"
metricsAddr = ":8081"
)

func main() {
// Create our middleware factory with the default settings.
mdlw := middleware.New(middleware.Config{
Recorder: metrics.NewRecorder(metrics.Config{}),
})

// Create fast HTTP router and global middleware.
r := fasthttprouter.New()

// Add our handler.
r.GET("/", fasthttp.RequestHandler(func(ctx *fasthttp.RequestCtx) {
ctx.SetStatusCode(http.StatusOK)
ctx.SetBody([]byte("Hello world"))
}))

// Set up middleware.
fasthttpHandler := fasthttpmiddleware.Handler("", mdlw, r.Handler)

// Serve our handler.
go func() {
log.Printf("server listening at %s", srvAddr)
if err := fasthttp.ListenAndServe(srvAddr, fasthttpHandler); err != nil {
log.Panicf("error while serving: %s", err)
}
}()

// Serve our metrics.
go func() {
log.Printf("metrics listening at %s", metricsAddr)
if err := http.ListenAndServe(metricsAddr, promhttp.Handler()); err != nil {
log.Panicf("error while serving metrics: %s", err)
}
}()

// Wait until some signal is captured.
sigC := make(chan os.Signal, 1)
signal.Notify(sigC, syscall.SIGTERM, syscall.SIGINT)
<-sigC
}
2 changes: 1 addition & 1 deletion examples/gorestful/main.go
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import (
"os/signal"
"syscall"

gorestful "github.com/emicklei/go-restful"
gorestful "github.com/emicklei/go-restful/v3"
"github.com/prometheus/client_golang/prometheus/promhttp"
metrics "github.com/slok/go-http-metrics/metrics/prometheus"
"github.com/slok/go-http-metrics/middleware"
59 changes: 51 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,62 @@
module github.com/slok/go-http-metrics

require (
contrib.go.opencensus.io/exporter/prometheus v0.2.0
github.com/emicklei/go-restful v2.14.2+incompatible
github.com/gin-gonic/gin v1.6.3
contrib.go.opencensus.io/exporter/prometheus v0.4.0
github.com/emicklei/go-restful/v3 v3.7.1
github.com/fasthttp/router v1.4.4
github.com/gin-gonic/gin v1.7.4
github.com/go-chi/chi v4.1.2+incompatible
github.com/gorilla/mux v1.8.0
github.com/julienschmidt/httprouter v1.3.0
github.com/justinas/alice v1.2.0
github.com/labstack/echo/v4 v4.1.17
github.com/prometheus/client_golang v1.7.1
github.com/stretchr/testify v1.6.1
github.com/labstack/echo/v4 v4.6.1
github.com/prometheus/client_golang v1.11.0
github.com/stretchr/testify v1.7.0
github.com/urfave/negroni v1.0.0
go.opencensus.io v0.22.4
github.com/valyala/fasthttp v1.31.0
go.opencensus.io v0.23.0
goji.io v2.0.2+incompatible
)

go 1.15
require (
github.com/andybalholm/brotli v1.0.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-kit/log v0.1.0 // indirect
github.com/go-logfmt/logfmt v0.5.0 // indirect
github.com/go-playground/locales v0.13.0 // indirect
github.com/go-playground/universal-translator v0.17.0 // indirect
github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.4.3 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/klauspost/compress v1.13.4 // indirect
github.com/labstack/gommon v0.3.0 // indirect
github.com/leodido/go-urn v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.28.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/prometheus/statsd_exporter v0.21.0 // indirect
github.com/savsgio/gotils v0.0.0-20210921075833-21a6215cb0e4 // indirect
github.com/stretchr/objx v0.1.1 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.1 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/net v0.0.0-20210913180222-943fd674d43e // indirect
golang.org/x/sys v0.0.0-20210910150752-751e447fb3d0 // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.26.0-rc.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)

go 1.17
Loading