Skip to content

samplingFraction not working #8282

Closed

Description

@fe-ax

Description:
Traces are not being sent out when using 100:100 samplingFraction, but are when using 100% samplingRate. Neither working when setting 50:100.

Repro steps:
Set EnvoyProxy object to nominator 100 and denominator 100:

YAML config of EnvoyProxy
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
  labels:
    argocd.argoproj.io/instance: envoy-gateway
  name: private
  namespace: envoy-gateway
spec:
  logging:
    level:
      default: info
  provider:
    kubernetes:
      envoyDeployment:
        container:
          image: ...envoyproxy/envoy:v1.34.2
          resources:
            limits:
              cpu: 500m
              memory: 200Mi
            requests:
              cpu: 500m
              memory: 200Mi
        name: envoy-private
        pod:
          affinity:
            podAntiAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                - labelSelector:
                    matchLabels:
                      app.kubernetes.io/instance: envoy-private
                  topologyKey: kubernetes.io/hostname
          labels:
            app.kubernetes.io/instance: envoy-private
          topologySpreadConstraints:
            - labelSelector:
                matchLabels:
                  app.kubernetes.io/instance: envoy-private
              maxSkew: 1
              topologyKey: topology.kubernetes.io/zone
              whenUnsatisfiable: ScheduleAnyway
        strategy:
          rollingUpdate:
            maxSurge: 25%
            maxUnavailable: 1
          type: RollingUpdate
      envoyHpa:
        maxReplicas: 20
        metrics:
          - resource:
              name: cpu
              target:
                averageUtilization: 60
                type: Utilization
            type: Resource
          - resource:
              name: memory
              target:
                averageUtilization: 60
                type: Utilization
            type: Resource
        minReplicas: 3
      envoyPDB:
        maxUnavailable: 1
      envoyService:
        externalTrafficPolicy: Local
        name: envoy-private
        type: ClusterIP
    type: Kubernetes
  telemetry:
    tracing:
      customTags:
        envoy:
          literal:
            value: private
          type: Literal
        k8s.namespace.name:
          environment:
            defaultValue: envoy-gateway
            name: ENVOY_GATEWAY_NAMESPACE
          type: Environment
        k8s.pod.name:
          environment:
            defaultValue: '-'
            name: ENVOY_POD_NAME
          type: Environment
        provider:
          literal:
            value: otel
          type: Literal
      provider:
        host: alloy.alloy.svc
        port: 4317
        type: OpenTelemetry
      samplingFraction:
        denominator: 100
        numerator: 100

Environment:
Envoy: 1.34.2
Envoy Gateway: 1.6.3
Alloy: 1.12.2
Kubernetes: 1.33.7
CRDS envoy: 1.6.3
CRDS gateway: 1.4.1 bundle

Logs:
N/A

