promlinter

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 9 Imported by: 8

README

promlinter

A linter for checking Prometheus metrics name via promlint.

usage

Installation

Go Get

go get github.com/yeya24/promlinter/cmd/promlinter

Download from release

Please go to https://github.com/yeya24/promlinter/releases.

Build from source
Requirements
  • Go >= 1.13
  • make
git clone https://github.com/yeya24/promlinter.git
make build

Then you can find the promlinter binary file in the ./bin directory.

Usage

usage: promlinter [<flags>] <command> [<args> ...]

Prometheus metrics linter for Go code.

This tool can cover most of the patterns of metrics naming issues, but it cannot detect metric values that can only be determined in the runtime.

By default it doesn't output parsing failures, if you want to see them, you can add --strict flag to enable it.

It is also supported to disable the lint functions using repeated flag --disable. Current supported functions are:

  [Help]: Help detects issues related to the help text for a metric.

  [MetricUnits]: MetricUnits detects issues with metric unit names.

  [Counter]: Counter detects issues specific to counters, as well as patterns that should only be used with counters.

  [HistogramSummaryReserved]: HistogramSummaryReserved detects when other types of metrics use names or labels reserved for use by histograms and/or summaries.

  [MetricTypeInName]: MetricTypeInName detects when metric types are included in the metric name.

  [ReservedChars]: ReservedChars detects colons in metric names.

  [CamelCase]: CamelCase detects metric names and label names written in camelCase.

  [UnitAbbreviations]: UnitAbbreviations detects abbreviated units in the metric name.

Flags:
  -h, --help     Show context-sensitive help (also try --help-long and --help-man).
      --version  Show application version.

Commands:
  help [<command>...]
    Show help.

  list [<flags>] [<files>...]
    List metrics name.

  lint [<flags>] [<files>...]
    Lint metrics via promlint.

Run tests

make test

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LintFuncNames []string
)

Functions

This section is empty.

Types

type Issue

type Issue struct {
	Text   string
	Metric string
	Pos    token.Position
}

Issue contains metric name, error text and metric position.

func RunLint

func RunLint(fs *token.FileSet, files []*ast.File, s Setting) []Issue

type MetricFamilyWithPos

type MetricFamilyWithPos struct {
	MetricFamily *dto.MetricFamily
	Pos          token.Position
}

func RunList

func RunList(fs *token.FileSet, files []*ast.File, strict bool) []MetricFamilyWithPos

func (*MetricFamilyWithPos) Labels added in v0.3.0

func (m *MetricFamilyWithPos) Labels() []string

type Setting

type Setting struct {
	Strict            bool
	DisabledLintFuncs []string
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL