Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Add datasources list method #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

danielllek
Copy link

Add datasources list method

@@ -97,6 +88,33 @@ func (c *Client) UpdateDataSource(s *DataSource) error {
return nil
}

func (c *Client) DataSources() ([]DataSource, error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have a test for this method, and even nicer that it'd have an example of the payload the api returns.

Copy link

@gpolek gpolek Oct 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will prepare some additional tests.

Regarding payload, for example we use Azure Monitor and Zabbix, both having different jsonData and secureJsopData

Azure Monitor:

{
    "id": 101,
    "orgId": 1,
    "name": "SOME_DATASOURCE_NAME",
    "type": "grafana-azure-monitor-datasource",
    "typeLogoUrl": "",
    "access": "proxy",
    "url": "/api/datasources/proxy/101",
    "password": "",
    "user": "",
    "database": "",
    "basicAuth": false,
    "basicAuthUser": "",
    "basicAuthPassword": "",
    "withCredentials": false,
    "isDefault": false,
    "jsonData": {
        "appInsightsAppId": "00000000-0000-0000-0000-000000000000",
        "azureLogAnalyticsSameAs": false,
        "cloudName": "azuremonitor"
    },
    "secureJsonData": {
        "appInsightsApiKey":"bUtGHDSq7XtxsKeBUrfwYfk6QhGWZRP2
    },
    "version": 5,
    "readOnly": false
}

Zabbix:

{
    "id": 67,
    "orgId": 1,
    "name": "Zabbix",
    "type": "alexanderzobnin-zabbix-datasource",
    "typeLogoUrl": "",
    "access": "proxy",
    "url": "http://zabbi/api_jsonrpc.php",
    "password": "",
    "user": "",
    "database": "",
    "basicAuth": false,
    "basicAuthUser": "",
    "basicAuthPassword": "",
    "withCredentials": false,
    "isDefault": false,
    "jsonData": {
        "addThresholds": true,
        "alerting": true,
        "alertingMinSeverity": 3,
        "dbConnectionDatasourceId": null,
        "dbConnectionEnable": false,
        "disableReadOnlyUsersAck": false,
        "keepCookies": [],
        "password": "KdrVK8U0x3hgBppY",
        "trends": false,
        "username": "grafana",
        "zabbixVersion": 4
    },
    "secureJsonData": {},
    "version": 8,
    "readOnly": false
}

DefaultRegion string `json:"defaultRegion,omitempty"`
TlsSkipVerify bool `json:"tlsSkipVerify,omitempty"`
}
type JSONData map[string]interface{}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious to hear your reasoning for changing the types here. Do we have to worry about any potential consumers of Datasource method since they'll have to change how they access the JSONData and SecureJSONData properties?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are multiple DataSource types available for Grafana and struct here allows only to use go-grafana-api only with one DataSource (I assume it was something with AWS).

If we loosen typing here to map[string]interface{} we are able to pass different jsonData and secureJsonData needed for other datasource types.

We know breaking changes are not welcomed into the interfaces and we are more than happy to make this possible without breaking changes but I don't see a way how to achieve that. Maybe with reflect or changing type to some Inteface but I am not a fan of either.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking changes aside, I'm not sure it's necessary to remove the schema from jsonData and secureJsonData entirely to support additional data source types. There tends to be some overlap in values between the different data sources; how we've handled different schemas for similar objects is to merge the maps of all the possible keys of the different data source types and tack on the omitempty tag to most of them so that they won't be sent unless explicitly used. Does that sound like an alright approach to you?

@mlclmj mlclmj added enhancement size/M Denotes a PR that changes 30-99 lines labels Oct 17, 2019
Copy link
Contributor

@mlclmj mlclmj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto to the points that @ghmeier makes, these would be breaking changes for downstream clients, for example in the terraform provider, and I don't necessarily favor that unless there's a compelling reason to.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement size/M Denotes a PR that changes 30-99 lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants