Documentation ¶
Overview ¶
Package metrics provides Knative utilities for exporting metrics to Stackdriver backend or Prometheus backend based on config-observability settings.
Index ¶
- Constants
- func Buckets125(low, high float64) []float64
- func ConfigMapName() string
- func Domain() string
- func FlushExporter() bool
- func GetKnativeBrokerMonitoredResource(v *view.View, tags []tag.Tag, gm *gcpMetadata) ([]tag.Tag, monitoredresource.Interface)
- func GetKnativeImporterMonitoredResource(v *view.View, tags []tag.Tag, gm *gcpMetadata) ([]tag.Tag, monitoredresource.Interface)
- func GetKnativeRevisionMonitoredResource(v *view.View, tags []tag.Tag, gm *gcpMetadata) ([]tag.Tag, monitoredresource.Interface)
- func GetKnativeTriggerMonitoredResource(v *view.View, tags []tag.Tag, gm *gcpMetadata) ([]tag.Tag, monitoredresource.Interface)
- func Record(ctx context.Context, ms stats.Measurement)
- func UpdateExporter(ops ExporterOptions, logger *zap.SugaredLogger) error
- func UpdateExporterFromConfigMap(component string, logger *zap.SugaredLogger) func(configMap *corev1.ConfigMap)
- type ExporterOptions
- type Global
- type KnativeBroker
- type KnativeImporter
- type KnativeRevision
- type KnativeTrigger
Constants ¶
const ( DomainEnv = "METRICS_DOMAIN" ConfigMapNameEnv = "CONFIG_OBSERVABILITY_NAME" )
const ( // The following keys are used to configure metrics reporting. // See https://github.com/knative/serving/blob/master/config/config-observability.yaml // for details. AllowStackdriverCustomMetricsKey = "metrics.allow-stackdriver-custom-metrics" BackendDestinationKey = "metrics.backend-destination" ReportingPeriodKey = "metrics.reporting-period-seconds" StackdriverProjectIDKey = "metrics.stackdriver-project-id" // Stackdriver is used for Stackdriver backend Stackdriver metricsBackend = "stackdriver" // Prometheus is used for Prometheus backend Prometheus metricsBackend = "prometheus" )
Variables ¶
This section is empty.
Functions ¶
func Buckets125 ¶
Buckets125 generates an array of buckets with approximate powers-of-two buckets that also aligns with powers of 10 on every 3rd step. This can be used to create a view.Distribution.
func ConfigMapName ¶
func ConfigMapName() string
ConfigMapName gets the name of the metrics ConfigMap
func FlushExporter ¶
func FlushExporter() bool
FlushExporter waits for exported data to be uploaded. This should be called before the process shuts down or exporter is replaced. Return value indicates whether the exporter is flushable or not.
func Record ¶
func Record(ctx context.Context, ms stats.Measurement)
Record decides whether to record one measurement via OpenCensus based on the following conditions:
- No package level metrics config. In this case it just proxies to OpenCensus based on the assumption that users expect the metrics to be recorded when they call this function. Users must ensure metrics config are set before using this function to get expected behavior.
- The backend is not Stackdriver.
- The backend is Stackdriver and it is allowed to use custom metrics.
- The backend is Stackdriver and the metric is one of the built-in metrics: "knative_revision", "knative_broker", "knative_trigger", "knative_importer".
func UpdateExporter ¶
func UpdateExporter(ops ExporterOptions, logger *zap.SugaredLogger) error
UpdateExporter updates the exporter based on the given ExporterOptions.
func UpdateExporterFromConfigMap ¶
func UpdateExporterFromConfigMap(component string, logger *zap.SugaredLogger) func(configMap *corev1.ConfigMap)
UpdateExporterFromConfigMap returns a helper func that can be used to update the exporter when a config map is updated.
Types ¶
type ExporterOptions ¶
type ExporterOptions struct { // Domain is the metrics domain. e.g. "knative.dev". Must be present. Domain string // Component is the name of the component that emits the metrics. e.g. // "activator", "queue_proxy". Should only contains alphabets and underscore. // Must be present. Component string // PrometheusPort is the port to expose metrics if metrics backend is Prometheus. // It should be between maxPrometheusPort and maxPrometheusPort. 0 value means // using the default 9090 value. If is ignored if metrics backend is not // Prometheus. PrometheusPort int // ConfigMap is the data from config map config-observability. Must be present. // See https://github.com/knative/serving/blob/master/config/config-observability.yaml // for details. ConfigMap map[string]string }
ExporterOptions contains options for configuring the exporter.
type KnativeBroker ¶
type KnativeBroker struct { Project string Location string ClusterName string NamespaceName string BrokerName string }
func (*KnativeBroker) MonitoredResource ¶
func (kb *KnativeBroker) MonitoredResource() (resType string, labels map[string]string)
type KnativeImporter ¶
type KnativeImporter struct { Project string Location string ClusterName string NamespaceName string ImporterName string ImporterResourceGroup string }
func (*KnativeImporter) MonitoredResource ¶
func (ki *KnativeImporter) MonitoredResource() (resType string, labels map[string]string)
type KnativeRevision ¶
type KnativeRevision struct { Project string Location string ClusterName string NamespaceName string ServiceName string ConfigurationName string RevisionName string }
func (*KnativeRevision) MonitoredResource ¶
func (kr *KnativeRevision) MonitoredResource() (resType string, labels map[string]string)
type KnativeTrigger ¶
type KnativeTrigger struct { Project string Location string ClusterName string NamespaceName string TriggerName string BrokerName string TypeFilterAttribute string SourceFilterAttribute string }
func (*KnativeTrigger) MonitoredResource ¶
func (kt *KnativeTrigger) MonitoredResource() (resType string, labels map[string]string)