Coder Social home page Coder Social logo

mixtool's Introduction

mixtool

NOTE: This project is alpha stage. Flags, configuration, behavior and design may change significantly in following releases.

The mixtool is a helper for easily working with jsonnet mixins.

Install

Make sure you're using golang v1.17 or higher, and run:

go install github.com/monitoring-mixins/mixtool/cmd/mixtool@main

Usage

All command line flags:

NAME:
   mixtool - Improves your jsonnet mixins workflow

USAGE:
   mixtool [global options] command [command options] [arguments...]

VERSION:
   v0.1.0-pre

DESCRIPTION:
   mixtool helps with generating, building and linting jsonnet mixins

COMMANDS:
   generate  Generate manifests from jsonnet input
   lint      Lint jsonnet files
   new       Create new jsonnet mixin files
   server    Start a server to provision Prometheus rule file(s) with.
   list      List all available mixins
   install   Install a mixin
   help, h   Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help
   --version, -v  print the version

Generate

NAME:
   mixtool generate - Generate manifests from jsonnet input

USAGE:
   mixtool generate command [command options] [arguments...]

COMMANDS:
   alerts      Generate Prometheus alerts based on the mixins
   rules       Generate Prometheus rules based on the mixins
   dashboards  Generate Grafana dashboards based on the mixins
   all         Generate all resources - Prometheus alerts, Prometheus rules and Grafana dashboards

OPTIONS:
   --help, -h  show help
   

New

NAME:
   mixtool new - Create new files for Prometheus alerts & rules and Grafana dashboards as jsonnet mixin

USAGE:
   mixtool new command [command options] [arguments...]

COMMANDS:
   grafana-dashboard  Create a new file with a Grafana dashboard mixin inside
   prometheus-alerts  Create a new file with Prometheus alert mixins inside
   prometheus-rules   Create a new file with Prometheus rule mixins inside

OPTIONS:
   --help, -h  show help
   

New Examples

mixtool new grafana-dashboard > my-dashboard.jsonnet
mixtool new prometheus-alerts > my-alerts.jsonnet
mixtool new prometheus-rules > my-rules.jsonnet

Lint

NAME:
   mixtool lint - Lint jsonnet files

USAGE:
   mixtool lint [command options] [arguments...]

DESCRIPTION:
   Lint jsonnet files for correct structure of JSON objects

OPTIONS:
   --grafana                Lint Grafana dashboards against Grafana's schema
   --prometheus             Lint Prometheus alerts and rules and their given expressions
   --jpath value, -J value  Add folders to be used as vendor folders
   

Lint Examples

# This will lint the file for Prometheus alerts & rules and Grafana dashboards.
mixtool lint prometheus.jsonnet

# Don't lint Grafana dashboards.
mixtool lint --grafana=false prometheus.jsonnet

# Don't lint Prometheus alerts & rules.
mixtool lint --prometheus=false prometheus.jsonnet

# Lint multiple files sequentially.
mixtool lint prometheus.jsonnet grafana.jsonnet

mixtool's People

Contributors

allenmqcymp avatar brancz avatar callumj avatar clyang82 avatar dasomeone avatar dependabot[bot] avatar krajorama avatar metalmatze avatar mshahzeb avatar renovate[bot] avatar rgeyer avatar superq avatar tomwilkie avatar v-zhuravlev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mixtool's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

circleci
.circleci/config.yml
  • cimg/go 1.22
github-actions
.github/workflows/golangci-lint.yml
  • actions/checkout v4
  • actions/setup-go v5
  • golangci/golangci-lint-action v6.0.1
gomod
go.mod
  • go 1.22
  • go 1.22.3
  • github.com/fatih/color v1.16.0
  • github.com/grafana/dashboard-linter v0.0.0-20240506202110-49d8cc29d8fc@49d8cc29d8fc
  • github.com/gobuffalo/packr/v2 v2.8.3
  • github.com/google/go-jsonnet v0.20.0
  • github.com/grafana/tanka v0.26.0
  • github.com/jsonnet-bundler/jsonnet-bundler v0.5.1
  • github.com/pkg/errors v0.9.1
  • github.com/stretchr/testify v1.9.0
  • github.com/invopop/yaml v0.3.1
  • github.com/urfave/cli v1.22.15

  • Check this box to trigger a request for Renovate to run again on this repository

Not able to install mixtool to get cortex dashboards

