Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added grafana uid #211

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion docs/json_schemas/grafana_datasource/v0/requirer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@
},
"title": "Datasource Uids",
"type": "string"
},
"grafana_uid": {
"description": "UID of the requirer application.",
"examples": [
"foo-0000-0000-0000-0000-grafana-1"
],
"title": "Grafana Uid",
"type": "string"
}
},
"required": [
"datasource_uids"
"datasource_uids",
"grafana_uid"
],
"title": "GrafanaSourceRequirerAppData",
"type": "object"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@
"description": "Grafana datasource UID, as assigned by Grafana.",
"title": "Uid",
"type": "string"
},
"grafana_uid": {
"description": "Grafana UID.",
"title": "Grafana Uid",
"type": "string"
}
},
"required": [
"type",
"uid"
"uid",
"grafana_uid"
],
"title": "GrafanaDatasource",
"type": "object"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@
"description": "Grafana datasource UID, as assigned by Grafana.",
"title": "Uid",
"type": "string"
},
"grafana_uid": {
"description": "Grafana UID.",
"title": "Grafana Uid",
"type": "string"
}
},
"required": [
"type",
"uid"
"uid",
"grafana_uid"
],
"title": "GrafanaDatasource",
"type": "object"
Expand Down
9 changes: 7 additions & 2 deletions interfaces/grafana_datasource/v0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ In most cases, this will be accomplished using the [grafana_source library](http
The `grafana_datasource` interface implements a provider/requirer pattern.
The provider is a charm that implements a grafana datasource-compatible endpoint, and the requirer is a charm that is able to use such an endpoint to query the data.

The requirer is furthermore expected to share back to the provider a unique identifier assigned to the source. This can be used by the provider to share with other charms for data correlation and cross-referencing purposes.
The requirer is furthermore expected to share back to the provider:
- a unique identifier assigned to the source. This can be used by the provider to share with other charms for data correlation and cross-referencing purposes.
- a unique identifier for the grafana application itself.

```mermaid
flowchart TD
Provider -- DatasourceEndpoint --> Requirer
Requirer -- DatasourceUID --> Provider
Requirer -- [DatasourceUID,GrafanaUID] --> Provider
```

## Behavior
Expand All @@ -30,6 +32,7 @@ The requirer and the provider need to adhere to a certain set of criteria to be
### Requirer

- Is expected to share back via application data a mapping from provider unit names to unique datasource IDs.
- Is expected to share back via application data a unique ID for the grafana application.

## Relation Data

Expand Down Expand Up @@ -73,10 +76,12 @@ application_data: {

The provider is expected to share back a unique identifier for each unit of the requirer, as a mapping.
This will be encoded as a json dict and nested under the `datasource_uids` field in the application databag.
Also, is expected to share back a unique ID for the grafana application.

#### Example
```yaml
application-data: {
grafana_uid: 0000-0000-0000-0000,
datasource_uids: {
"tempo/0": 0000-0000-0000-0001,
"tempo/1": 0000-0000-0000-0002,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,3 @@ def test_datasource_uid_shared_if_remote_data_valid():
# each requirer unit has received a datasource uid
assert ds_uids['foo/0']
assert ds_uids['foo/42']


4 changes: 4 additions & 0 deletions interfaces/grafana_datasource/v0/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class ProviderSchema(DataBagSchema):
class GrafanaSourceRequirerAppData(BaseModel):
"""Application databag model for the requirer side of this interface."""
datasource_uids: Json[Dict[str, str]]
grafana_uid: str = Field(
description="UID of the requirer application.",
examples=['foo-0000-0000-0000-0000-grafana-1']
)


class RequirerSchema(DataBagSchema):
Expand Down
9 changes: 6 additions & 3 deletions interfaces/grafana_datasource_exchange/v0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ The requirer and the provider need to adhere to a certain set of criteria to be
- Is expected to register each datasource endpoint (one per unit) with a central grafana application and obtain a Datasource UID for each one of them.
- Is expected to share via application data, as a json-encoded array (sorted by UID), the following information:
- for each datasource (which technically will likely mean, for each unit of the application):
- the datasource UID: an arbitrary string, that is expected to be unique for the grafana instance
- the datasource UID: an arbitrary string, uniquely identifying the datasource
- the grafana UID: an arbitrary string uniquely identifying a grafana instance
- the datasource type: a grafana datasource type name (typically will be [one of the built-in ones](https://grafana.com/docs/grafana/latest/datasources/#built-in-core-data-sources))

To avoid complexity, we stipulate that the data will be provided in bulk: only 'fully specified' datasources will be shared, i.e. this is not a valid databag state:
Expand Down Expand Up @@ -62,11 +63,13 @@ application_data: {
[
{
type: tempo,
uid: 0000-0000-0000-0001
uid: 0000-0000-0000-0001,
grafana_uid: 0000-0000-0000-0002,
},
{
type: prometheus,
uid: 0000-0000-0000-0002
uid: 0000-0000-0000-0003,
grafana_uid: 0000-0000-0000-0004,
},
]
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import json

from interface_tester import Tester
from scenario import State, Relation

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
# given that this interface is symmetric, and we expect each provider
# to also be a requirer, we omit the requirer tests.
from interface_tester import Tester
from scenario import State, Relation


def test_datasource_exchange():
# GIVEN the grafana_datasource interface has shared one or more source UIDs
source_exchange = Relation(
endpoint='grafana-source-exchange',
interface='grafana_datasource_exchange',
remote_app_name='bar'
)
tester = Tester(state_in=State(
relations=[
source_exchange
]
))
# WHEN the requirer processes any relation event
tester.run('grafana-source-exchange-relation-changed')
# THEN the requirer publishes valid data
tester.assert_schema_valid()
1 change: 1 addition & 0 deletions interfaces/grafana_datasource_exchange/v0/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class GrafanaDatasource(BaseModel):
"https://grafana.com/docs/grafana/latest/datasources/#built-in-core-data-sources.",
examples=["tempo", "loki", "prometheus", "elasticsearch"])
uid: str = Field(description="Grafana datasource UID, as assigned by Grafana.")
grafana_uid: str = Field(description="Grafana UID.")


class GrafanaSourceAppData(BaseModel):
Expand Down
Loading