Skip to content

Add TelemetryPolicy test#783

Merged
silvi-t merged 1 commit intoKuadrant:mainfrom
silvi-t:telemetryPolicy
Nov 6, 2025
Merged

Add TelemetryPolicy test#783
silvi-t merged 1 commit intoKuadrant:mainfrom
silvi-t:telemetryPolicy

Conversation

@silvi-t
Copy link
Copy Markdown
Contributor

@silvi-t silvi-t commented Oct 3, 2025

Description

  • Adds comprehensive test coverage for TelemetryPolicy custom labels propagation to Limitador metrics
  • Implements support for custom user attributes in Keycloak OIDC tokens through new mapper functionality
  • Tests verify that user and group labels from both API Key and OIDC authentication correctly appear in Limitador metrics

Changes

New Features

  • Keycloak Client Mapper: Added add_user_attribute_mapper() method in testsuite/oidc/keycloak/objects.py:122 to enable custom user attributes in JWT tokens
    • Supports configurable attributes with flexible token claim mapping
    • Controls inclusion in access tokens, ID tokens, and userinfo endpoints

Tests

  • TelemetryPolicy Test Suite (testsuite/tests/singlecluster/extensions/telemetry_policy/):
    • test_telemetry_policy_api_key_auth.py: Tests custom labels with API Key authentication
      • Verifies user/group labels from API key annotations appear in Limitador metrics
      • Tests authorized_calls, authorized_hits, and limited_calls metrics
    • test_telemetry_policy_keycloak_auth.py: Tests custom labels with Keycloak/OIDC authentication
      • Verifies user/group labels from OIDC token claims appear in Limitador metrics
      • Tests propagation from Keycloak user attributes
    • conftest.py: Shared fixtures for ServiceMonitor, TelemetryPolicy, and RateLimit policy setup

Testing

  • Added parameterized tests covering multiple authentication methods (API Key and OIDC)
  • Tests verify label presence and correctness across three metric types
  • Includes Prometheus integration to validate metrics scraping and label propagation

Verification Steps

Run the tests using:
poetry run pytest testsuite/tests/singlecluster/extensions/telemetry_policy/test_telemetry_policy_api_key_auth.py
poetry run pytest testsuite/tests/singlecluster/extensions/telemetry_policy/test_telemetry_policy_keycloak_auth.py

Closes #761

@silvi-t silvi-t requested a review from crstrn13 October 3, 2025 13:39
Comment thread testsuite/tests/singlecluster/extensions/telemetry_policy/conftest.py Outdated
@silvi-t silvi-t force-pushed the telemetryPolicy branch 3 times, most recently from 4055853 to 9f26844 Compare October 16, 2025 11:06
@silvi-t silvi-t marked this pull request as ready for review October 16, 2025 11:10
@silvi-t silvi-t requested a review from averevki October 16, 2025 11:10
Comment thread testsuite/oidc/keycloak/objects.py Outdated
Comment thread testsuite/tests/singlecluster/extensions/telemetry_policy/conftest.py Outdated
Comment thread testsuite/tests/singlecluster/extensions/telemetry_policy/conftest.py Outdated
Signed-off-by: Silvia Tarabova <starabov@redhat.com>
Copy link
Copy Markdown
Contributor

@averevki averevki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice, tests run for me 👍

@silvi-t silvi-t merged commit 65d8bff into Kuadrant:main Nov 6, 2025
3 checks passed
@silvi-t silvi-t deleted the telemetryPolicy branch December 10, 2025 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TelemetryPolicy testing

4 participants