Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## [Unreleased]

Breaking change. The library has been refactored to be more flexible when adding new framework/libraries.
Breaking change: The library has been refactored to be more flexible when adding new framework/libraries.

### Added

Expand All @@ -14,7 +14,7 @@ Breaking change. The library has been refactored to be more flexible when adding
- Added `Reporter` interface as the service responsible of getting the data to be measured.
- All different framwork helpers now implement with the new Reporter way.
- Fixed Gin returning duplicated data (#31).
- Standard handler now is on `middleware/std` instead of `middleware`.
- (Breaking) Standard handler now is on `middleware/std` instead of `middleware`.

### Removed

Expand Down
63 changes: 1 addition & 62 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func main() {
w.WriteHeader(http.StatusOK)
w.Write([]byte("hello world!"))
})
h = middlewarestd.Measure("", mdlw, h)
h = middlewarestd.Handler("", mdlw, h)

// Serve metrics.
log.Printf("serving metrics at: %s", ":9090")
Expand All @@ -86,67 +86,6 @@ func main() {

For more examples check the [examples]. [default][default-example] and [custom][custom-example] are the examples for Go net/http std library users.

## V1 migration

From `v0` to `v1` the middleware API has changed (not the metrics API or metric implementations).

This changes was because `v0` started with `http.Handler` in mind, but then the support for some libs/middlwares were implemented, the way these frameworks/libraries are designed itself, are not compatible with go's `http.Handler`, but we want to support these and many more. So to be able to support these correctly and many more,an internal big refactor was required, this lead us to the need to leak a little bit of this internal refactor.

Here is how you can migrate the standard `http.Handler` from one to another (the other framework/lib migrations are straignforward).

Before:

```go
package main

import (
metrics "github.com/slok/go-http-metrics/metrics/prometheus"
"github.com/slok/go-http-metrics/middleware"
)

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

myHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("hello world!"))
})

// Measure handler.
h := mdlw.Handler("", myHandler)
}
```

After:

```go
package main

import (
metrics "github.com/slok/go-http-metrics/metrics/prometheus"
"github.com/slok/go-http-metrics/middleware"
middlewarestd "github.com/slok/go-http-metrics/middleware/std"
)

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

myHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
w.Write([]byte("hello world!"))
})

// Measure handler.
h := middlewarestd.Measure("", mdlw, myHandler)
}
```

## Prometheus query examples

Get the request rate by handler:
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ the main Go net/http handler:
w.WriteHeader(http.StatusOK)
w.Write([]byte("hello world!"))
})
h := httpstdmiddleware.Measure("", mdlw, myHandler)
h := httpstdmiddleware.Handler("", mdlw, myHandler)

// Serve metrics.
log.Printf("serving metrics at: %s", ":9090")
Expand Down