-
Notifications
You must be signed in to change notification settings - Fork 4.6k
stats/opentelemetry: Add CSM Observability API #7277
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 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 hidden or 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,95 @@ | ||
| /* | ||
| * | ||
| * Copyright 2024 gRPC authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package csm | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/url" | ||
|
|
||
| "google.golang.org/grpc" | ||
| "google.golang.org/grpc/internal" | ||
| "google.golang.org/grpc/stats/opentelemetry" | ||
| otelinternal "google.golang.org/grpc/stats/opentelemetry/internal" | ||
| ) | ||
|
|
||
| var clientSideOTelWithCSM grpc.DialOption | ||
| var clientSideOTel grpc.DialOption | ||
|
|
||
| // Observability sets up CSM Observability for the binary globally. It sets up | ||
| // two client side OpenTelemetry instrumentation components configured with the | ||
| // provided options, one with a CSM Plugin Option configured, one without. | ||
| // Created channels will pick up one of these dependent on whether channels are | ||
| // CSM Channels or not, which is derived from the Channel's parsed target after | ||
| // dialing. | ||
| // | ||
| // It sets up a server side OpenTelemetry instrumentation component configured | ||
| // with options provided alongside a CSM Plugin Option to be registered globally | ||
| // and picked up for every server. | ||
| // | ||
| // The CSM Plugin Option is instantiated with local labels and metadata exchange | ||
|
||
| // labels pulled from the environment, and emits metadata exchange labels from | ||
| // the peer and local labels. Context timeouts do not trigger an error, but set | ||
| // certain labels to "unknown". | ||
| // | ||
| // This function is not thread safe, and should only be invoked once in main | ||
| // before any channels or servers are created. Returns a cleanup function to be | ||
| // deferred in main. | ||
dfawley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| func Observability(ctx context.Context, options opentelemetry.Options) func() { | ||
dfawley marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
dfawley marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| csmPluginOption := newPluginOption(ctx) | ||
| clientSideOTelWithCSM = dialOptionWithCSMPluginOption(options, csmPluginOption) | ||
| clientSideOTel = opentelemetry.DialOption(options) | ||
|
|
||
| serverSideOTelWithCSM := serverOptionWithCSMPluginOption(options, csmPluginOption) | ||
|
|
||
| internal.AddGlobalPerTargetDialOptions.(func(opt any))(perTargetDialOption{}) | ||
|
|
||
| internal.AddGlobalServerOptions.(func(opt ...grpc.ServerOption))(serverSideOTelWithCSM) | ||
dfawley marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return func() { | ||
| internal.ClearGlobalServerOptions() | ||
| internal.ClearGlobalPerTargetDialOptions() | ||
| } | ||
| } // fail, can run it locally and on cloudtop, replace to point to this stats/opentelemetry (replace grpc or something else)? | ||
dfawley marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // make it's own go mod | ||
| // go get a random version using hash | ||
| // then replace | ||
| // try and build docker image using that docker run thing, this is the hook into interop scripts... | ||
|
|
||
| // replace grpc module and otel module I guess | ||
|
|
||
| type perTargetDialOption struct {} | ||
|
|
||
| func (perTargetDialOption) DialOptionForTarget(parsedTarget url.URL) grpc.DialOption { | ||
| if determineTargetCSM(&parsedTarget) { | ||
| return clientSideOTelWithCSM | ||
| } | ||
| return clientSideOTel | ||
dfawley marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| func dialOptionWithCSMPluginOption(options opentelemetry.Options, po otelinternal.PluginOption) grpc.DialOption { | ||
| options.MetricsOptions.OptionalLabels = []string{"csm.service_name", "csm.service_namespace_name"} // Attach the two xDS Optional Labels for this component to not filter out. | ||
| otelinternal.SetPluginOption.(func(options *opentelemetry.Options, po otelinternal.PluginOption))(&options, po) | ||
| return opentelemetry.DialOption(options) | ||
| } | ||
|
|
||
| func serverOptionWithCSMPluginOption(options opentelemetry.Options, po otelinternal.PluginOption) grpc.ServerOption { | ||
| otelinternal.SetPluginOption.(func(options *opentelemetry.Options, po otelinternal.PluginOption))(&options, po) | ||
| return opentelemetry.ServerOption(options) | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.