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

services setAlias experiments #1860

Closed
wants to merge 1 commit into from
Closed

Conversation

gabor
Copy link
Contributor

@gabor gabor commented Jul 30, 2024

when you use query_type=metrics, and add the function setAlias($__zbx_host_name: abcd), this will work.
when you do the same for query_type=services, it does not work.

based on some investigation it seems it will not be easy to make it work for query_type=services.

for query_type=metrics this works, because this is executed as a backend-query, and that handler eventually reaches this line:

this.applyFrontendFunctions(resp, request);
,

and applyFrontendFunctions calls setAlias.

when query_type=services, it is not a backend query, so the same code is not called.
instead, we call

async queryITServiceData(target: ZabbixMetricsQuery, timeRange, request) {
, and that codepath does not call applyFrontendFunctions.

in this draft PR, i tried some quick hacks to make things work, you can see i added the applyFrontendFunctions call in datasource.ts.

this will cause setAlias to be called.

but that is not enough.
in setAlias, there is a main IF, which branches based on the field-count, if it's 2 or less, it goes into the first branch. we fall here, but the code looks for a field named Value, which it does not find. so it sets the frame-name and that's all.
my second hack adjusts this, where, if the value-field is not found, it lets the code continue. and this will finally apply the alias.

but that is not enough.
you see, the "happy path", when it works for query_type=metrics, works because of this line:

alias = getTemplateSrv().replace(alias, valueField?.config?.custom?.scopedVars);
... it will use the dataframe field's valueField.config.custom.scopedVars, so that it has access to variables. this way, when you do setAlias($__zbx_host_name...), the value for zbx_host_name is found there (probably, i'm guessing 😁 ). but in our case, there is no such attribute, so while something like setAlias(abcd), will work, setAlias($__zbx_host_name) will not, because it's unable to find that variable's value.

@gabor gabor requested a review from a team as a code owner July 30, 2024 12:23
@gabor
Copy link
Contributor Author

gabor commented Aug 14, 2024

this was only a test and demonstration, closing it now.

@gabor gabor closed this Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant