Skip to content

Commit cc8a156

Browse files
committed
Adding support for multiple data sources in psconfig grafana agent
1 parent 8555128 commit cc8a156

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

psconfig/perfsonar-psconfig/doc/psconfig-grafana-agent-schema.json

+4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@
184184
"enum": [ "auto", "manual" ],
185185
"description": "Define how to determine the data source to use. 'auto' means it will try to detrmine an archive based on pSConfig template and will fallback to the default defined by grafana-datasource-name. 'manual' means it will just use grafana-datasource-name. "
186186
},
187+
"datasource_name": {
188+
"type": "string",
189+
"description": "If datasource_selector is manual, then the name of the data source to use. If datasource_selector is auto then this is ignored. If datasource_selector is manual and this is not set, then the global grafana-datasource-name will be used."
190+
},
187191
"priority": {
188192
"$ref": "#/pSConfig/Priority",
189193
"description": "Priority of display."

psconfig/perfsonar-psconfig/psconfig/grafana/agent.py

+7
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,13 @@ def _run_handle_psconfig(self, psconfig, agent_conf, remote=None):
318318
if mdc.datasource_selector() == 'auto':
319319
# create the data source or find existing based on pSConfig template
320320
mdc_var_obj["grafana_datasource_name"], mdc_var_obj["grafana_datasource"] = self._select_gf_datasource(expanded_archives)
321+
elif mdc.datasource_selector() == 'manual' and mdc.datasource_name():
322+
#use the manally defined datasource in the display config
323+
mdc_var_obj["grafana_datasource_name"] = mdc.datasource_name()
324+
mdc_var_obj["grafana_datasource"] = self.grafana_datasource_by_name.get(mdc.datasource_name(), None)
325+
if not mdc_var_obj["grafana_datasource"]:
326+
self.logger.warn(self.logf.format("'datasource_selector' is not auto and grafana_datasource_name '{}' does not exist on Grafana server. Skipping.".format(mdc.datasource_name())))
327+
continue
321328
elif mdc.datasource_selector() == 'manual' and self.grafana_datasource:
322329
#use the manally defined datasource in the agent config
323330
mdc_var_obj["grafana_datasource"] = self.grafana_datasource

psconfig/perfsonar-psconfig/psconfig/grafana/config.py

+3
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ def task_selector(self, val=None):
126126
def datasource_selector(self, val=None):
127127
return self._field_enum('datasource_selector', val, [ "auto", "manual" ])
128128

129+
def datasource_name(self, val=None):
130+
return self._field('datasource_name', val)
131+
129132
def priority(self, val=None):
130133
return self._field_class('priority', Priority, val)
131134

psconfig/perfsonar-psconfig/psconfig/grafana/schema.py

+4
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ def psconfig_grafana_json_schema(self):
192192
"enum": [ "auto", "manual" ],
193193
"description": "Define how to determine the data source to use. 'auto' means it will try to detrmine an archive based on pSConfig template and will fallback to the default defined by grafana-datasource-name. 'manual' means it will just use grafana-datasource-name. "
194194
},
195+
"datasource_name": {
196+
"type": "string",
197+
"description": "If datasource_selector is manual, then the name of the data source to use. If datasource_selector is auto then this is ignored. If datasource_selector is manual and this is not set, then the global grafana-datasource-name will be used."
198+
},
195199
"priority": {
196200
"$ref": "#/pSConfig/Priority",
197201
"description": "Priority of display."

0 commit comments

Comments
 (0)