Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions api/v1alpha1/agentgateway/agentgateway_policy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ type BackendTLS struct {
AlpnProtocols *[]TinyString `json:"alpnProtocols,omitempty"`
}

// +kubebuilder:validation:XValidation:rule="!has(self.tracing)",message="tracing is not currently implemented"
type Frontend struct {
// tcp defines settings on managing incoming TCP connections.
// +optional
Expand All @@ -268,7 +267,6 @@ type Frontend struct {
AccessLog *AccessLog `json:"accessLog,omitempty"`

// Tracing contains various settings for OpenTelemetry tracer.
// TODO: not currently implemented
// +optional
Tracing *Tracing `json:"tracing,omitempty"`
}
Expand Down Expand Up @@ -1269,10 +1267,14 @@ type Tracing struct {
// +optional
Protocol TracingProtocol `json:"protocol,omitempty"`

// attributes specifies customizations to the key-value pairs that are included in the trace
// attributes specify customizations to the key-value pairs that are included in the trace.
// +optional
Attributes *LogTracingAttributes `json:"attributes,omitempty"`

// resources describe the entity producing telemetry and specify the resources to be included in the trace.
// +optional
Resources []ResourceAdd `json:"resources,omitempty"`

// randomSampling is an expression to determine the amount of random sampling. Random sampling will initiate a new
// trace span if the incoming request does not have a trace initiated already. This should evaluate to a float between
// 0.0-1.0, or a boolean (true/false) If unspecified, random sampling is disabled.
Expand All @@ -1284,3 +1286,10 @@ type Tracing struct {
// +optional
ClientSampling *shared.CELExpression `json:"clientSampling,omitempty"`
}

type ResourceAdd struct {
// +required
Name ShortString `json:"name"`
// +required
Expression shared.CELExpression `json:"expression"`
}
22 changes: 22 additions & 0 deletions api/v1alpha1/agentgateway/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,6 @@ tool (
sigs.k8s.io/controller-tools/cmd/controller-gen
sigs.k8s.io/kind
)

// TODO: remove and bump agw
replace github.com/agentgateway/agentgateway => ../agentgateway
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ github.com/OpenPeeDeeP/depguard/v2 v2.2.1 h1:vckeWVESWp6Qog7UZSARNqfu/cZqvki8zsu
github.com/OpenPeeDeeP/depguard/v2 v2.2.1/go.mod h1:q4DKzC4UcVaAvcfd41CZh0PWpGgzrVxUYBlgKNGquUo=
github.com/PuerkitoBio/goquery v1.10.1 h1:Y8JGYUkXWTGRB6Ars3+j3kN0xg1YqqlwvdTV8WTFQcU=
github.com/PuerkitoBio/goquery v1.10.1/go.mod h1:IYiHrOMps66ag56LEH7QYDDupKXyo5A8qrjIx3ZtujY=
github.com/agentgateway/agentgateway v0.11.0 h1:+0SDC/YTRJFUtkfFGe3zvxydIEJHGrwVL6pQEThy+yc=
github.com/agentgateway/agentgateway v0.11.0/go.mod h1:/Lzpteag/nnE4bwW/3Dh5GaxuICmCQs40VhQpkTatlk=
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
github.com/alecholmes/xfccparser v0.4.0 h1:IFB4bP34oorjcV3n8utZtBhEwlAw9rZ43pb4LgT23Vo=
github.com/alecholmes/xfccparser v0.4.0/go.mod h1:J9fzzUOtjw74IwNdGVbjnOVj1UDlwGQj1zZzgQRlRDY=
Expand Down
2 changes: 1 addition & 1 deletion hack/utils/oss_compliance/osa_provided.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Name|Version|License
[cel.dev/expr](https://cel.dev/expr)|v0.25.1|Apache License 2.0
[semver/v3](https://github.com/Masterminds/semver)|v3.4.0|MIT License
[PuerkitoBio/goquery](https://github.com/PuerkitoBio/goquery)|v1.10.1|BSD 3-clause "New" or "Revised" License
[agentgateway/agentgateway](https://github.com/agentgateway/agentgateway)|v0.11.0|Apache License 2.0
[agentgateway/agentgateway](https://github.com/agentgateway/agentgateway)|latest|Apache License 2.0
[anthropics/anthropic-sdk-go](https://github.com/anthropics/anthropic-sdk-go)|v1.13.0|MIT License
[retry-go/v4](https://github.com/avast/retry-go)|v4.7.0|MIT License
[xds/go](https://github.com/cncf/xds)|v0.0.0-20251110193048-8bfbf64dc13e|Apache License 2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1707,8 +1707,8 @@ spec:
tracer.
properties:
attributes:
description: attributes specifies customizations to the key-value
pairs that are included in the trace
description: attributes specify customizations to the key-value
pairs that are included in the trace.
properties:
add:
description: |-
Expand Down Expand Up @@ -1844,13 +1844,30 @@ spec:
maxLength: 16384
minLength: 1
type: string
resources:
description: resources describe the entity producing telemetry
and specify the resources to be included in the trace.
items:
properties:
expression:
description: CELExpression represents a Common Expression
Language (CEL) expression.
maxLength: 16384
minLength: 1
type: string
name:
maxLength: 256
minLength: 1
type: string
required:
- expression
- name
type: object
type: array
required:
- backendRef
type: object
type: object
x-kubernetes-validations:
- message: tracing is not currently implemented
rule: '!has(self.tracing)'
targetRefs:
description: targetRefs specifies the target resources by reference
to attach the policy to.
Expand Down
84 changes: 81 additions & 3 deletions pkg/agentgateway/plugins/frontend_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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))
}

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))
Copy link
Contributor

Choose a reason for hiding this comment

The 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
}

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,
Expand Down
58 changes: 45 additions & 13 deletions pkg/agentgateway/plugins/testdata/frontendpolicy/full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,23 @@ spec:
add:
- expression: 'request.headers["user-agent"]'
name: http.useragent
# tracing:
# backendRef:
# name: my-otel
# namespace: some-other-ns
# protocol: GRPC
# clientSampling: "true"
# randomSampling: "true"
# attributes:
# remove:
# - response.code
# add:
# - expression: 'request.headers["user-agent"]'
# name: http.useragent
tracing:
backendRef:
name: my-otel
namespace: some-other-ns
port: 4317
protocol: GRPC
clientSampling: "true"
randomSampling: "true"
resources:
- name: service.name
expression: "agent-gateway"
attributes:
remove:
- response.code
add:
- expression: 'request.headers["user-agent"]'
name: http.useragent

---
# Output
Expand Down Expand Up @@ -111,6 +115,34 @@ output:
gateway:
name: test
namespace: default
- Policy:
frontend:
tracing:
attributes:
- name: http.useragent
value: request.headers["user-agent"]
clientSampling: "true"
protocol: GRPC
providerBackend:
port: 4317
service:
hostname: my-otel.some-other-ns.svc.cluster.local
namespace: some-other-ns
randomSampling: "true"
remove:
- response.code
resources:
- name: service.name
value: agent-gateway
key: frontend/default/agw:frontend-tracing:default/test
name:
kind: AgentgatewayPolicy
name: agw
namespace: default
target:
gateway:
name: test
namespace: default
status:
ancestors:
- ancestorRef:
Expand Down
49 changes: 0 additions & 49 deletions test/e2e/features/tracing/testdata/setup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,53 +62,4 @@ spec:
cpu: "100m"
limits:
cpu: "200m"
---
# Custom GWP to define OTEL_RESOURCE_ATTRIBUTES required for the environment detector
kind: GatewayParameters
apiVersion: gateway.kgateway.dev/v1alpha1
metadata:
name: tracing-params
spec:
kube:
envoyContainer:
env:
- name: OTEL_RESOURCE_ATTRIBUTES
value: "environment=detector,resource=attribute"
---
kind: Gateway
apiVersion: gateway.networking.k8s.io/v1
metadata:
name: gw
spec:
gatewayClassName: kgateway
infrastructure:
parametersRef:
name: tracing-params
group: gateway.kgateway.dev
kind: GatewayParameters
listeners:
- protocol: HTTP
port: 8080
name: http
allowedRoutes:
namespaces:
from: All
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: httpbin
namespace: httpbin
labels:
example: httpbin-route
spec:
parentRefs:
- name: gw
namespace: default
hostnames:
- "www.example.com"
rules:
- backendRefs:
- name: httpbin
port: 8000
---
Loading