From 4e02d28d47cb3aff1c759e1ab948e9901c2f6651 Mon Sep 17 00:00:00 2001 From: Yao Wu Date: Tue, 20 Nov 2018 11:38:07 -0800 Subject: [PATCH 1/8] add constants for resource type and labels --- metrics/metricsKey/constants.go | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 metrics/metricsKey/constants.go diff --git a/metrics/metricsKey/constants.go b/metrics/metricsKey/constants.go new file mode 100644 index 0000000000..af0447885f --- /dev/null +++ b/metrics/metricsKey/constants.go @@ -0,0 +1,40 @@ +/* +Copyright 2018 The Knative Authors +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package metricsKey + +const ( + // ResourceTypeKnativeRevision is the Stackdriver resource type for Knative revision + ResourceTypeKnativeRevision = "knative_revision" + + // LabelProject is the label for project number (gaia id) + LabelProject = "project" + + // LabelLocation is the label for location where the service is deployed + LabelLocation = "location" + + // LabelClusterName is the label for immutable name of the cluster + LabelClusterName = "cluster_name" + + // LabelNamespaceName is the label for immutable name of the namespace that the service is deployed + LabelNamespaceName = "namespace_name" + + // LabelServiceName is the label for the deployed service name + LabelServiceName = "service_name" + + // LabelConfigurationName is the label for the configuration which created the monitored revision + LabelConfigurationName = "configuration_name" + + // LabelRevisionName is the label for the monitored revision + LabelRevisionName = "revision_name" +) From 121907745f86a77ef61c87bf94b8be38623a8680 Mon Sep 17 00:00:00 2001 From: Yao Wu Date: Tue, 20 Nov 2018 13:00:35 -0800 Subject: [PATCH 2/8] add set and map for easy access --- metrics/metricsKey/constants.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/metrics/metricsKey/constants.go b/metrics/metricsKey/constants.go index af0447885f..42e844cd6e 100644 --- a/metrics/metricsKey/constants.go +++ b/metrics/metricsKey/constants.go @@ -38,3 +38,21 @@ const ( // LabelRevisionName is the label for the monitored revision LabelRevisionName = "revision_name" ) + +var ( + // KnativeRevisionLabels stores the set of resource labels for resource type knative_revision + KnativeRevisionLabels = map[string]struct{}{ + LabelProject: struct{}{}, + LabelLocation: struct{}{}, + LabelClusterName: struct{}{}, + LabelNamespaceName: struct{}{}, + LabelServiceName: struct{}{}, + LabelConfigurationName: struct{}{}, + LabelRevisionName: struct{}{}, + } + + // ResourceTypeToLabelsMap maps resource type to the set of resource labels + ResourceTypeToLabelsMap = map[string]map[string]struct{}{ + ResourceTypeKnativeRevision: KnativeRevisionLabels, + } +) From 0a2c5960f02f63d90eb113b37415a9063a7d0f74 Mon Sep 17 00:00:00 2001 From: Yao Wu Date: Tue, 20 Nov 2018 13:46:30 -0800 Subject: [PATCH 3/8] address cr comments --- metrics/doc.go | 18 ++++++++++++++++++ .../{metricsKey => metricskey}/constants.go | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 metrics/doc.go rename metrics/{metricsKey => metricskey}/constants.go (99%) diff --git a/metrics/doc.go b/metrics/doc.go new file mode 100644 index 0000000000..74a448fc1b --- /dev/null +++ b/metrics/doc.go @@ -0,0 +1,18 @@ +/* +Copyright 2018 The Knative Authors +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +/* +Package metrics provides utilites for exporting metrics to Stackdriver backend +or Prometheus backend based on config-observability settings. +*/ +package metrics diff --git a/metrics/metricsKey/constants.go b/metrics/metricskey/constants.go similarity index 99% rename from metrics/metricsKey/constants.go rename to metrics/metricskey/constants.go index 42e844cd6e..faa50414a5 100644 --- a/metrics/metricsKey/constants.go +++ b/metrics/metricskey/constants.go @@ -11,7 +11,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package metricsKey +package metricskey const ( // ResourceTypeKnativeRevision is the Stackdriver resource type for Knative revision From 16bb97c9e894ff7dbb912b711abc6c35c2ea8f61 Mon Sep 17 00:00:00 2001 From: Yao Wu Date: Tue, 20 Nov 2018 13:48:57 -0800 Subject: [PATCH 4/8] fix typo --- metrics/doc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/doc.go b/metrics/doc.go index 74a448fc1b..5a5605c6ed 100644 --- a/metrics/doc.go +++ b/metrics/doc.go @@ -12,7 +12,7 @@ limitations under the License. */ /* -Package metrics provides utilites for exporting metrics to Stackdriver backend +Package metrics provides utilities for exporting metrics to Stackdriver backend or Prometheus backend based on config-observability settings. */ package metrics From b2f0ffd9adbf433764222bd978b995a1b92c4be4 Mon Sep 17 00:00:00 2001 From: Yao Wu Date: Tue, 20 Nov 2018 14:16:35 -0800 Subject: [PATCH 5/8] Update comment --- metrics/doc.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/metrics/doc.go b/metrics/doc.go index 5a5605c6ed..631bb5966c 100644 --- a/metrics/doc.go +++ b/metrics/doc.go @@ -11,8 +11,6 @@ See the License for the specific language governing permissions and limitations under the License. */ -/* -Package metrics provides utilities for exporting metrics to Stackdriver backend -or Prometheus backend based on config-observability settings. -*/ +// Package metrics provides Knative utilities for exporting metrics to Stackdriver +// backend or Prometheus backend based on config-observability settings. package metrics From 5d568d534da39048defae1348b7be8f5df488a42 Mon Sep 17 00:00:00 2001 From: Yao Wu Date: Tue, 20 Nov 2018 14:31:50 -0800 Subject: [PATCH 6/8] add value unknown --- metrics/metricskey/constants.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/metrics/metricskey/constants.go b/metrics/metricskey/constants.go index faa50414a5..73b5d0b2c3 100644 --- a/metrics/metricskey/constants.go +++ b/metrics/metricskey/constants.go @@ -37,6 +37,9 @@ const ( // LabelRevisionName is the label for the monitored revision LabelRevisionName = "revision_name" + + // ValueUnknown is the default value if the field is unknown + ValueUnknown = "unknown" ) var ( From 48b2d22e914df2df78f1eea0d3f02d0c7ca65459 Mon Sep 17 00:00:00 2001 From: Yao Wu Date: Wed, 21 Nov 2018 11:29:09 -0800 Subject: [PATCH 7/8] Update comments --- metrics/metricskey/constants.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/metrics/metricskey/constants.go b/metrics/metricskey/constants.go index 73b5d0b2c3..f8e44f3dd3 100644 --- a/metrics/metricskey/constants.go +++ b/metrics/metricskey/constants.go @@ -20,7 +20,7 @@ const ( // LabelProject is the label for project number (gaia id) LabelProject = "project" - // LabelLocation is the label for location where the service is deployed + // LabelLocation is the label for location (e.g. GCE zone, AWS region) where the service is deployed LabelLocation = "location" // LabelClusterName is the label for immutable name of the cluster @@ -38,7 +38,8 @@ const ( // LabelRevisionName is the label for the monitored revision LabelRevisionName = "revision_name" - // ValueUnknown is the default value if the field is unknown + // ValueUnknown is the default value if the field is unknown, e.g. project will be unknown if Knative + // is not running on GKE. ValueUnknown = "unknown" ) From cbca2aeebfacc46bfaa358137a29553fbedc8e76 Mon Sep 17 00:00:00 2001 From: Yao Wu Date: Wed, 21 Nov 2018 14:11:41 -0800 Subject: [PATCH 8/8] update comments --- metrics/metricskey/constants.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/metricskey/constants.go b/metrics/metricskey/constants.go index f8e44f3dd3..57d8338a38 100644 --- a/metrics/metricskey/constants.go +++ b/metrics/metricskey/constants.go @@ -17,7 +17,7 @@ const ( // ResourceTypeKnativeRevision is the Stackdriver resource type for Knative revision ResourceTypeKnativeRevision = "knative_revision" - // LabelProject is the label for project number (gaia id) + // LabelProject is the label for project (e.g. GCP GAIA ID, AWS project name) LabelProject = "project" // LabelLocation is the label for location (e.g. GCE zone, AWS region) where the service is deployed