-
Notifications
You must be signed in to change notification settings - Fork 634
Add AgentgatewayPolicy frontend tracing support #13226
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
lgadban
merged 9 commits into
kgateway-dev:main
from
npolshakova:xds-tracing-api-changes
Jan 7, 2026
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2c0e2f9
xds tracing
npolshakova 354a217
bump
npolshakova b77f3b1
bump
npolshakova 31e558f
test grpc and http
npolshakova c6460e5
working e2e
npolshakova cd5bd31
rm e2e tests
npolshakova 0c1f30f
bump agw
npolshakova 50eff00
cleanup
npolshakova 29840aa
revert e2e tracing changes
lgadban 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
Some comments aren't visible on the classic Files Changed page.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import ( | |
|
|
||
| "github.com/kgateway-dev/kgateway/v2/api/v1alpha1/agentgateway" | ||
| "github.com/kgateway-dev/kgateway/v2/pkg/kgateway/wellknown" | ||
| "github.com/kgateway-dev/kgateway/v2/pkg/utils/kubeutils" | ||
| ) | ||
|
|
||
| const ( | ||
|
|
@@ -63,18 +64,95 @@ func translateFrontendPolicyToAgw( | |
|
|
||
| func translateFrontendTracing(policy *agentgateway.AgentgatewayPolicy, name string, target *api.PolicyTarget) []AgwPolicy { | ||
| tracing := policy.Spec.Frontend.Tracing | ||
| if tracing == nil { | ||
| return nil | ||
| } | ||
|
|
||
| var provider *api.BackendReference | ||
| ref := tracing.BackendRef | ||
| if ref.Kind == nil || *ref.Kind == "Service" { | ||
| ns := policy.GetNamespace() | ||
| if tracing.BackendRef.Namespace != nil { | ||
| ns = string(*tracing.BackendRef.Namespace) | ||
| } | ||
| var port uint32 | ||
| if ref.Port != nil { | ||
| port = uint32(*ref.Port) | ||
| } | ||
| hostname := kubeutils.GetServiceHostname(string(ref.Name), ns) | ||
| provider = &api.BackendReference{ | ||
| Kind: &api.BackendReference_Service_{ | ||
| Service: &api.BackendReference_Service{ | ||
| Namespace: ns, | ||
| Hostname: hostname, | ||
| }, | ||
| }, | ||
| Port: port, | ||
| } | ||
| } else { | ||
| // TODO: support other backend ref kinds | ||
| logger.Error("Backend reference kind is not supported", "kind", string(*ref.Kind)) | ||
| } | ||
|
|
||
npolshakova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var addAttributes []*api.FrontendPolicySpec_TracingAttribute | ||
| var rmAttributes []string | ||
| if tracing.Attributes != nil { | ||
| for _, add := range tracing.Attributes.Add { | ||
| addAttributes = append(addAttributes, &api.FrontendPolicySpec_TracingAttribute{ | ||
| Name: add.Name, | ||
| Value: string(add.Expression), | ||
| }) | ||
| } | ||
| for _, rm := range tracing.Attributes.Remove { | ||
| rmAttributes = append(rmAttributes, rm) | ||
| } | ||
| } | ||
|
|
||
| var addResources []*api.FrontendPolicySpec_TracingAttribute | ||
| if tracing.Resources != nil { | ||
| for _, add := range tracing.Resources { | ||
| addResources = append(addResources, &api.FrontendPolicySpec_TracingAttribute{ | ||
| Name: add.Name, | ||
| Value: string(add.Expression), | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| var randomSampling *string | ||
| if tracing.RandomSampling != nil { | ||
| randomSampling = ptr.Of(string(*tracing.RandomSampling)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. castPtr helps hgere |
||
| } | ||
|
|
||
| var clientSampling *string | ||
| if tracing.ClientSampling != nil { | ||
| clientSampling = ptr.Of(string(*tracing.ClientSampling)) | ||
| } | ||
|
|
||
| protocol := api.FrontendPolicySpec_Tracing_HTTP | ||
| if tracing.Protocol == agentgateway.TracingProtocolHttp { | ||
| protocol = api.FrontendPolicySpec_Tracing_HTTP | ||
| } else if tracing.Protocol == agentgateway.TracingProtocolGrpc { | ||
| protocol = api.FrontendPolicySpec_Tracing_GRPC | ||
npolshakova marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| tracingPolicy := &api.Policy{ | ||
| Key: name + frontendTracingPolicySuffix + attachmentName(target), | ||
| Name: TypedResourceName(wellknown.AgentgatewayPolicyGVK.Kind, policy), | ||
| Target: target, | ||
| Kind: &api.Policy_Frontend{ | ||
| Frontend: &api.FrontendPolicySpec{ | ||
| // TODO: implement this | ||
| Kind: &api.FrontendPolicySpec_Tracing_{Tracing: &api.FrontendPolicySpec_Tracing{}}, | ||
| Kind: &api.FrontendPolicySpec_Tracing_{Tracing: &api.FrontendPolicySpec_Tracing{ | ||
| ProviderBackend: provider, | ||
| Attributes: addAttributes, | ||
| Remove: rmAttributes, | ||
| Resources: addResources, | ||
| Protocol: protocol, | ||
| RandomSampling: randomSampling, | ||
| ClientSampling: clientSampling, | ||
| }}, | ||
| }, | ||
| }, | ||
| } | ||
| _ = tracing | ||
|
|
||
| logger.Debug("generated tracing policy", | ||
| "policy", policy.Name, | ||
|
|
||
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
Oops, something went wrong.
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.