[BUG] NodeGraph API plugin is unable to add datasource URL when using grafana api to add datasource
Describe the bug The Node Graph API plugin fails to correctly add the datasource URL when using the Grafana API to add the datasource. Although the datasource appears to be added successfully, the DATASOURCE_URL field does not show up in the Grafana UI, leading to a "Bad Gateway" error.
Steps to Reprodue
- Create a script using the provided code below. Run the script to add the Node Graph API datasource via the Grafana API. bash Copy #!/bin/bash GRAFANA_URL="https://$grafana_ingress" USERNAME="admin" PASSWORD="your_grafana_password"
DATASOURCE_NAME="NodeGraphAPI_DS" DATASOURCE_TYPE="hamedkarbasi93-nodegraphapi-datasource" DATASOURCE_URL="http://k8spacket.k8spacket.svc.cluster.local:8080/nodegraph"
Create the JSON payload
json_payload="{ "name": "$DATASOURCE_NAME", "type": "$DATASOURCE_TYPE", "access": "proxy", "isDefault": false, "url": "$DATASOURCE_URL", "uid": "nodegraphapi_ds", "jsonData": {} }"
echo "JSON Payload:" echo "$json_payload"
Add the NodeGraph API datasource
response=$(curl -k -s -w "%{http_code}" -o /tmp/curl_response_output -X POST "$GRAFANA_URL/api/datasources"
-u "$USERNAME:$PASSWORD"
-H "Content-Type: application/json"
-d "$json_payload")
Check the HTTP response code
if [ "$response" -eq 200 ]; then echo "Datasource '$DATASOURCE_NAME' added successfully." elif [ "$response" -eq 401 ]; then echo "Authentication failed. Please check your Grafana username and password." elif [ "$response" -eq 409 ]; then echo "Datasource '$DATASOURCE_NAME' already exists." else echo "Failed to add datasource '$DATASOURCE_NAME'. HTTP response code: $response" echo "Error details:" cat /tmp/curl_response_output fi
Expected Result The datasource should be successfully added, and the DATASOURCE_URL field should appear in the Grafana UI.
Actual Result The datasource is successfully added, but the DATASOURCE_URL field is missing in the Grafana UI. A "Bad Gateway" error is displayed due to the absence of the DATASOURCE_URL.