grafana-tools / sdk

Library for using Grafana' structures in Go programs and client for Grafana REST API.
Apache License 2.0
319 stars 190 forks source link

StatusMessage Datasource Bug #197

Closed safaci2000 closed 1 day ago

safaci2000 commented 2 years ago

Hello,

So the response being returned from: CreateDatasource is StatusMessage unfortunately that does not map out correctly.

The response for the current version of the API looks like this for: Version 8.3.6

{
  "datasource": {
    "id": 5,
    "uid": "EwLFuaBnk",
    "orgId": 1,
    "name": "testing",
    "type": "elasticsearch",
    "typeLogoUrl": "",
    "access": "direct",
    "url": "http://1.2.3.4",
    "password": "",
    "user": "",
    "database": "grafanasdk",
    "basicAuth": false,
    "basicAuthUser": "",
    "basicAuthPassword": "",
    "withCredentials": false,
    "isDefault": false,
    "jsonData": {
      "esVersion": "5",
      "maxConcurrentShardRequests": "256",
      "timeField": "@timestamp"
    },
    "secureJsonFields": {},
    "version": 1,
    "readOnly": false
  },
  "id": 5,
  "message": "Datasource added",
  "name": "testing"
}

Except for id, message and name none of the other fields will be mapped correctly. As StatusMessage is being used by a variety of fields, before I attempt to fix it, I was wondering what approach would you like to take?

I saw a Generics 1.18 ticket so not sure if this would benefit from it.

I was thinking of a few approaches.

  1. Parse the the message twice giving it raw JSON and a 2nd time with just the content of datasource ?
  2. Create a new DatasourceStatusMessage.
  3. Look at how Generics might come into play to create a more generic approach.

Any suggestions on how you'd prefer to have this handled?