I am trying to get Cortex block storage dashboards from https://github.com/grafana/cortex-jsonnet/tree/master/cortex-mixin/dashboards and i am trying to replicate the steps in https://github.com/grafana/cortex-jsonnet#monitoring-for-cortex. While installing mixtool, i am not able to get the module. I am getting the following error. This issue is covered here in #27, but I am getting the same problem last cited.

Here is what i am seeing!

➜  Documents GO111MODULE=on go get -u github.com/monitoring-mixins/mixtool/cmd/mixtool
go: found github.com/monitoring-mixins/mixtool/cmd/mixtool in github.com/monitoring-mixins/mixtool v0.0.0-20210104103825-ae18e31161ea
go: github.com/mattn/go-colorable upgrade => v0.1.8
go: golang.org/x/sys upgrade => v0.0.0-20210124154548-22da62e12c0c
go: github.com/Unknwon/com upgrade => v1.0.1
go: github.com/imdario/mergo upgrade => v0.3.11
go: github.com/mattn/go-isatty upgrade => v0.0.12
go: golang.org/x/crypto upgrade => v0.0.0-20201221181555-eec23a3978ad
go: github.com/rogpeppe/go-internal upgrade => v1.7.0
go: github.com/stretchr/objx upgrade => v0.3.0
go: github.com/russross/blackfriday/v2 upgrade => v2.1.0
go: github.com/urfave/cli upgrade => v1.22.5
go: github.com/uber/jaeger-lib upgrade => v2.4.0+incompatible
go: gopkg.in/yaml.v2 upgrade => v2.4.0
go: github.com/golang/protobuf upgrade => v1.4.3
go: sigs.k8s.io/yaml upgrade => v1.2.0
go: golang.org/x/tools upgrade => v0.1.0
go: go.uber.org/atomic upgrade => v1.7.0
go: github.com/fatih/color upgrade => v1.10.0
go: github.com/pkg/errors upgrade => v0.9.1
go: github.com/davecgh/go-spew upgrade => v1.1.1
go: golang.org/x/lint upgrade => v0.0.0-20201208152925-83fdc39ff7b5
go: google.golang.org/protobuf upgrade => v1.25.0
go: golang.org/x/sync upgrade => v0.0.0-20201207232520-09787c993a3a
go: github.com/spf13/cast upgrade => v1.3.1
go: github.com/gosimple/slug upgrade => v1.9.0
go: github.com/mitchellh/copystructure upgrade => v1.1.1
go: github.com/opentracing/opentracing-go upgrade => v1.2.0
go: github.com/gobuffalo/packd upgrade => v1.0.0
go: gopkg.in/macaron.v1 upgrade => v1.4.0
go: github.com/google/go-jsonnet upgrade => v0.17.0
go: github.com/prometheus/client_golang upgrade => v1.9.0
go: github.com/prometheus/common upgrade => v0.15.0
go: github.com/go-logfmt/logfmt upgrade => v0.5.0
go: github.com/cpuguy83/go-md2man/v2 upgrade => v2.0.0
go: github.com/Masterminds/semver/v3 upgrade => v3.1.1
go: github.com/prometheus/client_model upgrade => v0.2.0
go: github.com/google/uuid upgrade => v1.2.0
go: github.com/teris-io/shortid upgrade => v0.0.0-20201117134242-e59966efd125
go: github.com/ghodss/yaml upgrade => v1.0.0
go: github.com/grafana/grafana upgrade => v6.1.6+incompatible
go: github.com/bradfitz/gomemcache upgrade => v0.0.0-20190913173617-a41fca850d0b
go: github.com/prometheus/procfs upgrade => v0.4.1
go: github.com/inconshreveable/log15 upgrade => v0.0.0-20201112154412-8562bdadbbac
go: github.com/lib/pq upgrade => v1.9.0
go: github.com/go-kit/kit upgrade => v0.10.0
go: github.com/go-sql-driver/mysql upgrade => v1.5.0
go: github.com/golang/snappy upgrade => v0.0.2
go: github.com/beorn7/perks upgrade => v1.0.1
go: gopkg.in/ini.v1 upgrade => v1.62.0
go: github.com/mitchellh/reflectwalk upgrade => v1.0.1
go: github.com/Masterminds/goutils upgrade => v1.1.1
go: github.com/go-macaron/session upgrade => v1.0.2
go: github.com/Masterminds/semver upgrade => v1.5.0
go: github.com/gobuffalo/envy upgrade => v1.9.0
go: github.com/go-macaron/inject upgrade => v0.0.0-20200308113650-138e5925c53b
go: github.com/huandu/xstrings upgrade => v1.3.2
go: gopkg.in/yaml.v3 upgrade => v3.0.0-20210107192922-496545a6307b
go: github.com/Masterminds/sprig/v3 upgrade => v3.2.2
go: github.com/grafana/tanka upgrade => v0.14.0
go get: github.com/Unknwon/[email protected] updating to
	github.com/Unknwon/[email protected]: parsing go.mod:
	module declares its path as: github.com/unknwon/com
	        but was required as: github.com/Unknwon/com

