internalmetrics

package
v1.71.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: Apache-2.0 Imports: 2 Imported by: 69

Documentation

Overview

Package internalmetrics provides functionality to collect Prometheus metrics.

Index

Constants

This section is empty.

Variables

View Source
var Metrics = MetricsType{
	GraphNodes: prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "kiali_graph_nodes",
			Help: "The number of nodes in a generated graph.",
		},
		[]string{labelGraphKind, labelGraphType, labelWithServiceNodes},
	),
	GraphGenerationTime: prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "kiali_graph_generation_duration_seconds",
			Help: "The time required to generate a graph.",
		},
		[]string{labelGraphKind, labelGraphType, labelWithServiceNodes},
	),
	GraphAppenderTime: prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "kiali_graph_appender_duration_seconds",
			Help: "The time required to execute an appender while generating a graph.",
		},
		[]string{labelAppender},
	),
	GraphMarshalTime: prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "kiali_graph_marshal_duration_seconds",
			Help: "The time required to marshal and return the JSON for a graph.",
		},
		[]string{labelGraphKind, labelGraphType, labelWithServiceNodes},
	),
	APIProcessingTime: prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "kiali_api_processing_duration_seconds",
			Help: "The time required to execute a particular REST API route request.",
		},
		[]string{labelRoute},
	),
	PrometheusProcessingTime: prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "kiali_prometheus_processing_duration_seconds",
			Help: "The time required to execute a Prometheus query.",
		},
		[]string{labelQueryGroup},
	),
	KubernetesClients: prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "kiali_kubernetes_clients",
			Help: "The number of Kubernetes clients in use.",
		},
		[]string{},
	),
	APIFailures: prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "kiali_api_failures_total",
			Help: "Counts the total number of failures encountered by a particular API handler.",
		},
		[]string{labelRoute},
	),
	CheckerProcessingTime: prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "kiali_checker_processing_duration_seconds",
			Help: "The time required to execute a validation checker.",
		},
		[]string{labelCheckerName},
	),
	ValidationProcessingTime: prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "kiali_validation_processing_duration_seconds",
			Help: "The time required to execute a full validation check on a namespace or service.",
		},
		[]string{labelNamespace, labelService},
	),
	SingleValidationProcessingTime: prometheus.NewHistogramVec(
		prometheus.HistogramOpts{
			Name: "kiali_single_validation_processing_duration_seconds",
			Help: "The time required to execute a validation check on a single Istio object.",
		},
		[]string{labelNamespace, labelType, labelName},
	),
}

Metrics contains all of Kiali's own internal metrics. These metrics can be accessed directly to update their values, or you can use available utility functions defined below.

Functions

func GetAPIFailureMetric added in v1.36.0

func GetAPIFailureMetric(route string) prometheus.Counter

func GetAPIProcessingTimePrometheusTimer

func GetAPIProcessingTimePrometheusTimer(apiRouteName string) *prometheus.Timer

GetAPIProcessingTimePrometheusTimer returns a timer that can be used to store a value for the API processing time metric. The timer is ticking immediately when this function returns. Typical usage is as follows:

promtimer := GetAPIProcessingTimePrometheusTimer(...)
defer promtimer.ObserveDuration()

func GetCheckerProcessingTimePrometheusTimer added in v1.36.4

func GetCheckerProcessingTimePrometheusTimer(checkerName string) *prometheus.Timer

GetCheckerProcessingTimePrometheusTimer returns a timer that can be used to store a value for the validation checker processing time metric. The timer is ticking immediately when this function returns.

Typical usage is as follows:

promtimer := GetCheckerProcessingTimePrometheusTimer(...)
... execute the validation check ...
promtimer.ObserveDuration()

func GetGraphAppenderTimePrometheusTimer

func GetGraphAppenderTimePrometheusTimer(appenderName string) *prometheus.Timer

GetGraphAppenderTimePrometheusTimer returns a timer that can be used to store a value for the graph appender time metric. The timer is ticking immediately when this function returns. Typical usage is as follows:

promtimer := GetGraphAppenderTimePrometheusTimer(...)
... run the appender ...
promtimer.ObserveDuration()

func GetGraphGenerationTimePrometheusTimer

func GetGraphGenerationTimePrometheusTimer(graphKind string, graphType string, withServiceNodes bool) *prometheus.Timer

GetGraphGenerationTimePrometheusTimer returns a timer that can be used to store a value for the graph generation time metric. The timer is ticking immediately when this function returns. Typical usage is as follows:

promtimer := GetGraphGenerationTimePrometheusTimer(...)
defer promtimer.ObserveDuration()

func GetGraphMarshalTimePrometheusTimer

func GetGraphMarshalTimePrometheusTimer(graphKind string, graphType string, withServiceNodes bool) *prometheus.Timer

GetGraphMarshalTimePrometheusTimer returns a timer that can be used to store a value for the graph marshal time metric. The timer is ticking immediately when this function returns. Typical usage is as follows:

