| 12345678910111213141516171819202122232425262728293031323334353637 |
- package prom
- import (
- "strings"
- prometheus "github.com/prometheus/client_golang/api"
- )
- const (
- // PrometheusClientID is the identifier used when creating the client that
- // targets prometheus. This can be used to check a specific client instance
- // by calling prom.IsClientID(client, prom.PrometheusClientID)
- PrometheusClientID string = "Prometheus"
- )
- // identityClient provides an interface for extracting an indentifer from the client objects
- type identityClient interface {
- ID() string
- }
- // IsClientID returns true if the client has an identifier of the specific type.
- func IsClientID(cli prometheus.Client, id string) bool {
- if cli == nil {
- return false
- }
- if idClient, ok := cli.(identityClient); ok {
- return strings.EqualFold(idClient.ID(), id)
- }
- return false
- }
- // IsPrometheus returns true if the client provided is used to target prometheus
- func IsPrometheus(cli prometheus.Client) bool {
- return IsClientID(cli, PrometheusClientID)
- }
|