Skip to content

Commit

Permalink
feat: fix metrics readme
Browse files Browse the repository at this point in the history
  • Loading branch information
franklinkim committed Sep 11, 2023
1 parent 7537cbc commit 03bc5bc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 229 deletions.
26 changes: 9 additions & 17 deletions metrics/readme.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,23 @@ package metrics

import (
"github.com/foomo/keel/markdown"
"github.com/foomo/keel/telemetry/nonrecording"
"github.com/prometheus/client_golang/prometheus"
)

func Readme() string {
md := markdown.Markdown{}
values := nonrecording.Metrics()
var rows [][]string

gatherer, _ := prometheus.DefaultRegisterer.(*prometheus.Registry).Gather()
for _, value := range gatherer {
values = append(values, nonrecording.Metric{
Name: value.GetName(),
Type: value.GetType().String(),
Help: value.GetHelp(),
})
if gatherer, err := prometheus.DefaultGatherer.Gather(); err == nil {
for _, value := range gatherer {
rows = append(rows, []string{
value.GetName(),
value.GetType().String(),
value.GetHelp(),
})
}
}

rows := make([][]string, 0, len(values))
for _, value := range values {
rows = append(rows, []string{
markdown.Code(value.Name),
value.Type,
value.Help,
})
}
if len(rows) > 0 {
md.Println("### Metrics")
md.Println("")
Expand Down
18 changes: 18 additions & 0 deletions service/httpreadme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
"github.com/foomo/keel/config"
"github.com/foomo/keel/env"
"github.com/foomo/keel/service"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"go.opentelemetry.io/otel/metric/instrument"
"go.uber.org/zap"
)

Expand All @@ -21,6 +24,7 @@ func ExampleNewHTTPReadme() {

svr := keel.NewServer(
keel.WithLogger(zap.NewNop()),
keel.WithPrometheusMeter(true),
keel.WithHTTPReadmeService(true),
)

Expand All @@ -40,6 +44,18 @@ func ExampleNewHTTPReadme() {
_ = config.MustGetBool(c, "example.required.bool")
_ = config.MustGetString(c, "example.required.string")

m := svr.Meter()

// add metrics
fooBarCounter := promauto.NewCounter(prometheus.CounterOpts{
Name: "foo_bar_total",
Help: "Foo bar metrics",
})
fooBazCounter, _ := m.SyncInt64().Counter("foo_baz_total", instrument.WithDescription("Foo baz metrics"))

fooBarCounter.Add(1)
fooBazCounter.Add(svr.Context(), 1)

// add http service
svr.AddService(service.NewHTTP(l, "demp-http", "localhost:8080", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
Expand Down Expand Up @@ -136,6 +152,8 @@ func ExampleNewHTTPReadme() {
//
// | Name | Type | Description |
// | ---------------------------------- | ------- | ------------------------------------------------------------------ |
// | foo_bar_total | COUNTER | Foo bar metrics |
// | foo_baz_total | COUNTER | Foo baz metrics |
// | `go_gc_duration_seconds` | SUMMARY | A summary of the pause duration of garbage collection cycles. |
// | `go_goroutines` | GAUGE | Number of goroutines that currently exist. |
// | `go_info` | GAUGE | Information about the Go environment. |
Expand Down
162 changes: 0 additions & 162 deletions telemetry/nonrecording/instruments.go

This file was deleted.

50 changes: 0 additions & 50 deletions telemetry/nonrecording/meter.go

This file was deleted.

0 comments on commit 03bc5bc

Please sign in to comment.