pkg/metrics
Victor Agababov 92c9752a4c
Add RecordN method to permit recording of N measurements simultaneously. (#1025)
* Add RecordN method to permit recording of N measurements simultaneously.

In serving we have many places where we try to record several metrics at the same time.
Besides very repetetive code, this also brings inefficiences, since metrics code has to do _some_ work
for every call, which is completely avoidable.

This way we can record N measurements with one hit.

* tests and nits

* review items per discussion with Evan:

- remove ros
- make measurements ...

* review
2020-01-31 11:26:28 -08:00
..
metricskey Add metrics for Knative Certificate creation count (#976) 2020-01-06 15:57:49 -08:00
metricstest Switch *testing.T uses to equivalent interface + structured logging (#935) 2019-12-13 10:22:54 -08:00
testing Migrate pkg to use the knative.dev/pkg import path (#489) 2019-06-26 13:02:06 -07:00
OWNERS Update OWNERS to use OWNERS_ALIASES (#422) 2019-05-29 20:04:33 -07:00
README.md Format markdown (#981) 2020-01-08 07:19:53 -08:00
client.go Hook into two other Kubernetes metric subsystems. (#682) 2019-09-16 10:46:43 -07:00
client_test.go Hook into two other Kubernetes metric subsystems. (#682) 2019-09-16 10:46:43 -07:00
config.go Add RecordN method to permit recording of N measurements simultaneously. (#1025) 2020-01-31 11:26:28 -08:00
config_observability.go Add default metrics backend to observability config (#994) 2020-01-14 23:08:06 -08:00
config_observability_test.go Add default metrics backend to observability config (#994) 2020-01-14 23:08:06 -08:00
config_test.go Allow to specify default exporter option when updating from ConfigMap (#1006) 2020-01-22 15:34:23 -08:00
doc.go add metrics constants for resource type and labels (#168) 2018-11-21 14:17:21 -08:00
exporter.go Allow to specify default exporter option when updating from ConfigMap (#1006) 2020-01-22 15:34:23 -08:00
exporter_test.go Upgrade OpenCensus Stackdriver exporter (#865) 2019-12-03 14:12:37 -08:00
gcp_metadata.go Add field to metrics config for configuring Stackdriver exporter client (#794) 2019-10-25 10:28:36 -07:00
memstats.go Expose Go memstats as metrics. (#711) 2019-09-21 00:07:08 -07:00
memstats_test.go Expose Go memstats as metrics. (#711) 2019-09-21 00:07:08 -07:00
metrics.go Update our dependency on K8s libs to 1.15.3 (#686) 2019-09-18 13:36:48 -07:00
monitored_resources.go Eventing Stackdriver integration (#612) 2019-08-30 09:13:49 -07:00
monitored_resources_eventing.go Upgrade OpenCensus Stackdriver exporter (#865) 2019-12-03 14:12:37 -08:00
monitored_resources_serving.go Upgrade OpenCensus Stackdriver exporter (#865) 2019-12-03 14:12:37 -08:00
opencensus_exporter.go Add support for OpenCensus Agent as a destination for Knative metrics. (#978) 2020-01-10 18:42:58 -08:00
prometheus_exporter.go Update opencensus to a newer version (#526) 2019-07-12 16:18:48 -07:00
prometheus_exporter_test.go Migrate pkg to use the knative.dev/pkg import path (#489) 2019-06-26 13:02:06 -07:00
record.go Add RecordN method to permit recording of N measurements simultaneously. (#1025) 2020-01-31 11:26:28 -08:00
record_test.go Add RecordN method to permit recording of N measurements simultaneously. (#1025) 2020-01-31 11:26:28 -08:00
reflector.go Hook into two other Kubernetes metric subsystems. (#682) 2019-09-16 10:46:43 -07:00
reflector_test.go Hook into two other Kubernetes metric subsystems. (#682) 2019-09-16 10:46:43 -07:00
stackdriver_exporter.go Upgrade OpenCensus Stackdriver exporter (#865) 2019-12-03 14:12:37 -08:00
stackdriver_exporter_test.go Upgrade OpenCensus Stackdriver exporter (#865) 2019-12-03 14:12:37 -08:00
utils.go Initial StatsReporter for Source (#648) 2019-09-10 13:12:29 -07:00
workqueue.go Update our dependency on K8s libs to 1.15.3 (#686) 2019-09-18 13:36:48 -07:00
workqueue_test.go Update our dependency on K8s libs to 1.15.3 (#686) 2019-09-18 13:36:48 -07:00
zz_generated.deepcopy.go update boilerplate to use 2020 (#979) 2020-01-07 16:04:51 -08:00

README.md

Common metrics export interfaces for Knative

Note that this directory is currently in transition. See the Plan for details on where this is heading.

Current status

The code currently uses OpenCensus to support exporting metrics to multiple backends. Currently, two backends are supported: Prometheus and Stackdriver.

Metrics export is controlled by a ConfigMap called config-observability which is a key-value map with specific values supported for each of the Stackdriver and Prometheus backends. Hot-reload of the ConfigMap on a running process is supported by directly watching (via the Kubernetes API) the config-observability object. Configuration via environment is also supported for use by the queue-proxy, which runs with user permissions in the user's namespace.

Problems

There are currently 6 supported Golang exporters for OpenCensus. At least the Stackdriver exporter causes problems/failures if started without access to (Google) application default credentials. It's not clear that we want to build all of those backends into the core of knative.dev/pkg and all downstream dependents, and we'd like all the code shipped in knative.dev/pkg to be able to be tested without needing any special environment setup.

With the current direct-integration setup, there needs to be initial and ongoing work in pkg (which should be high-value, low-churn code) to maintain and update stats exporters which need to be statically linked into ~all Knative binaries. This setup also causes problems for vendors who may want or need to perform an out-of-tree integration (e.g. proprietary or partially-proprietary monitoring stacks).

Another problem is that each vendor's exporter requires different parameters, supplied as Golang Options methods which may require complex connections with the Knative ConfigMap. Two examples of this are secrets like API keys and the Prometheus monitoring port (which requires additional service/etc wiring).

See also this doc, where the plan was worked out.

The plan

OpenCensus (and eventually OpenTelemetry) offers an sidecar or host-level agent with speaks the OpenCensus protocol and can proxy from this protocol to multiple backends.

OpenCensus Agent configuration (From OpenCensus Documentation)

We will standardize on export to the OpenCensus export protocol, and encourage vendors to implement their own OpenCensus Agent or Collector DaemonSet, Sidecar, or other OpenCensus Protocol service which connects to their desired monitoring environment. For now, we will use the config-observability ConfigMap to provide the OpenCensus endpoint, but we will work with the OpenTelemetry group to define a kubernetes-friendly standard export path.

Additionally, once OpenTelemetry agent is stable, we will propose adding the OpenTelemetry agent running on a localhost port as part of the runtime contract.

We need to make sure that the OpenCensus library does not block, fail, or queue metrics in-process excessively in the case where the OpenCensus Agent is not present on the cluster. This will allow us to ship Knative components which attempt to reach out the Agent if present, and which simply retain local statistics for a short period of time if not.

Concerns

  • Unsure about the stability of the OpenCensus Agent (or successor). We're currently investigating this, but the OpenCensus agent seems to have been recommended by several others.
  • Running fluentd as a sidecar was very big (400MB) and had a large impact on cold start times.
    • Mitigation: run the OpenCensus agent as a DaemonSet (like we do with fluentd now).
  • Running as a DaemonSet may make it more difficult to ensure that metrics for each namespace end up in the right place.
    • We have this problem with the built-in configurations today, so this doesn't make the problem substantially worse.
    • May want/need some connection between the Agent and the Kubelet to verify sender identities eventually.
    • Only expose OpenCensus Agent on localhost, not outside the node.

Steps to reach the goal

  • Add OpenCensus Agent as one of the export options.
  • Ensure that all tests pass in a non-Google-Cloud connected environment. This is true today. Ensure this on an ongoing basis.
  • Google to implement OpenCensus Agent configuration to match what they are doing for Stackdriver now. (No public issue link because this shoud be in Google's vendor-specific configuration.)
  • Document how to configure OpenCensus/OpenTelemetry Agent + Prometheus to achieve the current level of application visibility, and determine a long-term course for how to maintain this as a "bare minimum" supported configuration.
  • Stop adding exporter features outside of the OpenCensus / OpenTelemetry export as of 0.13 release (03 March 2020). Between now and 0.13, small amounts of additional features can be built in to assist with the bridging process or to support existing products. New products should build on the OpenCensus Agent approach.