promtimer := GetGraphMarshalTimePrometheusTimer(...)
defer promtimer.ObserveDuration()

func GetPrometheusProcessingTimePrometheusTimer

func GetPrometheusProcessingTimePrometheusTimer(queryGroup string) *prometheus.Timer

GetPrometheusProcessingTimePrometheusTimer returns a timer that can be used to store a value for the Prometheus query processing time metric. The timer is ticking immediately when this function returns.

Note that the queryGroup parameter is simply some string that can be used to identify a particular set of Prometheus queries. This queryGroup does not necessarily have to identify a unique query (indeed, if you do that, that might cause too many timeseries to be collected), but it only needs to identify a set of queries. For example, perhaps there is a group of similar Prometheus queries used to generate a graph - in this case, the processing time for all of those queries can be combined into a single metric timeseries by passing in a queryGroup of "Graph-Generation".

Typical usage is as follows:

promtimer := GetPrometheusProcessingTimePrometheusTimer(...)
... execute the query ...
promtimer.ObserveDuration()

func GetSingleValidationProcessingTimePrometheusTimer added in v1.36.4

func GetSingleValidationProcessingTimePrometheusTimer(namespace string, objectType string, objectName string) *prometheus.Timer

GetSingleValidationProcessingTimePrometheusTimer returns a timer that can be used to store a value for the single validation processing time metric (time to validate a specific Istio object in a specific namespace. The timer is ticking immediately when this function returns.

Typical usage is as follows:

promtimer := GetSingleValidationProcessingTimePrometheusTimer(...)
... execute the validation check ...
promtimer.ObserveDuration()

func GetValidationProcessingTimePrometheusTimer added in v1.36.4

func GetValidationProcessingTimePrometheusTimer(namespace string, service string) *prometheus.Timer

GetValidationProcessingTimePrometheusTimer returns a timer that can be used to store a value for the validation processing time metric (time to validate a namespace or service). The timer is ticking immediately when this function returns.

When service is an empty string, it means this timer will track how long it took to validate all services within the namespace.

Typical usage is as follows:

promtimer := GetValidationProcessingTimePrometheusTimer(...)
... execute the validation checks ...
promtimer.ObserveDuration()

func RegisterInternalMetrics

func RegisterInternalMetrics()

RegisterInternalMetrics must be called at startup to prepare the Prometheus scrape endpoint.

func SetGraphNodes

func SetGraphNodes(graphKind string, graphType string, withServiceNodes bool, nodeCount int)

SetGraphNodes sets the node count metric

func SetKubernetesClients added in v0.17.0

func SetKubernetesClients(clientCount int)

SetKubernetesClients sets the kubernetes client count

Types

type MetricsType

type MetricsType struct {
	GraphNodes                     *prometheus.GaugeVec
	GraphGenerationTime            *prometheus.HistogramVec
	GraphAppenderTime              *prometheus.HistogramVec
	GraphMarshalTime               *prometheus.HistogramVec
	APIProcessingTime              *prometheus.HistogramVec
	PrometheusProcessingTime       *prometheus.HistogramVec
	KubernetesClients              *prometheus.GaugeVec
	APIFailures                    *prometheus.CounterVec
	CheckerProcessingTime          *prometheus.HistogramVec
	ValidationProcessingTime       *prometheus.HistogramVec
	SingleValidationProcessingTime *prometheus.HistogramVec
}

MetricsType defines all of Kiali's own internal metrics.

type SuccessOrFailureMetricType

type SuccessOrFailureMetricType struct {
	*prometheus.Timer
	prometheus.Counter
}

SuccessOrFailureMetricType let's you capture metrics for both successes and failures, where successes are tracked using a duration histogram and failures are tracked with a counter. Typical usage is:

func SomeFunction(...) (..., err error) {
	sof := GetSuccessOrFailureMetricTypeObject()
	defer sof.ObserveNow(&err)
	... do the work of SomeFunction here...
}

If a function doesn't support returning an error, then call ObserveDuration directly:

func SomeFunction(...) (...) {
	sof := GetSuccessOrFailureMetricTypeObject()
	defer sof.ObserveDuration()
	... do the work of SomeFunction here...
}

If a function doesn't support returning an error, but you still need to report a failure, call Inc() directly to increment the failure counter:

func SomeFunction(...) (...) {
	sof := GetSuccessOrFailureMetricTypeObject()
	defer func() { if (somethingBadHappened) { sof.Inc() } else { sof.ObserveDuration() }}()
	... do the work of SomeFunction here...
}

func (*SuccessOrFailureMetricType) ObserveNow

func (sof *SuccessOrFailureMetricType) ObserveNow(err *error)

ObserveNow will observe a duration unless *err is not nil in which case the error counter will be incremented instead. We use a pointer to err because this function is normally invoked via 'defer' and so the actual value of the error won't be set until the actual invocation of this function. (read the docs on 'defer' if you don't get it).

Jump to

Keyboard shortcuts

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