Skip to content

Commit

Permalink
Data source health check: Support data source zipkin
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jun 29, 2022
1 parent fc14f66 commit a86df5b
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ implemented as of June 2022.
- Prometheus
- Tempo
- Testdata
- Zipkin

We are humbly asking the community to contribute adapters for other data
sources.
Expand Down
1 change: 0 additions & 1 deletion docs/datasource-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ stackdriver
testdata

### UNKNOWN
zipkin

### TODO
alertmanager
Expand Down
7 changes: 7 additions & 0 deletions examples/datasource-health-probe.rst
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,10 @@ Testdata

python examples/datasource-health-probe.py --type=testdata


Zipkin
======
::

docker run --rm -it --publish=9411:9411 openzipkin/zipkin:2.23
python examples/datasource-health-probe.py --type=zipkin --url=http://host.docker.internal:9411
6 changes: 6 additions & 0 deletions grafana_client/elements/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,12 @@ def health_check(self, datasource: Union[DatasourceIdentifier, Dict]) -> Datasou
message = "Success"
success = True

# With Zipkin, a 200 OK response with a JSON body containing an empty array is probably just fine.
elif datasource_type == "zipkin":
if response == []:
message = "Success"
success = True

# Generic case, where the response has a top-level `results` or `data` key.
else:
if "results" in response:
Expand Down
5 changes: 5 additions & 0 deletions grafana_client/knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def datasource_factory(datasource: DatasourceModel) -> DatasourceModel:
datasource.access = "proxy"
elif datasource.type == "testdata":
pass
elif datasource.type == "zipkin":
datasource.access = "proxy"
else:
raise NotImplementedError(f"Unknown data source type: {datasource.type}")
return datasource
Expand Down Expand Up @@ -226,6 +228,8 @@ def query_factory(datasource, expression: str, store: Optional[str] = None) -> U
query = {}
elif datasource_type == "testdata":
query = expression
elif datasource_type == "zipkin":
query = {}
else:
raise NotImplementedError(f"Unknown data source type: {datasource_type}")
return query
Expand All @@ -251,6 +255,7 @@ def query_factory(datasource, expression: str, store: Optional[str] = None) -> U
"simpod-json-datasource": "url:///datasources/proxy/{datasource_id}",
"tempo": "url:///datasources/proxy/{datasource_id}/api/echo",
"testdata": "url:///datasources/uid/{datasource_uid}",
"zipkin": "url:///datasources/proxy/{datasource_id}/api/v2/services",
}


Expand Down
8 changes: 8 additions & 0 deletions test/elements/test_datasource_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@
"access": "proxy",
}

ZIPKIN_DATASOURCE = {
"id": 57,
"uid": "3sXIv8q7k",
"name": "Zipkin",
"type": "zipkin",
"access": "proxy",
}


PROMETHEUS_DATA_RESPONSE = {
"status": "success",
Expand Down
27 changes: 27 additions & 0 deletions test/elements/test_datasource_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
SUNANDMOON_DATASOURCE_INCOMPLETE,
TEMPO_DATASOURCE,
TESTDATA_DATASOURCE,
ZIPKIN_DATASOURCE,
)

import requests_mock
Expand Down Expand Up @@ -731,6 +732,32 @@ def test_health_check_testdata(self, m):
),
)

@requests_mock.Mocker()
def test_health_check_zipkin_success(self, m):
m.get(
"http://localhost/api/datasources/uid/3sXIv8q7k",
json=ZIPKIN_DATASOURCE,
)
m.get(
"http://localhost/api/datasources/proxy/57/api/v2/services",
json=[],
)
response = self.grafana.datasource.health_check(DatasourceIdentifier(uid="3sXIv8q7k"))
response.duration = None
response.response = None
self.assertEqual(
response,
DatasourceHealthResponse(
uid="3sXIv8q7k",
type="zipkin",
success=True,
status="OK",
message="Success",
duration=None,
response=None,
),
)

@requests_mock.Mocker()
def test_health_check_zdict_valid_response_success(self, m):
"""
Expand Down

0 comments on commit a86df5b

Please sign in to comment.