Fail to create new prometheus-alerts

Running command to create prometheus-alerts fails with the following error:

$ mixtool new prometheus-alerts > my-alerts.jsonnet                                                                                              
2020/09/07 11:24:47 failed to create file : open : no such file or directory

Without output redirect, gives the same error:

$ mixtool new prometheus-alerts                                                                                                      
2020/09/07 11:25:07 failed to create file : open : no such file or directory

I've installed mixtool via go get -u github.com/monitoring-mixins/mixtool/cmd/mixtool, here are some additional details:

$ mixtool -v                                                                                                                                                 
mixtool version 0.0.0

$ go version                                                                                                                                   
go version go1.15 darwin/amd64

Can't retrieve mixtool using go get

Hi,
i try to retrieve mixtool, i've got this error :

$ go version
go version go1.15.3 linux/amd64
$ go get -u github.com/monitoring-mixins/mixtool/cmd/mixtool
# github.com/monitoring-mixins/mixtool/cmd/mixtool
golang/src/github.com/monitoring-mixins/mixtool/cmd/mixtool/generate.go:32:22: cannot use cli.StringSliceFlag literal (type cli.StringSliceFlag) as type cli.Flag in slice literal:
        cli.StringSliceFlag does not implement cli.Flag (Apply method has pointer receiver)
golang/src/github.com/monitoring-mixins/mixtool/cmd/mixtool/generate.go:35:3: undefined: cli.BoolTFlag
golang/src/github.com/monitoring-mixins/mixtool/cmd/mixtool/generate.go:44:15: cannot use cli.Command literal (type cli.Command) as type *cli.Command in slice literal
golang/src/github.com/monitoring-mixins/mixtool/cmd/mixtool/generate.go:47:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in append:
        cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
golang/src/github.com/monitoring-mixins/mixtool/cmd/mixtool/generate.go:55:15: cannot use cli.Command literal (type cli.Command) as type *cli.Command in slice literal
golang/src/github.com/monitoring-mixins/mixtool/cmd/mixtool/generate.go:58:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in append:
        cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
golang/src/github.com/monitoring-mixins/mixtool/cmd/mixtool/generate.go:66:15: cannot use cli.Command literal (type cli.Command) as type *cli.Command in slice literal
golang/src/github.com/monitoring-mixins/mixtool/cmd/mixtool/generate.go:69:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in append:
        cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
golang/src/github.com/monitoring-mixins/mixtool/cmd/mixtool/generate.go:77:15: cannot use cli.Command literal (type cli.Command) as type *cli.Command in slice literal
golang/src/github.com/monitoring-mixins/mixtool/cmd/mixtool/generate.go:80:18: cannot use cli.StringFlag literal (type cli.StringFlag) as type cli.Flag in append:
        cli.StringFlag does not implement cli.Flag (Apply method has pointer receiver)
golang/src/github.com/monitoring-mixins/mixtool/cmd/mixtool/generate.go:77:15: too many errors

Any idea ?
what do you think about provides binaries from releases ?

Check for recording rules with ranges too short for a given scrape interval

The dashboard linter checks that rate/irate/increase queries use the Grafana $__rate_interval to ensure that the ranges are large enough to capture sufficient datapoints to calculate.

However, in recording rules, the ranges must be hardcoded, and can be too short for a given scrape interval.

The linting of recording rules should allow some way to specify a target scrape interval, and warn when the range is too small to produce a result.

Grafana "OK" errors

The latest version is reporting linting errors for "OK"

$ mixtool lint mixin.libsonnet 
[panel-rate-interval-rule] 'MySQL': OK
[panel-rate-interval-rule] 'MySQL': OK
[panel-rate-interval-rule] 'MySQL': OK
[panel-rate-interval-rule] 'MySQL': OK
[panel-rate-interval-rule] 'MySQL': OK
[panel-rate-interval-rule] 'MySQL': OK
...
[panel-promql-rule] 'MySQL': OK
2022/02/28 15:28:15 failed to lint the file mixin.libsonnet: 163 lint errors found

