Grizzly Documentation

repository·main·Indexed 20 days ago

https://github.com/grafana-cold-storage/grizzly

Grizzly is a CLI tool (grr) for managing observability resources—including Grafana dashboards, datasources, alert/recording rules, and Prometheus alerts—as code. It facilitates GitOps and CI/CD integration by allowing users to pull, edit, diff, and apply resource definitions. Note: Grizzly is marked for deprecation and will be superseded by grafanactl.

Tokens
20.5K
Snippets
100
Records
125
Agent score
68%

What's inside grizzly

  1. Overview of Grizzly capabilities

    main

    Grizzly is a command line tool designed to manage observability resources as code. It allows you to define resources like dashboards, alerting rules, and recording rules within your codebase, enabling integration into continuous deployment (CD) pipelines. This ensures that observability configurations are updated automatically whenever your application is deployed.

    Supported Providers and Resources

    Grafana

    • Alerting contact points
    • Alerting notification templates
    • Alerting notification policy
    • Alert rule groups
    • Dashboards
    • Dashboard folders
    • Datasources
    • Library elements

    Prometheus

    • Alerts
    • Recording rules

    Grafana Synthetic Monitoring

    • Monitoring Checks
  2. Use the Grizzly Provider for Grafana Resources

    main

    The pkg/grafana package provides a Grizzly provider that includes a suite of Handlers designed to manage various Grafana resources. You can use these Handlers to programmatically manage the lifecycle of observability components within Grafana.

    Supported resource types include:

    • Dashboards
    • Datasources
    • Alert and Recording Rules
    • Synthetic Monitoring Checks
  3. Manage Grafana resources with Grizzly

    main
    Grizzly is a command-line utility designed to bring software engineering best practices—such as version control, code reviews, and CI/CD—to Grafana resources like dashboards and datasources. It enables workflows for pulling resources into files, editing them via a WYSIWYG interface, validating them, and publishing them back to Grafana instances or migrating them between instances.
  4. Hide elements in Jsonnet using the double colon operator

    main

    In Jsonnet, you can use the :: operator to define "hidden" elements. Elements defined with :: are internal to the script and will not be visible in the final rendered output. This is useful for defining intermediate data structures, libraries, or logic that should only be accessed by other parts of the script via reference.

    grizzly_alerts:: {
      rules: [...]
    }
  5. How Hugo template types work

    main

    Hugo uses different template types to determine how content is rendered:

    • Home Page Template: Used only for the site's root page (e.g., layouts/index.html).
    • Single Templates: Used to generate output for an individual content file (e.g., single.html).
    • List Templates: Used to group multiple pieces of content together (e.g., list.html).

    Template Selection Logic: When Hugo renders a piece of content, it searches for a template using the content's section or type. It follows this priority:

    1. A template matching the specific section or type (e.g., post/single.html).
    2. A template in the _default/ directory (e.g., _default/single.html).
  6. Use Hugo Template Types: Single, List, and Partial

    main

    Hugo uses templates to bridge content and presentation. Templates define what content is published, where it is published, and how it is rendered to HTML. There are three main types:

    • Single Template: Used to render a single piece of content, such as an individual article or post.
    • List Template: Used to render a group of related content, such as a list of recent posts or category archives. The Home Page is a special type of list template.
    • Partial Template: Small, reusable templates that can be included in other templates using the partial template command. These are ideal for common elements like banners or footers to avoid code duplication.

    Template Resolution Logic: Hugo searches for templates by looking for an exact match for the content. If no match is found, it shifts up one level in the directory hierarchy and continues searching until it finds a match or reaches the default site template. You can also use front matter to influence which template Hugo selects.

  7. Configure Hugo Site Settings

    main

    Hugo uses a configuration file to override default site settings. The file can be written in TOML, YAML, or JSON. Hugo determines the format based on the file extension.

    Common configuration tasks include:

    • Specifying alternate locations for the content/ directory.
    • Specifying alternate locations for the themes/ directory.
    • Defining where the public/ output directory should be located.

    Note: If you use YAML or JSON instead of TOML, ensure you rename the file extension accordingly (e.g., config.yaml or config.json).

  8. Basic Syntax of Go Templates

    main

    Go templates are HTML files that use double curly braces {{ }} to embed variables and functions.

    • Variables/Functions: Accessed via {{ variable_name }} or {{ function_name arg1 arg2 }}.
    • Parameters: Separated by spaces.
    • Dot Notation: Used to access methods and fields (e.g., {{ .Params.bar }}).
    • Grouping: Use parentheses to group expressions, such as in complex conditionals.
    <!-- Accessing a variable -->
    {{ foo }}
    
    <!-- Calling a function with parameters -->
    {{ add 1 2 }}
    
    <!-- Accessing fields via dot notation -->
    {{ .Params.bar }}
    
    <!-- Grouping with parentheses -->
    {{ if or (isset .Params "alt") (isset .Params "caption") }} Caption {{ end }}
  9. Configure Grizzly using Contexts

    main

    Grizzly uses 'contexts' (similar to kubectl) to manage multiple configurations, making it ideal for workstation use where you switch between different environments (e.g., staging vs. production). By default, Grizzly uses the default context.

    Important Note on Precedence: Environment variables take precedence over context settings. If you have existing environment variables set, they will prevent Grizzly from using your context configurations. You can import your current environment variables into the default context using grr config import, but you should unset the environment variables afterward to ensure context settings are respected.

    # Create a new context
    grr config create-context production
    
    # Switch to a different context
    grr use-context staging
    
    # List all existing contexts
    grr config get-contexts
    
    # Show the currently active context
    grr config current-context
    
    # Import current environment variables into the default context
    grr config import
  10. Understand the Context (the dot)

    main

    The dot . represents the current context.

    Crucial Behavior: The value of . changes inside loops or with blocks. Inside a range loop, . refers to the current item in the iteration, not the global page data. To access global data (like the site title) inside a loop, you must assign it to a variable before entering the loop.

    {{ $title := .Site.Title }}
    {{ range .Params.tags }}
      <!-- Inside the loop, '.' is the tag, not the site. We use '$title' to access the site title -->
      <a href="{{ . | urlize }}">{{ . }}</a> - {{ $title }}
    {{ end }}