Repository: knative/pkg
Pull request #1635 (2020-08-19 20:08:36)

Add collector address to be used by queue-proxy

knative-prow-robot: [APPROVALNOTIFIER] This PR is **NOT APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/1635#" title="Author self-approved">jjzeng-seattle</a>*
To complete the [pull request process](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process), please assign **mdemirhan**
You can assign the PR to them by writing `/assign @mdemirhan` in a comment when ready.

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

<details open>
Needs approval from an approver in each of these files:

- **[metrics/OWNERS](https://github.com/knative/pkg/blob/master/metrics/OWNERS)**

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":["mdemirhan"]} -->
yanweiguo: /lgtm
/approve
knative-prow-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/knative/pkg/pull/1635#" title="Author self-approved">jjzeng-seattle</a>*, *<a href="https://github.com/knative/pkg/pull/1635#issuecomment-676647722" title="Approved">yanweiguo</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=knative%2Fpkg).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[metrics/OWNERS](https://github.com/knative/pkg/blob/master/metrics/OWNERS)~~ [yanweiguo]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/metrics/config_observability.go b/metrics/config_observability.go
index d17fba89c..c284a2576 100644
--- a/metrics/config_observability.go
+++ b/metrics/config_observability.go
@@ -63,6 +63,10 @@ type ObservabilityConfig struct {
 
 	// EnableRequestLog enables activator/queue-proxy to write request logs.
 	EnableRequestLog bool
+
+	// MetricsCollectorAddress specifies the metrics collector address. This is only used
+	// when the metrics backend is opencensus.
+	MetricsCollectorAddress string
 }
 
 func defaultConfig() *ObservabilityConfig {
@@ -83,6 +87,7 @@ func NewObservabilityConfigFromConfigMap(configMap *corev1.ConfigMap) (*Observab
 		cm.AsBool("logging.enable-probe-request-log", &oc.EnableProbeRequestLog),
 		cm.AsString("metrics.request-metrics-backend-destination", &oc.RequestMetricsBackend),
 		cm.AsBool("profiling.enable", &oc.EnableProfiling),
+		cm.AsString("metrics.opencensus-address", &oc.MetricsCollectorAddress),
 	); err != nil {
 		return nil, err
 	}


Test patch:
diff --git a/metrics/config_observability_test.go b/metrics/config_observability_test.go
index 6c90f291d..44b2ec5af 100644
--- a/metrics/config_observability_test.go
+++ b/metrics/config_observability_test.go
@@ -103,6 +103,23 @@ func TestObservabilityConfiguration(t *testing.T) {
 			"metrics.request-metrics-backend-destination": "stackdriver",
 			"profiling.enable":                            "true",
 		},
+	}, {
+		name:    "observability configuration with collector address",
+		wantErr: false,
+		wantConfig: &ObservabilityConfig{
+			EnableProbeRequestLog:   false,
+			EnableProfiling:         false,
+			EnableRequestLog:        false,
+			EnableVarLogCollection:  false,
+			LoggingURLTemplate:      DefaultLogURLTemplate,
+			RequestLogTemplate:      "",
+			RequestMetricsBackend:   "opencensus",
+			MetricsCollectorAddress: "otel:55678",
+		},
+		data: map[string]string{
+			"metrics.request-metrics-backend-destination": "opencensus",
+			"metrics.opencensus-address":                  "otel:55678",
+		},
 	}}
 
 	for _, tt := range observabilityConfigTests {