Find a better name for the mixtool

Maybe we can find a better name for the mixtool.
Let's discuss.

@mxinden wants the name to better reflect the circumstances that this tool is mostly for monitoring related mixins (correct me if I'm wrong). Should we adapt to that? Maybe we can try to be open for contributions for non-monitoring related tasks / commands / objects?

Earlier in the project I named it locally jsonnet-mixer to match the naming of the jsonnet-bundler but having the jb and jm as command line tools, doesn't feel right.

Please always think about the name for the project itself, but also about how we could name it on the CLI.

/cc @brancz @s-urbaniak @squat @ant31

Support for mixins with Jsonnet external-variables

It is possible to generate mixins using jsonnet external variables, but not possible to use mixtool with those jsonnet files:

gitpod /workspace/observability $ mixtool lint monitoring-satellite/main.jsonnet 
RUNTIME ERROR: Undefined external variable: remote_write_url
        monitoring-satellite/main.jsonnet:11:7-37       builtin function <extVar>
        monitoring-satellite/main.jsonnet:89:57-59
        <std>:1293:24-25        thunk from <function <anonymous>>
        <std>:1293:5-33 function <anonymous>
        monitoring-satellite/main.jsonnet:89:40-77      $

        2:16-58 thunk <mixin> from <$>
        4:21-26 thunk from <$>
        <std>:1302:21-22        thunk from <function <anonymous>>
        <std>:1302:5-32 function <anonymous>
        4:4-47  $
        During evaluation

RUNTIME ERROR: Undefined external variable: remote_write_url
        monitoring-satellite/main.jsonnet:11:7-37       builtin function <extVar>
        monitoring-satellite/main.jsonnet:89:57-59
        <std>:1293:24-25        thunk from <function <anonymous>>
        <std>:1293:5-33 function <anonymous>
        monitoring-satellite/main.jsonnet:89:40-77      $

        2:16-58 thunk <mixin> from <$>
        4:21-26 thunk from <$>
        <std>:1302:21-22        thunk from <function <anonymous>>
        <std>:1302:5-32 function <anonymous>
        4:4-48  $
        During evaluation

2021/05/12 18:58:19 failed to lint the file monitoring-satellite/main.jsonnet: 2 lint errors found

It would be nice if we could run for example:

mixtool lint --ext-str remote_write_url='my-remote-backend-url' monitoring-satellite/main.jsonnet 

Formally define and document the mixin spec

AFAIKT, there is no formal, documented "spec" for the format of a mixin.

It is implicitly defined by the eval methods, and discussed abstractly in these docs (which coincidentally should also be updated).

This is related to #36 which discusses the fact that typical jsonnet constructs are not natively supported (namely Top-level arguments and external variables).

In addition to supporting those (and all other?) jsonnet constructs, the mixin spec should be formalized and documented.

Linting false positives

Issue # 1
Getting error with dashboard linter: "[template-job-rule] 'Asterisk - Overview': Dashboard 'Asterisk - Overview' job template should use datasource '$datasource'" for the json dashboard attached.
asterisk-overview.json.zip

The linter expects datasource to be "$datasource" however copying JSON from Grafana sets this variable as "${datasource}"

Issue # 2
[template-job-rule] 'Asterisk - Overview': Dashboard 'Asterisk - Overview' job template should be a labelled 'job'

If you look at the dashboard JSON file - the job temlpate already has a label.

Installation issue

GO111MODULE=on go get -u github.com/monitoring-mixins/mixtool/cmd/mixtool

go: downloading github.com/monitoring-mixins/mixtool v0.0.0-20210817124007-bca30663e83c


go get: installing executables with 'go get' in module mode is deprecated.
Use 'go install pkg@version' instead.
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.

Could you please provide other way to install?

Don't overwrite existing files when creating new from templates

Currently the mixtool will overwrite file that already exists (even after changes where made)

Reproducing

mixtool generate prometheus-alerts /tmp/example.libsonnet
Make some changes and then run again:
mixtool generate prometheus-alerts /tmp/example.libsonnet
Changes are now lost.

Remove vendor

go.mod should provide sufficient stability guarantees for not keeping vendor around. We don't have a vendor folder on Grafana Tanka and did not run into any issues.

Not having vendor benefits pull requests, because it keeps them smaller and eaiser to review.

Thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.