Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix(dashboard): index out of bounds for widget query range (#9851)

Vikrant Gupta6b3c6fc7226d
diff --git a/pkg/types/dashboardtypes/dashboard.go b/pkg/types/dashboardtypes/dashboard.go
index 414537ebbd..b5177539a2 100644
--- a/pkg/types/dashboardtypes/dashboard.go
+++ b/pkg/types/dashboardtypes/dashboard.go
@@ -349,7 +349,7 @@ func (dashboard *Dashboard) GetWidgetQuery(startTime, endTime uint64, widgetInde
return nil, errors.Wrapf(err, errors.TypeInvalidInput, ErrCodeDashboardInvalidData, "invalid dashboard data")
}
- if len(data.Widgets) < int(widgetIndex)+1 {
+ if widgetIndex < 0 || int(widgetIndex) >= len(data.Widgets) {
return nil, errors.Newf(errors.TypeInvalidInput, ErrCodeDashboardInvalidInput, "widget with index %v doesn't exist", widgetIndex)
}
diff --git a/tests/integration/src/dashboard/a_public_dashboard.py b/tests/integration/src/dashboard/a_public_dashboard.py
index e505573e3e..b78b55249d 100644
--- a/tests/integration/src/dashboard/a_public_dashboard.py
+++ b/tests/integration/src/dashboard/a_public_dashboard.py
@@ -101,3 +101,145 @@ def test_create_and_get_public_dashboard(
)
tuple_row = tuple_result.fetchone()
assert tuple_row is not None
+
+
+def test_public_dashboard_widget_query_range(
+ signoz: SigNoz,
+ create_user_admin: Operation, # pylint: disable=unused-argument
+ get_token: Callable[[str, str], str],
+):
+ admin_token = get_token(USER_ADMIN_EMAIL, USER_ADMIN_PASSWORD)
+
+ dashboard_req = {
+ "title": "Test Widget Query Range Dashboard",
+ "description": "For testing widget query range",
+ "version": "v5",
+ "widgets": [
+ {
+ "id": "6990c9d8-57ad-492f-8c63-039081e30d02",
+ "panelTypes": "graph",
+ "query": {
+ "builder": {
+ "queryData": [
+ {
+ "aggregations": [
+ {
+ "metricName": "container.cpu.time",
+ "reduceTo": "avg",
+ "spaceAggregation": "sum",
+ "temporality": "",
+ "timeAggregation": "rate",
+ }
+ ],
+ "dataSource": "metrics",
+ "disabled": False,
+ "expression": "A",
+ "filter": {
+ "expression": ""
+ },
+ "functions": [],
+ "groupBy": [],
+ "having": {
+ "expression": ""
+ },
+ "legend": "",
+ "limit": 10,
+ "orderBy": [],
+ "queryName": "A",
+ "source": "",
+ "stepInterval": 10
+ }
+ ],
+ "queryFormulas": [],
+ "queryTraceOperator": []
+ },
+ "clickhouse_sql": [
+ {
+ "disabled": False,
+ "legend": "",
+ "name": "A",
+ "query": ""
+ }
+ ],
+ "id": "80f12506-ef72-4013-8282-2713c8114c9e",
+ "promql": [
+ {
+ "disabled": False,
+ "legend": "",
+ "name": "A",
+ "query": ""
+ }
+ ],
+ "queryType": "builder"
+ },
+ }
+ ],
+ }
+ create_response = requests.post(
+ signoz.self.host_configs["8080"].get("/api/v1/dashboards"),
+ json=dashboard_req,
+ headers={"Authorization": f"Bearer {admin_token}"},
+ timeout=2,
+ )
+ assert create_response.status_code == HTTPStatus.CREATED
+ data = create_response.json()["data"]
+ dashboard_id = data["id"]
+
+
+ # create public dashboard
+ response = requests.post(
+ signoz.self.host_configs["8080"].get(
+ f"/api/v1/dashboards/{dashboard_id}/public"
+ ),
+ json={
+ "timeRangeEnabled": False,
+ "defaultTimeRange": "10s",
+ },
+ headers={"Authorization": f"Bearer {admin_token}"},
+ timeout=2,
+ )
+
+ assert response.status_code == HTTPStatus.CREATED
+ assert "id" in response.json()["data"]
+
+ response = requests.get(
+ signoz.self.host_configs["8080"].get(
+ f"/api/v1/dashboards/{dashboard_id}/public"
+ ),
+ headers={"Authorization": f"Bearer {admin_token}"},
+ timeout=2,
+ )
+
+ assert response.status_code == HTTPStatus.OK
+ assert response.json()["status"] == "success"
+ public_path = response.json()["data"]["publicPath"]
+ public_dashboard_id = public_path.split("/public/dashboard/")[-1]
+
+
+
+ resp = requests.get(
+ signoz.self.host_configs["8080"].get(
+ f"/api/v1/public/dashboards/{public_dashboard_id}/widgets/0/query_range"
+ ),
+ timeout=2,
+ )
+ print(resp.json())
+ assert resp.status_code == HTTPStatus.OK
+ assert resp.json().get("status") == "success"
+
+
+ resp = requests.get(
+ signoz.self.host_configs["8080"].get(
+ f"/api/v1/public/dashboards/{public_dashboard_id}/widgets/-1/query_range"
+ ),
+ timeout=2,
+ )
+ assert resp.status_code == HTTPStatus.BAD_REQUEST
+
+ resp = requests.get(
+ signoz.self.host_configs["8080"].get(
+ f"/api/v1/public/dashboards/{public_dashboard_id}/widgets/1/query_range"
+ ),
+ timeout=2,
+ )
+ assert resp.status_code == HTTPStatus.BAD_REQUEST