Help us shape the future of Go! Take the 2026 Go Developer Survey

prometheusadapter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package prometheusadapter counts authentication outcomes as Prometheus metrics, on a registry the caller passes in. It is the only package of the library that imports client_golang: the providers report outcomes through an auth.Observer, and OutcomeCounter.Observe is one.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	Registerer prometheus.Registerer // required; the caller's registry, never the default one
	Namespace  string                // required, e.g. "forwardauth"; the metric is <Namespace>_auth_outcomes_total
}

Options configure an OutcomeCounter.

type OutcomeCounter

type OutcomeCounter struct {
	// contains filtered or unexported fields
}

OutcomeCounter counts authentication outcomes in <namespace>_auth_outcomes_total{provider,action,result}. The label values are closed sets: provider instance names, auth.Action and auth.Result. It is safe for concurrent use.

func New

func New(options *Options) (*OutcomeCounter, error)

New registers <namespace>_auth_outcomes_total on options.Registerer and returns the counter. A failed registration (e.g. a duplicate) is returned as an error, never panicked.

Example

The counter's Observe method is an auth.Observer: pass it (or a closure calling it next to ginadapter.Observe) as the Observer option of a provider, a session.Guard or an apikey.Authenticator.

package main

import (
	"context"
	"fmt"

	"github.com/prometheus/client_golang/prometheus"
	"github.com/prometheus/client_golang/prometheus/testutil"

	"github.com/govengers/auth"
	"github.com/govengers/auth/prometheusadapter"
)

func main() {
	registry := prometheus.NewRegistry() // built in main and served on the metrics port
	counter, err := prometheusadapter.New(&prometheusadapter.Options{Registerer: registry, Namespace: "billing"})
	if err != nil {
		fmt.Println(err)
		return
	}
	var observer auth.Observer = counter.Observe

	observer(context.Background(), auth.Outcome{Provider: "session", Action: auth.ActionAuthenticate, Result: auth.ResultSuccess})

	count, err := testutil.GatherAndCount(registry, "billing_auth_outcomes_total")
	fmt.Println(count, err)
}
Output:
1 <nil>

func (*OutcomeCounter) Observe

func (c *OutcomeCounter) Observe(_ context.Context, outcome auth.Outcome)

Observe has the auth.Observer shape: it counts outcome under its provider, action and result.

Jump to

Keyboard shortcuts

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