question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document the use of Templating

See original GitHub issue

What you expected to happen?

I attempted to use add templating to a dashboard, it is not documented how to use it so I provided these parameters: https://github.com/aknuds1/grafanalib/blob/master/grafanalib/core.py#L431-L439

        :param default: the default value for the variable
        :param dataSource: where to fetch the values for the variable from
        :param label: the variable's human label
        :param name: the variable's name
        :param query: the query users to fetch the valid values of the variable
        :param allValue: specify a custom all value with regex,
            globs or lucene syntax.
        :param includeAll: Add a special All option whose value includes
            all options.

What happened?

Js error in grafana when trying to import the resulting json dashboard. After some effort I determined that the js error is caued by the absence of some of these values for each template: https://github.com/aknuds1/grafanalib/blob/master/grafanalib/core.py#L456-L470

    def to_json_data(self):
        return {**_as_dict(self), **{
            'current': {
                'text': self.default,
                'value': self.default,
                'tags': [],
            },
            'hide': 0,
            'multi': False,
            'options': [],
            'refresh': 1,
            'regex': '',
            'sort': 1,
            'tagValuesQuery': None,
            'tagsQuery': None,
            'type': 'query',
        }}

I’m not very familiar with python but that bit of code looks like it should be used as defaults? In any case, when I include those keys/values for each templated variable in my dashboard.py, the resulting json generated does work!

How to reproduce it?

Create any dashboard that uses the templating, i.e.:

  templating=Templating(list=[
    { # namespace
      "default": "",
      "datasource": "prometheus",
      "label": "Namespace",
      "name": "namespace",
      "query": "label_values(kube_pod_info, namespace)",
      "allValue": ".+",
      "includeAll": True,
    },
  ]),

Is this a bug with how templating gets rendered? If not, can you add the proper incantation to use templating in the example dashboard.py?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisflemingcommented, Aug 13, 2021

I’m still checking this out - but I think I’ve found the problem, in my experimentation, it looks like ‘selected’ has to be set to either True or False to get things working https://github.com/chrisfleming/grafanalib/commit/0589cb5e67084e9c63669514d3efa267b44cbcc4

I’ve a few more checks but should have a pull request next week.

0reactions
JamesGibocommented, Sep 14, 2021

Could templating still be improved with some better docs? Or do we think this issue can be closed?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create effective document templates | Zapier
Let's dive in and cover how you can build templates for some common file types, like text documents, presentations, project checklists, and emails....
Read more >
Word 2010: Using a Template - GCF Global
A template is a predesigned document you can use to create documents quickly without having to think about formatting. With a template, many...
Read more >
Save a Word document as a template - Microsoft Support
Create and save a custom template from a new or existing document. ... To use content controls, you must convert the document to...
Read more >
What is a template? - TechTarget
A template is a form, mold or pattern used as a guide to make something. Here are some examples of templates: Website design;...
Read more >
How to Create a Template in Word - CustomGuide
1. Click the File tab. 2. Click New. 3. Search or browse for a template.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found