generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: otel metrics for ingress #2310
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious if this is too high of a cardinality to log
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depending on what info is contained in the paths, we could potentially chop the path and keep just the top level prefix, or otherwise parse out only the data that we find useful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh huh if the path is just the module name, I guess it doesn't even matter if we do anything special here, because it won't add any cardinality beyond the verb ref. We can just leave this as is - it's probably easiest to understand this way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The path is entirely user defined, i.e.
//ftl:ingress GET /http/echo
->https://<domain:port>/http/echo
But you're right it's equivalent to adding a verb ref, and it's pretty usefull; I'll leave it in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh got it, that makes sense. Sounds good!