Activity

  1. arkodg commented on Feb 16, 2026

    @arkodg
    Contributor
  2. added
    kind/bug
    on Feb 16, 2026
  3. added this to the v1.8.0-rc.1 Release milestone on Feb 16, 2026
  4. zirain commented on Feb 17, 2026

    @zirain
    Member

    we introuduce this for users who want sample rate less than 1%.
    IIUC, if you want 100%, it should be as following:

    samplingFraction:
        numerator: 100
    
  5. fe-ax commented on Feb 17, 2026

    @fe-ax
    Author

    @zirain I'm sorry that I wasn't clear. The goal is to set it to 1:1000 or 1:10000, but it didn't sent any traces in using fractional sampling. Setting it to 1:10 or 1:1 neither did, which I suspected would send 100% for testing purposes.

    Using samplingRate: 1 works. (Or 100)

  6. zirain commented on Feb 18, 2026

    @zirain
    Member

    100:1 means 100% sample rateing.
    1:1000 means 1 in 1000 requests will be sampled

  7. fe-ax commented on Feb 18, 2026

    @fe-ax
    Author

    @zirain I'm not sure whether you just want to be rude. It's not working.

    samplingFraction:
      numerator: 1
      denominator: 1000

    That config is not functioning it seems. Even if I send thousands of requests. As mentioned it works correctly when using samplingRate.

  8. zirain commented on Feb 18, 2026

    @zirain
    Member

    what's your configuration result 1% sampling rate.

  9. fe-ax commented on Feb 18, 2026

    @fe-ax
    Author

    @zirain

    That's samplingRate: 1 as mentioned above before. To get 0.1% sampling rate (which does not work, and also mentioned above):

    EnvoyProxy object
    apiVersion: gateway.envoyproxy.io/v1alpha1
    kind: EnvoyProxy
    metadata:
      labels:
        argocd.argoproj.io/instance: envoy-gateway
      name: public
      namespace: envoy-gateway
    spec:
      logging:
        level:
          default: info
      provider:
        kubernetes:
          envoyDeployment:
            container:
              image: >-
                .../envoyproxy/envoy:v1.34.2
              resources:
                limits:
                  cpu: 500m
                  memory: 200Mi
                requests:
                  cpu: 500m
                  memory: 200Mi
            name: envoy-public
            pod:
              affinity:
                podAntiAffinity:
                  requiredDuringSchedulingIgnoredDuringExecution:
                    - labelSelector:
                        matchLabels:
                          app.kubernetes.io/instance: envoy-public
                      topologyKey: kubernetes.io/hostname
              labels:
                app.kubernetes.io/instance: envoy-public
              topologySpreadConstraints:
                - labelSelector:
                    matchLabels:
                      app.kubernetes.io/instance: envoy-public
                  maxSkew: 1
                  topologyKey: topology.kubernetes.io/zone
                  whenUnsatisfiable: ScheduleAnyway
            strategy:
              rollingUpdate:
                maxSurge: 25%
                maxUnavailable: 1
              type: RollingUpdate
          envoyHpa:
            maxReplicas: 20
            metrics:
              - resource:
                  name: cpu
                  target:
                    averageUtilization: 60
                    type: Utilization
                type: Resource
              - resource:
                  name: memory
                  target:
                    averageUtilization: 60
                    type: Utilization
                type: Resource
            minReplicas: 3
          envoyPDB:
            maxUnavailable: 1
          envoyService:
            externalTrafficPolicy: Local
            name: envoy-public
            type: ClusterIP
        type: Kubernetes
      telemetry:
        tracing:
          customTags:
            envoy:
              literal:
                value: public
              type: Literal
            k8s.namespace.name:
              environment:
                defaultValue: envoy-gateway
                name: ENVOY_GATEWAY_NAMESPACE
              type: Environment
            k8s.pod.name:
              environment:
                defaultValue: '-'
                name: ENVOY_POD_NAME
              type: Environment
            provider:
              literal:
                value: otel
              type: Literal
          provider:
            host: alloy.alloy.svc
            port: 4317
            type: OpenTelemetry
          samplingFraction:
            denominator: 1000
            numerator: 1
  10. zirain commented on Feb 19, 2026

    @zirain
    Member
    # export GATEWAY_HOST=$(kubectl get gateway/eg -o jsonpath='{.status.addresses[0].value}')
    #
    # curl $GATEWAY_HOST/get
    # curl -H "x-some-id: fake-val" $GATEWAY_HOST/get
    #
    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
      name: eg
    spec:
      gatewayClassName: eg
      listeners:
        - name: http
          protocol: HTTP
          port: 80
      infrastructure:
        parametersRef:
          group: gateway.envoyproxy.io
          kind: EnvoyProxy
          name: zipkin-tracing
    ---
    apiVersion: gateway.envoyproxy.io/v1alpha1
    kind: EnvoyProxy
    metadata:
      name: zipkin-tracing
    spec:
      telemetry:
        tracing:
          samplingFraction:
            numerator: 1
            denominator: 1000
          provider:
            type: Zipkin
            backendRefs:
              - name: zipkin
                namespace: istio-system
                port: 9411
              # - name: otel-collector
              #   namespace: monitoring
              #   port: 9411
            zipkin:
              enable128BitTraceId: true
          customTags:
            "provider":
              type: Literal
              literal:
                value: "zipkin"
    ---
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: backend
    spec:
      hostnames:
      parentRefs:
        - name: eg
      rules:
        - matches:
            - path:
                type: PathPrefix
                value: /
          backendRefs:
            - name: infra-backend-v1
              port: 8080
    ---
    # apiVersion: gateway.envoyproxy.io/v1alpha1
    # kind: BackendTrafficPolicy
    # metadata:
    #   name: backend-tracing
    # spec:
    #   targetRefs:
    #     - group: gateway.networking.k8s.io
    #       kind: HTTPRoute
    #       name: backend-headers
    #   telemetry:
    #     tracing:
    #       samplingFraction:
    #         numerator: 100
    #         denominator: 100
    ---
    apiVersion: gateway.networking.k8s.io/v1
    kind: HTTPRoute
    metadata:
      name: backend-headers
    spec:
      hostnames:
      parentRefs:
        - name: eg
      rules:
        - matches:
            - headers:
                - name: x-some-id
                  type: Exact
                  value: fake-val
          backendRefs:
            - name: infra-backend-v1
              port: 8080
    
    

    result 0.001 sample rate as expected.

    istioctl pc l eg-84cdf87d75-v9dpj --proxy-admin-port 19000 --port 10080  -o yaml | grep randomSampling -A 10
              randomSampling:
                value: 0.001
    
  11. fe-ax commented on Feb 19, 2026

    @fe-ax
    Author

    @zirain Theoretically, yes, it should work. I have no doubts the setting changes the config. However when it's 0.001 it just stops sending any traces in. Or is there something else wrong in these three sampling settings?

           "default_filter_chain": {
            "filters": [
             {
              "name": "envoy.filters.network.http_connection_manager",
              "typed_config": {
               "@type": "type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager",
               "stat_prefix": "http-9999",
               "rds": {
                "config_source": {
                 "ads": {},
                 "resource_api_version": "V3"
                },
                "route_config_name": "envoy-gateway/public/http"
               },
               "http_filters": [
                {
                 "name": "envoy.filters.http.router",
                 "typed_config": {
                  "@type": "type.googleapis.com/envoy.extensions.filters.http.router.v3.Router",
                  "suppress_envoy_headers": true
                 }
                }
               ],
               "tracing": {
                "client_sampling": {
                 "value": 100
                },
                "random_sampling": {
                 "value": 0.001
                },
                "overall_sampling": {
                 "value": 100
                },
  12. fe-ax commented on Feb 19, 2026

    @fe-ax
    Author

    I see now.

    samplingFraction:
      numerator: 1
      denominator: 1000
    

    Results in 0.001 requests being sampled from a base value of 100. Resulting in 1:100.000 being sampled.

    I think there is a miscalculation going on in this setting as the documentation says 0.1% will be sampled, while in practice 0.001% will be sampled. (Referring to https://gateway.envoyproxy.io/latest/tasks/observability/proxy-trace/#sampling-rate)

  13. fe-ax commented on Feb 20, 2026

    @fe-ax
    Author

    @zirain I've looked into it a little deeper and I think there is issue in this code.

    {
    name: "fraction numerator only",
    tracing: &egv1a1.ProxyTracing{
    Tracing: egv1a1.Tracing{
    SamplingFraction: &gwapiv1.Fraction{
    Numerator: 100,
    },
    },
    },
    expected: 1.0,
    },

    As you said:

    we introuduce this for users who want sample rate less than 1%.
    IIUC, if you want 100%, it should be as following:

    samplingFraction:
    numerator: 100

    It would actually end up in 1% sampling as the base value for 100% is 100.0, not 1.0.

    I think this line is missing a multiplication by 100.

    rate = numerator / denominator

    I understand that, if you agree it's indeed not as expected, changing this code is complicated. People already using this would start receiving 100 times more traces.

    Maybe we should edit the documentation, like the part referred to in the comment above this one?

  14. reopened this on Feb 21, 2026
  15. zirain commented on Feb 21, 2026

    @zirain
    Member

    @fe-ax yeah, you're right, this's my mistake.

  16. zirain commented on Feb 21, 2026

    @zirain
    Member

    I missed // +kubebuilder:validation:XValidation:message="numerator must be less than or equal to denominator",rule="self.numerator <= self.denominator"

  17. self-assigned this
    on Feb 21, 2026
  18. fe-ax commented on Feb 22, 2026

    @fe-ax
    Author

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions