generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: otel metrics for ingress (#2310)
``` InstrumentationScope ftl.ingress Metric #0 Descriptor: -> Name: ftl.ingress.requests -> Description: the number of ingress requests that the FTL controller receives -> Unit: 1 -> DataType: Sum -> IsMonotonic: true -> AggregationTemporality: Cumulative NumberDataPoints #0 Data point attributes: -> ftl.ingress.method: Str(GET) -> ftl.ingress.path: Str(/http/echo) -> ftl.ingress.run_time_ms.bucket: Str([16,32)) -> ftl.ingress.verb.ref: Str(echo.getEcho) -> ftl.module.name: Str(echo) StartTimestamp: 2024-08-12 17:44:51.923107 +0000 UTC Timestamp: 2024-08-12 17:45:26.923594 +0000 UTC Value: 1 Metric #1 Descriptor: -> Name: ftl.ingress.ms_to_complete -> Description: duration in ms to complete an ingress request -> Unit: ms -> DataType: Histogram -> AggregationTemporality: Cumulative HistogramDataPoints #0 Data point attributes: -> ftl.ingress.method: Str(GET) -> ftl.ingress.path: Str(/http/echo) -> ftl.ingress.verb.ref: Str(echo.getEcho) -> ftl.module.name: Str(echo) StartTimestamp: 2024-08-12 17:44:51.92311 +0000 UTC Timestamp: 2024-08-12 17:45:26.923622 +0000 UTC Count: 1 Sum: 27.000000 Min: 27.000000 Max: 27.000000 ``` --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
477fa3a
commit 4570d93
Showing
5 changed files
with
106 additions
and
4 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
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
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,76 @@ | ||
package observability | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/alecthomas/types/optional" | ||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/metric" | ||
"go.opentelemetry.io/otel/metric/noop" | ||
|
||
schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema" | ||
"github.com/TBD54566975/ftl/backend/schema" | ||
"github.com/TBD54566975/ftl/internal/observability" | ||
) | ||
|
||
const ( | ||
ingressMeterName = "ftl.ingress" | ||
ingressMethodAttr = "ftl.ingress.method" | ||
ingressPathAttr = "ftl.ingress.path" | ||
ingressVerbRefAttr = "ftl.ingress.verb.ref" | ||
ingressFailureModeAttr = "ftl.ingress.failure_mode" | ||
ingressRunTimeBucketAttr = "ftl.ingress.run_time_ms.bucket" | ||
) | ||
|
||
type IngressMetrics struct { | ||
requests metric.Int64Counter | ||
msToComplete metric.Int64Histogram | ||
} | ||
|
||
func initIngressMetrics() (*IngressMetrics, error) { | ||
result := &IngressMetrics{ | ||
requests: noop.Int64Counter{}, | ||
msToComplete: noop.Int64Histogram{}, | ||
} | ||
|
||
var err error | ||
meter := otel.Meter(ingressMeterName) | ||
|
||
signalName := fmt.Sprintf("%s.requests", ingressMeterName) | ||
if result.requests, err = meter.Int64Counter(signalName, metric.WithUnit("1"), | ||
metric.WithDescription("the number of ingress requests that the FTL controller receives")); err != nil { | ||
return nil, wrapErr(signalName, err) | ||
} | ||
|
||
signalName = fmt.Sprintf("%s.ms_to_complete", ingressMeterName) | ||
if result.msToComplete, err = meter.Int64Histogram(signalName, metric.WithUnit("ms"), | ||
metric.WithDescription("duration in ms to complete an ingress request")); err != nil { | ||
return nil, wrapErr(signalName, err) | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
func (m *IngressMetrics) Request(ctx context.Context, method string, path string, verb optional.Option[*schemapb.Ref], startTime time.Time, failureMode optional.Option[string]) { | ||
attrs := []attribute.KeyValue{ | ||
attribute.String(ingressMethodAttr, method), | ||
attribute.String(ingressPathAttr, path), | ||
} | ||
if v, ok := verb.Get(); ok { | ||
attrs = append(attrs, | ||
attribute.String(observability.ModuleNameAttribute, v.Module), | ||
attribute.String(ingressVerbRefAttr, schema.RefFromProto(v).String())) | ||
} | ||
if f, ok := failureMode.Get(); ok { | ||
attrs = append(attrs, attribute.String(ingressFailureModeAttr, f)) | ||
} | ||
|
||
msToComplete := timeSinceMS(startTime) | ||
m.msToComplete.Record(ctx, msToComplete, metric.WithAttributes(attrs...)) | ||
|
||
attrs = append(attrs, attribute.String(ingressRunTimeBucketAttr, logBucket(2, msToComplete))) | ||
m.requests.Add(ctx, 1, metric.WithAttributes(attrs...)) | ||
} |
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