forked from iimos/saramaprom
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from wandera/migration
- Loading branch information
Showing
11 changed files
with
304 additions
and
342 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
run: | ||
timeout: 5m | ||
modules-download-mode: readonly | ||
linters: | ||
disable-all: true | ||
enable: | ||
- gosimple | ||
- govet | ||
- ineffassign | ||
- staticcheck | ||
- typecheck | ||
- unused | ||
- gofmt | ||
- revive | ||
- gci | ||
- gofumpt | ||
- whitespace | ||
- godot | ||
- unparam | ||
- gocritic | ||
- gosec | ||
|
||
issues: | ||
include: | ||
- EXC0012 # disable excluding of issues about comments from revive | ||
exclude-rules: | ||
- path: _test\.go | ||
linters: | ||
- gosec | ||
|
||
linters-settings: | ||
godot: | ||
# list of regexps for excluding particular comment lines from check | ||
exclude: | ||
- '^ @.*' # swaggo comments like // @title | ||
- '^ (\d+)(\.|\)).*' # enumeration comments like // 1. or // 1) | ||
gosec: | ||
global: | ||
audit: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export GOPROXY := go-proxy.oss.wandera.net | ||
export GONOSUMDB := github.com/wandera/* | ||
|
||
all: check test | ||
|
||
MAKEFLAGS += --no-print-directory | ||
|
||
prepare: | ||
@echo "Downloading tools" | ||
@cat tools.go | grep _ | cut -f2 -d " " | xargs -tI % sh -c "go install %" | ||
|
||
check: prepare | ||
@echo "Running check" | ||
ifeq (, $(shell which golangci-lint)) | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GOPATH)/bin v1.52.2 | ||
endif | ||
golangci-lint run | ||
go mod tidy | ||
|
||
test: prepare | ||
@echo "Running tests" | ||
mkdir -p report | ||
go test -race -v ./... -coverprofile=report/coverage.txt | tee report/report.txt | ||
go-junit-report -set-exit-code < report/report.txt > report/report.xml | ||
gocov convert report/coverage.txt | gocov-xml > report/coverage.xml | ||
go mod tidy | ||
|
||
clean: | ||
@echo "Running clean" | ||
rm -rf "report/" | ||
|
||
.PHONY: all check test prepare |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,7 @@ | ||
# saramaprom | ||
[![GoDoc](https://godoc.org/github.com/iimos/saramaprom?status.png)](http://godoc.org/github.com/iimos/saramaprom) | ||
[![Go Report](https://goreportcard.com/badge/github.com/iimos/saramaprom)](https://goreportcard.com/report/github.com/iimos/saramaprom) | ||
|
||
This is a prometheus metrics reporter for the [sarama](https://github.com/Shopify/sarama) library. | ||
It is based on https://github.com/deathowl/go-metrics-prometheus library. | ||
|
||
## Why | ||
Because `go-metrics-prometheus` is a general solution it reports metrics with no labels so it's hard to use. Thus a sarama specific solution was made, it reports metrics with labels for brokers, topics and consumer/producer instance. | ||
|
||
## Installation | ||
```console | ||
go get github.com/iimos/saramaprom | ||
``` | ||
|
||
## Usage | ||
|
||
```go | ||
import ( | ||
"context" | ||
"github.com/Shopify/sarama" | ||
"github.com/iimos/saramaprom" | ||
) | ||
|
||
ctx := context.Background() | ||
cfg := sarama.NewConfig() | ||
err := saramaprom.ExportMetrics(ctx, cfg.MetricRegistry, saramaprom.Options{}) | ||
``` | ||
|
||
Posible options: | ||
```go | ||
type Options struct { | ||
// PrometheusRegistry is prometheus registry. Default prometheus.DefaultRegisterer. | ||
PrometheusRegistry prometheus.Registerer | ||
|
||
// Namespace and Subsystem form the metric name prefix. | ||
// Default Subsystem is "sarama". | ||
Namespace string | ||
Subsystem string | ||
|
||
// Label specifies value of "label" label. Default "". | ||
Label string | ||
|
||
// FlushInterval specifies interval between updating metrics. Default 1s. | ||
FlushInterval time.Duration | ||
|
||
// OnError is error handler. Default handler panics when error occurred. | ||
OnError func(err error) | ||
|
||
// Debug turns on debug logging. | ||
Debug bool | ||
} | ||
``` | ||
|
||
Metric names by default: | ||
``` | ||
Gauges: | ||
sarama_batch_size | ||
sarama_compression_ratio | ||
sarama_incoming_byte_rate | ||
sarama_outgoing_byte_rate | ||
sarama_record_send_rate | ||
sarama_records_per_request | ||
sarama_request_latency_in_ms | ||
sarama_request_rate | ||
sarama_request_size | ||
sarama_requests_in_flight | ||
sarama_response_rate | ||
sarama_response_size | ||
Histograms: | ||
sarama_batch_size_histogram | ||
sarama_compression_ratio_histogram | ||
sarama_records_per_request_histogram | ||
sarama_request_latency_in_ms_histogram | ||
sarama_request_size_histogram | ||
sarama_response_size_histogram | ||
``` | ||
|
||
Every metric have three labels: | ||
* broker – kafka broker id | ||
* topic – kafka topic name | ||
* label – custom label to distinguish different consumers/producers | ||
|
||
|
||
## Requirements | ||
|
||
Go 1.13 or above. | ||
is a library for exporting sarama metrics (provided through [go-metrics](https://github.com/rcrowley/go-metrics)) to Prometheus. It is | ||
a fork of [saramaprom](https://github.com/iimos/saramaprom/tree/ab69b9d3b9e65611e5377c2fd40882124e491f50) with few fixes | ||
and tweaks: | ||
* go-metrics histograms are registered as Prometheus summaries (to better present client side quantiles) | ||
* removed histogram and timer words from metric names | ||
* removed configuration of optional labels from saramaprom (we never configure it and it was creating additional unnecessary dimension to metrics due to bad implementation) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,29 @@ | ||
module github.com/iimos/saramaprom | ||
module github.com/wandera/saramaprom | ||
|
||
go 1.13 | ||
go 1.19 | ||
|
||
require ( | ||
github.com/prometheus/client_golang v1.7.1 | ||
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 | ||
github.com/stretchr/testify v1.4.0 | ||
github.com/AlekSi/gocov-xml v1.1.0 | ||
github.com/axw/gocov v1.1.0 | ||
github.com/jstemmer/go-junit-report v1.0.0 | ||
github.com/prometheus/client_golang v1.14.0 | ||
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 | ||
github.com/stretchr/testify v1.8.0 | ||
) | ||
|
||
require ( | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.2.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/kr/pretty v0.3.1 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/prometheus/client_model v0.3.0 // indirect | ||
github.com/prometheus/common v0.42.0 // indirect | ||
github.com/prometheus/procfs v0.9.0 // indirect | ||
golang.org/x/sys v0.6.0 // indirect | ||
golang.org/x/tools v0.0.0-20190617190820-da514acc4774 // indirect | ||
google.golang.org/protobuf v1.30.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.