metrics

package
v1.40.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MetricParser = &resourceparser.Parser{
	Name: "Metric",

	InterestingImports: []paths.Pkg{"encore.dev/metrics"},
	Run: func(p *resourceparser.Pass) {
		var (
			names []pkginfo.QualifiedName
			specs = make(map[pkginfo.QualifiedName]*parseutil.ReferenceSpec)
		)
		for _, c := range metricConstructors {
			name := pkginfo.QualifiedName{PkgPath: "encore.dev/metrics", Name: c.FuncName}
			names = append(names, name)

			numTypeArgs := 1
			if c.HasLabels {
				numTypeArgs = 2
			}

			c := c
			parseFn := func(d parseutil.ReferenceInfo) {
				parseMetric(c, d)
			}

			spec := &parseutil.ReferenceSpec{
				MinTypeArgs: numTypeArgs,
				MaxTypeArgs: numTypeArgs,
				Parse:       parseFn,
			}
			specs[name] = spec
		}

		parseutil.FindPkgNameRefs(p.Pkg, names, func(file *pkginfo.File, name pkginfo.QualifiedName, stack []ast.Node) {
			spec := specs[name]
			parseutil.ParseReference(p, spec, parseutil.ReferenceData{
				File:         file,
				Stack:        stack,
				ResourceFunc: name,
			})
		})
	},
}

Functions

This section is empty.

Types

type Label

type Label struct {
	Key  string
	Type schema.BuiltinType
	Doc  string
}

func (Label) String

func (l Label) String() string

type Metric

type Metric struct {
	AST  *ast.CallExpr
	Name string     // The unique name of the metric
	Doc  string     // The documentation on the metric
	Type MetricType // the type of metric it is

	// File is the file the metric is declared in.
	File *pkginfo.File

	// LabelType is the label type of the metric,
	// if the metric is a group.
	LabelType option.Option[schema.Type]

	// Labels is the list of parsed labels.
	Labels []Label

	ValueType schema.BuiltinType

	// The struct literal for the config. Used to inject additional configuration
	// at compile-time.
	ConfigLiteral *ast.CompositeLit
}

func (*Metric) ASTExpr

func (m *Metric) ASTExpr() ast.Expr

func (*Metric) End

func (m *Metric) End() token.Pos

func (*Metric) Kind

func (m *Metric) Kind() resource.Kind

func (*Metric) Package

func (m *Metric) Package() *pkginfo.Package

func (*Metric) Pos

func (m *Metric) Pos() token.Pos

func (*Metric) ResourceName

func (m *Metric) ResourceName() string

func (*Metric) SortKey added in v1.16.3

func (m *Metric) SortKey() string

type MetricType

type MetricType int
const (
	Counter MetricType = iota
	Gauge
)

func (MetricType) String

func (i MetricType) String() string

Jump to

Keyboard shortcuts

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