grafana / kairosdb-datasource

Data source plugin for KairosDB
Apache License 2.0
30 stars 62 forks source link

Multi-value variable with Repeat for each value produces charts with all metrics #71

Open gucharbon opened 6 years ago

gucharbon commented 6 years ago

We're using Grafana to display metrics from KairosDB database.

We are using Grafana in Docker. Our Dockerfile is as follows:

ARG GRAFANA_VERSION="latest"
FROM grafana/grafana:${GRAFANA_VERSION}

ARG KAIROS_DATASOURCE_BRANCH="master"
# To use with git clone --single-branch -b ${KAIROS_DATSOURCE_BRANCH}
# --branch can also take tags and detaches the HEAD at that commit in the resulting repository.
# See https://git-scm.com/docs/git-clone

USER root

RUN apt-get update && apt-get -y install gnupg2 apt-transport-https lsb-release bzip2 && \
    curl -sL https://deb.nodesource.com/setup_10.x | bash - && \
    apt-get install --no-install-recommends -y git nodejs && \
    cd $GF_PATHS_PLUGINS && \
    git clone --single-branch -b ${KAIROS_DATASOURCE_BRANCH} https://github.com/grafana/kairosdb-datasource && \
    cd kairosdb-datasource && \
    npm install -g grunt-cli && \
    npm install && \
    grunt && \
    apt-get --purge -y autoremove git nodejs gnupg2 bzip2 && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

USER grafana

ARG GF_INSTALL_PLUGINS="grafana-clock-panel,grafana-simple-json-datasource"

RUN if [ ! -z "${GF_INSTALL_PLUGINS}" ]; then \
    OLDIFS=$IFS; \
        IFS=','; \
    for plugin in ${GF_INSTALL_PLUGINS}; do \
        IFS=$OLDIFS; \
        grafana-cli --pluginsDir "$GF_PATHS_PLUGINS" plugins install ${plugin}; \
    done; \
fi

We use variables to query metrics with regex:

image

We then created a chart panel repeating for each value of variable:

bug_grafana_kairos_chart_panel

We filled the panel Metrics options as follow:

image

When selecting only one variable, everything is working fine:

image

But when we select more than 1 metric, all metrics are displayed on all charts (and only first one uses alias)

image

I didn't use Grafana before but I'm quite sure that I saw dashboards using such features and working fine ! Can you confirm that I'm not misusing any feature ? This issue is mentionned in How reference a multi-variable on alias #66

jifwin commented 6 years ago

Hi

Thanks for the Dockerfile, it's really useful. Please check out the fix on "fix-metric-name-templating" branch. If it works for you, I'll merge it to master.

gucharbon commented 6 years ago

It seems that your fix is working !

I will be templating dashboards all day long so I'll come by to you if I encounter any suspicious behavior that might have been introduced with this fix.

Thanks a lot, and do not hesitate to share this Dockerfile in the README for example. I will edit so that we have full control on which version is installed like in this build:

docker build --build-arg GRAFANA_VERSION="latest" --build-arg KAIROS_DATASOURCE_BRANCH="fix-metric-name-templating" -t grafana:kairosds-fix-metric-name-templating .

gucharbon commented 6 years ago

Do you plan to merge the branch ? I've been using it since you created it and it is definetly working fine. Btw I'm still looking for a fix for Issue 67 but unfortunately I'm no JavaScript developer so it will take me some time to understand how to do that :)