diff options
| author | 2025-09-18 16:48:45 +0200 | |
|---|---|---|
| committer | 2025-09-18 16:48:45 +0200 | |
| commit | 82216281cee085771fa86173cdf6af6487e48512 (patch) | |
| tree | 33311c5469783d10e8b25dc006c148f8def8cfeb /vendor/github.com/technologize/otel-go-contrib/otelginmetrics | |
| parent | [feature] add paging support to rss feed endpoint, and support JSON / atom fe... (diff) | |
| download | gotosocial-0.20.0-rc1.tar.xz | |
[chore/docs] Fix Prometheus metric names for Gin, include example Grafana dash, update docs (#4443)v0.20.0-rc1
# Description
> If this is a code change, please include a summary of what you've coded, and link to the issue(s) it closes/implements.
>
> If this is a documentation change, please briefly describe what you've changed and why.
This pull request updates some of our inconsistent metric naming, and adds an example Grafana dashboard using all the most up-to-date metrics names, and updates our docs to describe the latest way of setting up metrics.
Closes https://codeberg.org/superseriousbusiness/gotosocial/issues/4362
Closes https://codeberg.org/superseriousbusiness/gotosocial/issues/4055
## Checklist
Please put an x inside each checkbox to indicate that you've read and followed it: `[ ]` -> `[x]`
If this is a documentation change, only the first checkbox must be filled (you can delete the others if you want).
- [x] I/we have read the [GoToSocial contribution guidelines](https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/CONTRIBUTING.md).
- [x] I/we have discussed the proposed changes already, either in an issue on the repository, or in the Matrix chat.
- [x] I/we have not leveraged AI to create the proposed changes.
- [x] I/we have performed a self-review of added code.
- [x] I/we have written code that is legible and maintainable by others.
- [x] I/we have commented the added code, particularly in hard-to-understand areas.
- [x] I/we have made any necessary changes to documentation.
- [ ] I/we have added tests that cover new code.
- [x] I/we have run tests and they pass locally with the changes.
- [x] I/we have run `go fmt ./...` and `golangci-lint run`.
Co-authored-by: kim <grufwub@gmail.com>
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4443
Reviewed-by: kim <gruf@noreply.codeberg.org>
Co-authored-by: tobi <tobi.smethurst@protonmail.com>
Co-committed-by: tobi <tobi.smethurst@protonmail.com>
Diffstat (limited to 'vendor/github.com/technologize/otel-go-contrib/otelginmetrics')
6 files changed, 0 insertions, 319 deletions
diff --git a/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/config.go b/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/config.go deleted file mode 100644 index f33fe38ed..000000000 --- a/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/config.go +++ /dev/null @@ -1,45 +0,0 @@ -package otelginmetrics - -import ( - "net/http" - - "go.opentelemetry.io/otel/attribute" - semconv "go.opentelemetry.io/otel/semconv/v1.7.0" -) - -type config struct { - recordInFlight bool - recordSize bool - recordDuration bool - groupedStatus bool - recorder Recorder - attributes func(serverName, route string, request *http.Request) []attribute.KeyValue - shouldRecord func(serverName, route string, request *http.Request) bool -} - -func defaultConfig() *config { - return &config{ - recordInFlight: true, - recordDuration: true, - recordSize: true, - groupedStatus: true, - attributes: DefaultAttributes, - shouldRecord: func(_, _ string, _ *http.Request) bool { - return true - }, - } -} - -var DefaultAttributes = func(serverName, route string, request *http.Request) []attribute.KeyValue { - attrs := []attribute.KeyValue{ - semconv.HTTPMethodKey.String(request.Method), - } - - if serverName != "" { - attrs = append(attrs, semconv.HTTPServerNameKey.String(serverName)) - } - if route != "" { - attrs = append(attrs, semconv.HTTPRouteKey.String(route)) - } - return attrs -} diff --git a/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/middleware.go b/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/middleware.go deleted file mode 100644 index 85479c7f1..000000000 --- a/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/middleware.go +++ /dev/null @@ -1,94 +0,0 @@ -package otelginmetrics - -import ( - "net/http" - "time" - - "github.com/gin-gonic/gin" - semconv "go.opentelemetry.io/otel/semconv/v1.7.0" -) - -// Middleware returns middleware that will trace incoming requests. -// The service parameter should describe the name of the (virtual) -// server handling the request. -func Middleware(service string, options ...Option) gin.HandlerFunc { - cfg := defaultConfig() - for _, option := range options { - option.apply(cfg) - } - recorder := cfg.recorder - if recorder == nil { - recorder = GetRecorder("") - } - return func(ginCtx *gin.Context) { - - ctx := ginCtx.Request.Context() - - route := ginCtx.FullPath() - if len(route) <= 0 { - route = "nonconfigured" - } - if !cfg.shouldRecord(service, route, ginCtx.Request) { - ginCtx.Next() - return - } - - start := time.Now() - reqAttributes := cfg.attributes(service, route, ginCtx.Request) - - if cfg.recordInFlight { - recorder.AddInflightRequests(ctx, 1, reqAttributes) - defer recorder.AddInflightRequests(ctx, -1, reqAttributes) - } - - defer func() { - - resAttributes := append(reqAttributes[0:0], reqAttributes...) - - if cfg.groupedStatus { - code := int(ginCtx.Writer.Status()/100) * 100 - resAttributes = append(resAttributes, semconv.HTTPStatusCodeKey.Int(code)) - } else { - resAttributes = append(resAttributes, semconv.HTTPAttributesFromHTTPStatusCode(ginCtx.Writer.Status())...) - } - - recorder.AddRequests(ctx, 1, resAttributes) - - if cfg.recordSize { - requestSize := computeApproximateRequestSize(ginCtx.Request) - recorder.ObserveHTTPRequestSize(ctx, requestSize, resAttributes) - recorder.ObserveHTTPResponseSize(ctx, int64(ginCtx.Writer.Size()), resAttributes) - } - - if cfg.recordDuration { - recorder.ObserveHTTPRequestDuration(ctx, time.Since(start), resAttributes) - } - }() - - ginCtx.Next() - } -} - -func computeApproximateRequestSize(r *http.Request) int64 { - s := 0 - if r.URL != nil { - s = len(r.URL.Path) - } - - s += len(r.Method) - s += len(r.Proto) - for name, values := range r.Header { - s += len(name) - for _, value := range values { - s += len(value) - } - } - s += len(r.Host) - - // N.B. r.Form and r.MultipartForm are assumed to be included in r.URL. - - if r.ContentLength != -1 { - s += int(r.ContentLength) - } - return int64(s) -} diff --git a/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/option.go b/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/option.go deleted file mode 100644 index 144ef9378..000000000 --- a/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/option.go +++ /dev/null @@ -1,74 +0,0 @@ -package otelginmetrics - -import ( - "net/http" - - "go.opentelemetry.io/otel/attribute" -) - -// Option applies a configuration to the given config -type Option interface { - apply(cfg *config) -} - -type optionFunc func(cfg *config) - -func (fn optionFunc) apply(cfg *config) { - fn(cfg) -} - -// WithAttributes sets a func using which what attributes to be recorded can be specified. -// By default the DefaultAttributes is used -func WithAttributes(attributes func(serverName, route string, request *http.Request) []attribute.KeyValue) Option { - return optionFunc(func(cfg *config) { - cfg.attributes = attributes - }) -} - -// WithRecordInFlight determines whether to record In Flight Requests or not -// By default the recordInFlight is true -func WithRecordInFlightDisabled() Option { - return optionFunc(func(cfg *config) { - cfg.recordInFlight = false - }) -} - -// WithRecordDuration determines whether to record Duration of Requests or not -// By default the recordDuration is true -func WithRecordDurationDisabled() Option { - return optionFunc(func(cfg *config) { - cfg.recordDuration = false - }) -} - -// WithRecordSize determines whether to record Size of Requests and Responses or not -// By default the recordSize is true -func WithRecordSizeDisabled() Option { - return optionFunc(func(cfg *config) { - cfg.recordSize = false - }) -} - -// WithGroupedStatus determines whether to group the response status codes or not. If true 2xx, 3xx will be stored -// By default the groupedStatus is true -func WithGroupedStatusDisabled() Option { - return optionFunc(func(cfg *config) { - cfg.groupedStatus = false - }) -} - -// WithRecorder sets a recorder for recording requests -// By default the open telemetry recorder is used -func WithRecorder(recorder Recorder) Option { - return optionFunc(func(cfg *config) { - cfg.recorder = recorder - }) -} - -// WithShouldRecordFunc sets a func using which whether a record should be recorded -// By default the all api calls are recorded -func WithShouldRecordFunc(shouldRecord func(serverName, route string, request *http.Request) bool) Option { - return optionFunc(func(cfg *config) { - cfg.shouldRecord = shouldRecord - }) -} diff --git a/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/otelrecorder.go b/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/otelrecorder.go deleted file mode 100644 index efdc96ffd..000000000 --- a/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/otelrecorder.go +++ /dev/null @@ -1,70 +0,0 @@ -package otelginmetrics - -import ( - "context" - "time" - - "go.opentelemetry.io/otel" - "go.opentelemetry.io/otel/attribute" - "go.opentelemetry.io/otel/metric" -) - -const instrumentationName = "github.com/technologize/otel-go-contrib/otelginmetrics" - -// Recorder knows how to record and measure the metrics. This -// has the required methods to be used with the HTTP -// middlewares. -type otelRecorder struct { - attemptsCounter metric.Int64UpDownCounter - totalDuration metric.Int64Histogram - activeRequestsCounter metric.Int64UpDownCounter - requestSize metric.Int64Histogram - responseSize metric.Int64Histogram -} - -func GetRecorder(metricsPrefix string) Recorder { - metricName := func(metricName string) string { - if len(metricsPrefix) > 0 { - return metricsPrefix + "." + metricName - } - return metricName - } - meter := otel.Meter(instrumentationName, metric.WithInstrumentationVersion(SemVersion())) - attemptsCounter, _ := meter.Int64UpDownCounter(metricName("http.server.request_count"), metric.WithDescription("Number of Requests"), metric.WithUnit("Count")) - totalDuration, _ := meter.Int64Histogram(metricName("http.server.duration"), metric.WithDescription("Time Taken by request"), metric.WithUnit("Milliseconds")) - activeRequestsCounter, _ := meter.Int64UpDownCounter(metricName("http.server.active_requests"), metric.WithDescription("Number of requests inflight"), metric.WithUnit("Count")) - requestSize, _ := meter.Int64Histogram(metricName("http.server.request_content_length"), metric.WithDescription("Request Size"), metric.WithUnit("Bytes")) - responseSize, _ := meter.Int64Histogram(metricName("http.server.response_content_length"), metric.WithDescription("Response Size"), metric.WithUnit("Bytes")) - return &otelRecorder{ - attemptsCounter: attemptsCounter, - totalDuration: totalDuration, - activeRequestsCounter: activeRequestsCounter, - requestSize: requestSize, - responseSize: responseSize, - } -} - -// AddRequests increments the number of requests being processed. -func (r *otelRecorder) AddRequests(ctx context.Context, quantity int64, attributes []attribute.KeyValue) { - r.attemptsCounter.Add(ctx, quantity, metric.WithAttributes(attributes...)) -} - -// ObserveHTTPRequestDuration measures the duration of an HTTP request. -func (r *otelRecorder) ObserveHTTPRequestDuration(ctx context.Context, duration time.Duration, attributes []attribute.KeyValue) { - r.totalDuration.Record(ctx, int64(duration/time.Millisecond), metric.WithAttributes(attributes...)) -} - -// ObserveHTTPRequestSize measures the size of an HTTP request in bytes. -func (r *otelRecorder) ObserveHTTPRequestSize(ctx context.Context, sizeBytes int64, attributes []attribute.KeyValue) { - r.requestSize.Record(ctx, sizeBytes, metric.WithAttributes(attributes...)) -} - -// ObserveHTTPResponseSize measures the size of an HTTP response in bytes. -func (r *otelRecorder) ObserveHTTPResponseSize(ctx context.Context, sizeBytes int64, attributes []attribute.KeyValue) { - r.responseSize.Record(ctx, sizeBytes, metric.WithAttributes(attributes...)) -} - -// AddInflightRequests increments and decrements the number of inflight request being processed. -func (r *otelRecorder) AddInflightRequests(ctx context.Context, quantity int64, attributes []attribute.KeyValue) { - r.activeRequestsCounter.Add(ctx, quantity, metric.WithAttributes(attributes...)) -} diff --git a/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/recorder.go b/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/recorder.go deleted file mode 100644 index 7fadeff38..000000000 --- a/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/recorder.go +++ /dev/null @@ -1,25 +0,0 @@ -package otelginmetrics - -import ( - "context" - "time" - - "go.opentelemetry.io/otel/attribute" -) - -type Recorder interface { - // AddRequests increments the number of requests being processed. - AddRequests(ctx context.Context, quantity int64, attributes []attribute.KeyValue) - - // ObserveHTTPRequestDuration measures the duration of an HTTP request. - ObserveHTTPRequestDuration(ctx context.Context, duration time.Duration, attributes []attribute.KeyValue) - - // ObserveHTTPRequestSize measures the size of an HTTP request in bytes. - ObserveHTTPRequestSize(ctx context.Context, sizeBytes int64, attributes []attribute.KeyValue) - - // ObserveHTTPResponseSize measures the size of an HTTP response in bytes. - ObserveHTTPResponseSize(ctx context.Context, sizeBytes int64, attributes []attribute.KeyValue) - - // AddInflightRequests increments and decrements the number of inflight request being processed. - AddInflightRequests(ctx context.Context, quantity int64, attributes []attribute.KeyValue) -} diff --git a/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/version.go b/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/version.go deleted file mode 100644 index 323e1a4c1..000000000 --- a/vendor/github.com/technologize/otel-go-contrib/otelginmetrics/version.go +++ /dev/null @@ -1,11 +0,0 @@ -package otelginmetrics - -// Version is the current release version of the gin instrumentation. -func Version() string { - return "1.0.0" -} - -// SemVersion is the semantic version to be supplied to tracer/meter creation. -func SemVersion() string { - return "semver:" + Version() -} |
