Skip to content

Commit

Permalink
Adding support for multiple data sources in psconfig grafana agent
Browse files Browse the repository at this point in the history
  • Loading branch information
arlake228 committed Sep 19, 2024
1 parent 8555128 commit cc8a156
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@
"enum": [ "auto", "manual" ],
"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. "
},
"datasource_name": {
"type": "string",
"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."
},
"priority": {
"$ref": "#/pSConfig/Priority",
"description": "Priority of display."
Expand Down
7 changes: 7 additions & 0 deletions psconfig/perfsonar-psconfig/psconfig/grafana/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ def _run_handle_psconfig(self, psconfig, agent_conf, remote=None):
if mdc.datasource_selector() == 'auto':
# create the data source or find existing based on pSConfig template
mdc_var_obj["grafana_datasource_name"], mdc_var_obj["grafana_datasource"] = self._select_gf_datasource(expanded_archives)
elif mdc.datasource_selector() == 'manual' and mdc.datasource_name():
#use the manally defined datasource in the display config
mdc_var_obj["grafana_datasource_name"] = mdc.datasource_name()
mdc_var_obj["grafana_datasource"] = self.grafana_datasource_by_name.get(mdc.datasource_name(), None)
if not mdc_var_obj["grafana_datasource"]:
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())))
continue
elif mdc.datasource_selector() == 'manual' and self.grafana_datasource:
#use the manally defined datasource in the agent config
mdc_var_obj["grafana_datasource"] = self.grafana_datasource
Expand Down
3 changes: 3 additions & 0 deletions psconfig/perfsonar-psconfig/psconfig/grafana/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ def task_selector(self, val=None):
def datasource_selector(self, val=None):
return self._field_enum('datasource_selector', val, [ "auto", "manual" ])

def datasource_name(self, val=None):
return self._field('datasource_name', val)

def priority(self, val=None):
return self._field_class('priority', Priority, val)

Expand Down
4 changes: 4 additions & 0 deletions psconfig/perfsonar-psconfig/psconfig/grafana/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ def psconfig_grafana_json_schema(self):
"enum": [ "auto", "manual" ],
"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. "
},
"datasource_name": {
"type": "string",
"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."
},
"priority": {
"$ref": "#/pSConfig/Priority",
"description": "Priority of display."
Expand Down

0 comments on commit cc8a156

Please sign in to comment.