informer

package module
v0.0.0-...-9b8d2ae Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: Apache-2.0 Imports: 1 Imported by: 0

README

Informer

Go library for exposing program metadata, version and build information.

TL;DR

See the example directory. That directory is an example of how a package that uses Informer might look.

cd example/
ls
# cmd  doc.go  example  info.go  Makefile
make
# CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-s -X "github.com/cisco-cx/informer/example.Program=example" -X "github.com/cisco-cx/informer/example.License=Apache-2.0" -X "github.com/cisco-cx/informer/example.URL=https://github.com/cisco-cx/informer/example" -X "github.com/cisco-cx/informer/example.BuildUser=vagrant" -X "github.com/cisco-cx/informer/example.BuildDate=2019-09-18T19:50:30+0000" -X "github.com/cisco-cx/informer/example.Version=f2211ec" -X "github.com/cisco-cx/informer/example.Revision=f2211ec" -X "github.com/cisco-cx/informer/example.Branch=master"' ./cmd/example
ls -l example
# -rwxr-xr-x 1 vagrant vagrant 1423424 Sep 18 19:50 example
./example
# (metadata=(program=example, license=Apache-2.0, url=https://github.com/cisco-cx/informer/example), versionInfo=(version=f2211ec, branch=master, revision=f2211ec), buildInfo=(language=go, languageVersion=go1.12.7, user=vagrant, date=2019-09-18T19:50:30+0000))

Usage

  • Step 1: Define global variables at the root (or other) package of your project.
  • Step 2: Import the package you used in Step 1 in a cmd (or other) package.
  • Step 3: Pass in values for your global variables at build time using ldflags.
  • Step 4: Call v1.NewInfoService and pass in your global vars as args to it.
  • Step 5: Use the various methods on the informer.InfoService interface as you wish.

Metrics

Excerpt of an HTTP GET response from a program that implements the Informer pattern:

# TYPE program_info gauge
program_info{branch="master",build_date="2019-09-18T19:50:30+0000",build_user="vagrant",language="go",language_version="go1.12.7",license="Apache-2.0",program="example",revision="f2211ec",url="https://github.com/cisco-cx/informer/example",version="f2211ec"} 1

Roadmap

  • Demonstrate the optional InfoCollector in the example directory.
  • Use the shared mock package in v1_test package.

Credit

This project is inspired by:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InfoCollector

type InfoCollector interface {
	// NewCollector returns a collector that exports metrics about current InfoService information.
	NewCollector() *prometheus.GaugeVec
}

InformerCollector is an optional extension to InfoService that represents the ability to expose metadata, build and version information as a metrics collector.

type InfoService

type InfoService interface {
	// BuildInfo returns build information as a string.
	BuildInfo() string

	// Metadata returns metadata as a string.
	Metadata() string

	// String returns metadata, build and version information as a string.
	String() string

	// VersionInfo returns version information as a string.
	VersionInfo() string
}

InfoService is a domain interface that represents a service for exposing build and version information.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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