Skip to content

Commit

Permalink
dt: test enterprise_license_expiry_sec metric
Browse files Browse the repository at this point in the history
Adds an integration test for the license expiry metric.
  • Loading branch information
pgellert committed Sep 19, 2024
1 parent 5289b7c commit 1d76d0a
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion tests/rptest/tests/rpk_cluster_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import json

from rptest.services.cluster import cluster
from rptest.services.redpanda import RESTART_LOG_ALLOW_LIST
from rptest.services.redpanda import RESTART_LOG_ALLOW_LIST, MetricSamples, MetricsEndpoint
from rptest.util import expect_exception, get_cluster_license, get_second_cluster_license
from ducktape.utils.util import wait_until
from rptest.util import wait_until_result
Expand Down Expand Up @@ -209,6 +209,25 @@ def test_cluster_down(self):
else:
assert False, f"Unexpected success: '{r}'"

def _get_license_expiry(self) -> int:
METRICS_NAME = "cluster_features_enterprise_license_expiry_sec"

def get_metrics_value(metrics_endpoint: MetricsEndpoint) -> int:
metrics = self.redpanda.metrics_sample(
sample_pattern=METRICS_NAME, metrics_endpoint=metrics_endpoint)
assert isinstance(metrics, MetricSamples), \
f'Failed to get metrics for {METRICS_NAME}'

samples = [sample for sample in metrics.samples]
assert len(samples) == len(self.redpanda.nodes), \
f'Invalid number of samples: {len(samples)}'
return int(samples[0].value)

internal_val = get_metrics_value(MetricsEndpoint.METRICS)
public_val = get_metrics_value(MetricsEndpoint.PUBLIC_METRICS)
assert internal_val == public_val, f"Mismatch: {internal_val} != {public_val}"
return internal_val

@cluster(num_nodes=3)
def test_upload_and_query_cluster_license_rpk(self):
"""
Expand All @@ -221,6 +240,12 @@ def test_upload_and_query_cluster_license_rpk(self):
"Skipping test, REDPANDA_SAMPLE_LICENSE env var not found")
return

wait_until(lambda: self._get_license_expiry() == -1,
timeout_sec=10,
backoff_sec=1,
retry_on_exc=True,
err_msg="Unset license should return a -1 expiry")

with tempfile.NamedTemporaryFile() as tf:
tf.write(bytes(license, 'UTF-8'))
tf.seek(0)
Expand All @@ -238,6 +263,14 @@ def obtain_license():
retry_on_exc=True,
err_msg="unable to retrieve license information")

wait_until(
lambda: self._get_license_expiry() > 0,
timeout_sec=10,
backoff_sec=1,
retry_on_exc=True,
err_msg="The expiry metric should be positive with a valid license"
)

expected_license = {
'expires':
"Jul 11 2122",
Expand Down

0 comments on commit 1d76d0a

Please sign in to comment.