Skip to content

Commit

Permalink
Merge pull request #23674 from vbotbuildovich/backport-pr-23638-v24.1…
Browse files Browse the repository at this point in the history
….x-490

[v24.1.x] tests: test legacy dashboard in rpk generate
  • Loading branch information
r-vasquez authored Oct 8, 2024
2 parents d64c5fb + ed43c0e commit 94d253e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
11 changes: 8 additions & 3 deletions tests/rptest/clients/rpk.py
Original file line number Diff line number Diff line change
Expand Up @@ -1439,13 +1439,18 @@ def try_offset_delete(retries=5):
# Retry if NOT_COORDINATOR is observed when command exits 1
return try_offset_delete(retries=5)

def generate_grafana(self, dashboard):

def generate_grafana(self, dashboard, datasource="", metrics_endpoint=""):
cmd = [
self._rpk_binary(), "generate", "grafana-dashboard", "--dashboard",
dashboard
dashboard, "-X", "admin.hosts=" + self._redpanda.admin_endpoints()
]

if datasource != "":
cmd += ["--datasource", datasource]

if metrics_endpoint != "":
cmd += ["--metrics-endpoint", metrics_endpoint]

return self._execute(cmd)

def describe_log_dirs(self):
Expand Down
38 changes: 21 additions & 17 deletions tests/rptest/tests/rpk_generate_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,32 @@ def __init__(self, ctx):
self._ctx = ctx
self._rpk = RpkTool(self.redpanda)

@cluster(num_nodes=3)
@cluster(num_nodes=1)
def test_generate_grafana(self):
"""
Test that rpk generate grafana-dashboard will generate the required dashboard
and that it's a proper JSON file.
"""
Test that rpk generate grafana-dashboard will generate the required dashboard
and that it's a proper JSON file.
"""

# dashboard is the dictionary of the current dashboards and their title.
dashboards = {
"operations": "Redpanda Ops Dashboard",
"consumer-metrics": "Kafka Java Consumer",
"consumer-offsets": "Kafka Consumer Offsets",
"topic-metrics": "Kafka Topic Metrics"
}
for name, expectedTitle in dashboards.items():
out = self._rpk.generate_grafana(name)
dashboards = [
"operations", "consumer-metrics", "consumer-offsets",
"topic-metrics", "legacy"
]
for name in dashboards:
datasource = ""
metrics_endpoint = ""
if name == "legacy":
datasource = "redpanda"
n = self.redpanda.get_node(1)
metrics_endpoint = self.redpanda.admin_endpoint(
n) + "/public_metrics"
out = self._rpk.generate_grafana(name,
datasource=datasource,
metrics_endpoint=metrics_endpoint)
try:
dash = json.loads(out)

# We only validate one known value, the main goal is to identify if it's a valid JSON
title = dash["title"]
assert title == expectedTitle, f"Received dashboard title: '{title}', expected: '{expectedTitle}'"
# We just need to assert that it was able to retrieve and parse the dashboard as valid json
json.loads(out)
except json.JSONDecodeError as err:
self.logger.error(
f"unable to parse generated' {name}' dashboard : {err}")

0 comments on commit 94d253e

Please sign in to comment.