mirror of https://github.com/knative/caching.git
Auto-update dependencies (#86)
Produced via: `dep ensure -update knative.dev/test-infra knative.dev/pkg` /assign mattmoor
This commit is contained in:
parent
30c1a0fea8
commit
14c30e6f2e
|
@ -927,7 +927,7 @@
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
digest = "1:c695f3415658f521f10bd3c3ed7f9a86433eafb2ca554ba64c2160d05c9633b0"
|
digest = "1:4dbfbd630beb854049c6d436ef47e1e6f07abb75cf66b130cc44dc4a7ce45078"
|
||||||
name = "knative.dev/pkg"
|
name = "knative.dev/pkg"
|
||||||
packages = [
|
packages = [
|
||||||
"apis",
|
"apis",
|
||||||
|
@ -946,7 +946,7 @@
|
||||||
"metrics/metricskey",
|
"metrics/metricskey",
|
||||||
]
|
]
|
||||||
pruneopts = "T"
|
pruneopts = "T"
|
||||||
revision = "0c1c6db1df9ea2343a6dbf1290e4325682fcf85d"
|
revision = "ec2f20ae67fbbccfac425061f2c7c089d1932105"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2019 The Knative Authors
|
Copyright 2019 The Knative Authors
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -18,6 +21,12 @@ import (
|
||||||
"knative.dev/pkg/metrics/metricskey"
|
"knative.dev/pkg/metrics/metricskey"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type gcpMetadata struct {
|
||||||
|
project string
|
||||||
|
location string
|
||||||
|
cluster string
|
||||||
|
}
|
||||||
|
|
||||||
func retrieveGCPMetadata() *gcpMetadata {
|
func retrieveGCPMetadata() *gcpMetadata {
|
||||||
gm := gcpMetadata{
|
gm := gcpMetadata{
|
||||||
project: metricskey.ValueUnknown,
|
project: metricskey.ValueUnknown,
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2018 The Knative Authors
|
Copyright 2018 The Knative Authors
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -13,12 +16,7 @@ limitations under the License.
|
||||||
|
|
||||||
package metricskey
|
package metricskey
|
||||||
|
|
||||||
import "k8s.io/apimachinery/pkg/util/sets"
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// ResourceTypeKnativeRevision is the Stackdriver resource type for Knative revision
|
|
||||||
ResourceTypeKnativeRevision = "knative_revision"
|
|
||||||
|
|
||||||
// LabelProject is the label for project (e.g. GCP GAIA ID, AWS project name)
|
// LabelProject is the label for project (e.g. GCP GAIA ID, AWS project name)
|
||||||
LabelProject = "project_id"
|
LabelProject = "project_id"
|
||||||
|
|
||||||
|
@ -31,49 +29,7 @@ const (
|
||||||
// LabelNamespaceName is the label for immutable name of the namespace that the service is deployed
|
// LabelNamespaceName is the label for immutable name of the namespace that the service is deployed
|
||||||
LabelNamespaceName = "namespace_name"
|
LabelNamespaceName = "namespace_name"
|
||||||
|
|
||||||
// LabelServiceName is the label for the deployed service name
|
|
||||||
LabelServiceName = "service_name"
|
|
||||||
|
|
||||||
// LabelRouteName is the label for immutable name of the route that receives the request
|
|
||||||
LabelRouteName = "route_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"
|
|
||||||
|
|
||||||
// ValueUnknown is the default value if the field is unknown, e.g. project will be unknown if Knative
|
// ValueUnknown is the default value if the field is unknown, e.g. project will be unknown if Knative
|
||||||
// is not running on GKE.
|
// is not running on GKE.
|
||||||
ValueUnknown = "unknown"
|
ValueUnknown = "unknown"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// KnativeRevisionLabels stores the set of resource labels for resource type knative_revision.
|
|
||||||
// LabelRouteName is added as extra label since it is optional, not in this map.
|
|
||||||
KnativeRevisionLabels = sets.NewString(
|
|
||||||
LabelProject,
|
|
||||||
LabelLocation,
|
|
||||||
LabelClusterName,
|
|
||||||
LabelNamespaceName,
|
|
||||||
LabelServiceName,
|
|
||||||
LabelConfigurationName,
|
|
||||||
LabelRevisionName,
|
|
||||||
)
|
|
||||||
|
|
||||||
// KnativeRevisionMetrics stores a set of metric types which are supported
|
|
||||||
// by resource type knative_revision.
|
|
||||||
KnativeRevisionMetrics = sets.NewString(
|
|
||||||
"knative.dev/serving/activator/request_count",
|
|
||||||
"knative.dev/serving/activator/request_latencies",
|
|
||||||
"knative.dev/serving/autoscaler/desired_pods",
|
|
||||||
"knative.dev/serving/autoscaler/requested_pods",
|
|
||||||
"knative.dev/serving/autoscaler/actual_pods",
|
|
||||||
"knative.dev/serving/autoscaler/stable_request_concurrency",
|
|
||||||
"knative.dev/serving/autoscaler/panic_request_concurrency",
|
|
||||||
"knative.dev/serving/autoscaler/target_concurrency_per_pod",
|
|
||||||
"knative.dev/serving/autoscaler/panic_mode",
|
|
||||||
"knative.dev/serving/revision/request_count",
|
|
||||||
"knative.dev/serving/revision/request_latencies",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
|
@ -0,0 +1,107 @@
|
||||||
|
/*
|
||||||
|
Copyright 2019 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
|
||||||
|
|
||||||
|
import "k8s.io/apimachinery/pkg/util/sets"
|
||||||
|
|
||||||
|
// TODO should be moved to eventing. See https://github.com/knative/pkg/issues/608
|
||||||
|
|
||||||
|
const (
|
||||||
|
// ResourceTypeKnativeTrigger is the Stackdriver resource type for Knative Triggers.
|
||||||
|
ResourceTypeKnativeTrigger = "knative_trigger"
|
||||||
|
|
||||||
|
// ResourceTypeKnativeBroker is the Stackdriver resource type for Knative Brokers.
|
||||||
|
ResourceTypeKnativeBroker = "knative_broker"
|
||||||
|
|
||||||
|
// ResourceTypeKnativeImporter is the Stackdriver resource type for Knative Importers.
|
||||||
|
ResourceTypeKnativeImporter = "knative_importer"
|
||||||
|
|
||||||
|
// LabelTriggerName is the label for the name of the Trigger.
|
||||||
|
LabelTriggerName = "trigger_name"
|
||||||
|
|
||||||
|
// LabelBrokerName is the label for the name of the Broker.
|
||||||
|
LabelBrokerName = "broker_name"
|
||||||
|
|
||||||
|
// LabelEventType is the label for the name of the event type.
|
||||||
|
LabelEventType = "event_type"
|
||||||
|
|
||||||
|
// LabelEventSource is the label for the name of the event source.
|
||||||
|
LabelEventSource = "event_source"
|
||||||
|
|
||||||
|
// LabelFilterType is the label for the Trigger filter attribute "type".
|
||||||
|
LabelFilterType = "filter_type"
|
||||||
|
|
||||||
|
// LabelFilterSource is the label for the Trigger filter attribute "source".
|
||||||
|
LabelFilterSource = "filter_source"
|
||||||
|
|
||||||
|
// LabelImporterName is the label for the name of the Importer.
|
||||||
|
LabelImporterName = "importer_name"
|
||||||
|
|
||||||
|
// LabelImporterResourceGroup is the name of the Importer CRD.
|
||||||
|
LabelImporterResourceGroup = "importer_resource_group"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// KnativeTriggerLabels stores the set of resource labels for resource type knative_trigger.
|
||||||
|
KnativeTriggerLabels = sets.NewString(
|
||||||
|
LabelProject,
|
||||||
|
LabelLocation,
|
||||||
|
LabelClusterName,
|
||||||
|
LabelNamespaceName,
|
||||||
|
LabelTriggerName,
|
||||||
|
LabelBrokerName,
|
||||||
|
)
|
||||||
|
|
||||||
|
// KnativeTriggerMetrics stores a set of metric types which are supported
|
||||||
|
// by resource type knative_trigger.
|
||||||
|
KnativeTriggerMetrics = sets.NewString(
|
||||||
|
"knative.dev/eventing/trigger/event_count",
|
||||||
|
"knative.dev/eventing/trigger/event_processing_latencies",
|
||||||
|
"knative.dev/eventing/trigger/event_dispatch_latencies",
|
||||||
|
)
|
||||||
|
|
||||||
|
// KnativeBrokerLabels stores the set of resource labels for resource type knative_broker.
|
||||||
|
KnativeBrokerLabels = sets.NewString(
|
||||||
|
LabelProject,
|
||||||
|
LabelLocation,
|
||||||
|
LabelClusterName,
|
||||||
|
LabelNamespaceName,
|
||||||
|
LabelBrokerName,
|
||||||
|
)
|
||||||
|
|
||||||
|
// KnativeBrokerMetrics stores a set of metric types which are supported
|
||||||
|
// by resource type knative_trigger.
|
||||||
|
KnativeBrokerMetrics = sets.NewString(
|
||||||
|
"knative.dev/eventing/broker/event_count",
|
||||||
|
)
|
||||||
|
|
||||||
|
// KnativeImporterLabels stores the set of resource labels for resource type knative_importer.
|
||||||
|
KnativeImporterLabels = sets.NewString(
|
||||||
|
LabelProject,
|
||||||
|
LabelLocation,
|
||||||
|
LabelClusterName,
|
||||||
|
LabelNamespaceName,
|
||||||
|
LabelImporterName,
|
||||||
|
LabelImporterResourceGroup,
|
||||||
|
)
|
||||||
|
|
||||||
|
// KnativeImporterMetrics stores a set of metric types which are supported
|
||||||
|
// by resource type knative_importer.
|
||||||
|
KnativeImporterMetrics = sets.NewString(
|
||||||
|
"knative.dev/eventing/importer/event_count",
|
||||||
|
)
|
||||||
|
)
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
Copyright 2019 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
|
||||||
|
|
||||||
|
import "k8s.io/apimachinery/pkg/util/sets"
|
||||||
|
|
||||||
|
// TODO should be moved to serving. See https://github.com/knative/pkg/issues/608
|
||||||
|
|
||||||
|
const (
|
||||||
|
// ResourceTypeKnativeRevision is the Stackdriver resource type for Knative revision
|
||||||
|
ResourceTypeKnativeRevision = "knative_revision"
|
||||||
|
|
||||||
|
// LabelServiceName is the label for the deployed service name
|
||||||
|
LabelServiceName = "service_name"
|
||||||
|
|
||||||
|
// LabelRouteName is the label for immutable name of the route that receives the request
|
||||||
|
LabelRouteName = "route_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"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// KnativeRevisionLabels stores the set of resource labels for resource type knative_revision.
|
||||||
|
// LabelRouteName is added as extra label since it is optional, not in this map.
|
||||||
|
KnativeRevisionLabels = sets.NewString(
|
||||||
|
LabelProject,
|
||||||
|
LabelLocation,
|
||||||
|
LabelClusterName,
|
||||||
|
LabelNamespaceName,
|
||||||
|
LabelServiceName,
|
||||||
|
LabelConfigurationName,
|
||||||
|
LabelRevisionName,
|
||||||
|
)
|
||||||
|
|
||||||
|
// KnativeRevisionMetrics stores a set of metric types which are supported
|
||||||
|
// by resource type knative_revision.
|
||||||
|
KnativeRevisionMetrics = sets.NewString(
|
||||||
|
"knative.dev/serving/activator/request_count",
|
||||||
|
"knative.dev/serving/activator/request_latencies",
|
||||||
|
"knative.dev/serving/autoscaler/desired_pods",
|
||||||
|
"knative.dev/serving/autoscaler/requested_pods",
|
||||||
|
"knative.dev/serving/autoscaler/actual_pods",
|
||||||
|
"knative.dev/serving/autoscaler/stable_request_concurrency",
|
||||||
|
"knative.dev/serving/autoscaler/panic_request_concurrency",
|
||||||
|
"knative.dev/serving/autoscaler/target_concurrency_per_pod",
|
||||||
|
"knative.dev/serving/autoscaler/panic_mode",
|
||||||
|
"knative.dev/serving/revision/request_count",
|
||||||
|
"knative.dev/serving/revision/request_latencies",
|
||||||
|
)
|
||||||
|
)
|
|
@ -1,9 +1,12 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2018 The Knative Authors
|
Copyright 2018 The Knative Authors
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -14,40 +17,27 @@ limitations under the License.
|
||||||
package metrics
|
package metrics
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go.opencensus.io/tag"
|
||||||
"knative.dev/pkg/metrics/metricskey"
|
"knative.dev/pkg/metrics/metricskey"
|
||||||
)
|
)
|
||||||
|
|
||||||
type gcpMetadata struct {
|
|
||||||
project string
|
|
||||||
location string
|
|
||||||
cluster string
|
|
||||||
}
|
|
||||||
|
|
||||||
type KnativeRevision struct {
|
|
||||||
Project string
|
|
||||||
Location string
|
|
||||||
ClusterName string
|
|
||||||
NamespaceName string
|
|
||||||
ServiceName string
|
|
||||||
ConfigurationName string
|
|
||||||
RevisionName string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (kr *KnativeRevision) MonitoredResource() (resType string, labels map[string]string) {
|
|
||||||
labels = map[string]string{
|
|
||||||
metricskey.LabelProject: kr.Project,
|
|
||||||
metricskey.LabelLocation: kr.Location,
|
|
||||||
metricskey.LabelClusterName: kr.ClusterName,
|
|
||||||
metricskey.LabelNamespaceName: kr.NamespaceName,
|
|
||||||
metricskey.LabelServiceName: kr.ServiceName,
|
|
||||||
metricskey.LabelConfigurationName: kr.ConfigurationName,
|
|
||||||
metricskey.LabelRevisionName: kr.RevisionName,
|
|
||||||
}
|
|
||||||
return "knative_revision", labels
|
|
||||||
}
|
|
||||||
|
|
||||||
type Global struct{}
|
type Global struct{}
|
||||||
|
|
||||||
func (g *Global) MonitoredResource() (resType string, labels map[string]string) {
|
func (g *Global) MonitoredResource() (resType string, labels map[string]string) {
|
||||||
return "global", nil
|
return "global", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTagsMap(tags []tag.Tag) map[string]string {
|
||||||
|
tagsMap := map[string]string{}
|
||||||
|
for _, t := range tags {
|
||||||
|
tagsMap[t.Key.Name()] = t.Value
|
||||||
|
}
|
||||||
|
return tagsMap
|
||||||
|
}
|
||||||
|
|
||||||
|
func valueOrUnknown(key string, tagsMap map[string]string) string {
|
||||||
|
if value, ok := tagsMap[key]; ok {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
return metricskey.ValueUnknown
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,163 @@
|
||||||
|
/*
|
||||||
|
Copyright 2019 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
|
||||||
|
|
||||||
|
// TODO should be moved to eventing. See https://github.com/knative/pkg/issues/608
|
||||||
|
|
||||||
|
import (
|
||||||
|
"contrib.go.opencensus.io/exporter/stackdriver/monitoredresource"
|
||||||
|
"go.opencensus.io/stats/view"
|
||||||
|
"go.opencensus.io/tag"
|
||||||
|
"knative.dev/pkg/metrics/metricskey"
|
||||||
|
)
|
||||||
|
|
||||||
|
type KnativeTrigger struct {
|
||||||
|
Project string
|
||||||
|
Location string
|
||||||
|
ClusterName string
|
||||||
|
NamespaceName string
|
||||||
|
TriggerName string
|
||||||
|
BrokerName string
|
||||||
|
TypeFilterAttribute string
|
||||||
|
SourceFilterAttribute string
|
||||||
|
}
|
||||||
|
|
||||||
|
type KnativeBroker struct {
|
||||||
|
Project string
|
||||||
|
Location string
|
||||||
|
ClusterName string
|
||||||
|
NamespaceName string
|
||||||
|
BrokerName string
|
||||||
|
}
|
||||||
|
|
||||||
|
type KnativeImporter struct {
|
||||||
|
Project string
|
||||||
|
Location string
|
||||||
|
ClusterName string
|
||||||
|
NamespaceName string
|
||||||
|
ImporterName string
|
||||||
|
ImporterResourceGroup string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kt *KnativeTrigger) MonitoredResource() (resType string, labels map[string]string) {
|
||||||
|
labels = map[string]string{
|
||||||
|
metricskey.LabelProject: kt.Project,
|
||||||
|
metricskey.LabelLocation: kt.Location,
|
||||||
|
metricskey.LabelClusterName: kt.ClusterName,
|
||||||
|
metricskey.LabelNamespaceName: kt.NamespaceName,
|
||||||
|
metricskey.LabelTriggerName: kt.TriggerName,
|
||||||
|
metricskey.LabelBrokerName: kt.BrokerName,
|
||||||
|
}
|
||||||
|
return metricskey.ResourceTypeKnativeTrigger, labels
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kb *KnativeBroker) MonitoredResource() (resType string, labels map[string]string) {
|
||||||
|
labels = map[string]string{
|
||||||
|
metricskey.LabelProject: kb.Project,
|
||||||
|
metricskey.LabelLocation: kb.Location,
|
||||||
|
metricskey.LabelClusterName: kb.ClusterName,
|
||||||
|
metricskey.LabelNamespaceName: kb.NamespaceName,
|
||||||
|
metricskey.LabelBrokerName: kb.BrokerName,
|
||||||
|
}
|
||||||
|
return metricskey.ResourceTypeKnativeBroker, labels
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ki *KnativeImporter) MonitoredResource() (resType string, labels map[string]string) {
|
||||||
|
labels = map[string]string{
|
||||||
|
metricskey.LabelProject: ki.Project,
|
||||||
|
metricskey.LabelLocation: ki.Location,
|
||||||
|
metricskey.LabelClusterName: ki.ClusterName,
|
||||||
|
metricskey.LabelNamespaceName: ki.NamespaceName,
|
||||||
|
metricskey.LabelImporterName: ki.ImporterName,
|
||||||
|
metricskey.LabelImporterResourceGroup: ki.ImporterResourceGroup,
|
||||||
|
}
|
||||||
|
return metricskey.ResourceTypeKnativeImporter, labels
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetKnativeBrokerMonitoredResource(
|
||||||
|
v *view.View, tags []tag.Tag, gm *gcpMetadata) ([]tag.Tag, monitoredresource.Interface) {
|
||||||
|
tagsMap := getTagsMap(tags)
|
||||||
|
kb := &KnativeBroker{
|
||||||
|
// The first three resource labels are from metadata.
|
||||||
|
Project: gm.project,
|
||||||
|
Location: gm.location,
|
||||||
|
ClusterName: gm.cluster,
|
||||||
|
// The rest resource labels are from metrics labels.
|
||||||
|
NamespaceName: valueOrUnknown(metricskey.LabelNamespaceName, tagsMap),
|
||||||
|
BrokerName: valueOrUnknown(metricskey.LabelBrokerName, tagsMap),
|
||||||
|
}
|
||||||
|
|
||||||
|
var newTags []tag.Tag
|
||||||
|
for _, t := range tags {
|
||||||
|
// Keep the metrics labels that are not resource labels
|
||||||
|
if !metricskey.KnativeBrokerLabels.Has(t.Key.Name()) {
|
||||||
|
newTags = append(newTags, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newTags, kb
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetKnativeTriggerMonitoredResource(
|
||||||
|
v *view.View, tags []tag.Tag, gm *gcpMetadata) ([]tag.Tag, monitoredresource.Interface) {
|
||||||
|
tagsMap := getTagsMap(tags)
|
||||||
|
kt := &KnativeTrigger{
|
||||||
|
// The first three resource labels are from metadata.
|
||||||
|
Project: gm.project,
|
||||||
|
Location: gm.location,
|
||||||
|
ClusterName: gm.cluster,
|
||||||
|
// The rest resource labels are from metrics labels.
|
||||||
|
NamespaceName: valueOrUnknown(metricskey.LabelNamespaceName, tagsMap),
|
||||||
|
TriggerName: valueOrUnknown(metricskey.LabelTriggerName, tagsMap),
|
||||||
|
BrokerName: valueOrUnknown(metricskey.LabelBrokerName, tagsMap),
|
||||||
|
}
|
||||||
|
|
||||||
|
var newTags []tag.Tag
|
||||||
|
for _, t := range tags {
|
||||||
|
// Keep the metrics labels that are not resource labels
|
||||||
|
if !metricskey.KnativeTriggerLabels.Has(t.Key.Name()) {
|
||||||
|
newTags = append(newTags, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newTags, kt
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetKnativeImporterMonitoredResource(
|
||||||
|
v *view.View, tags []tag.Tag, gm *gcpMetadata) ([]tag.Tag, monitoredresource.Interface) {
|
||||||
|
tagsMap := getTagsMap(tags)
|
||||||
|
ki := &KnativeImporter{
|
||||||
|
// The first three resource labels are from metadata.
|
||||||
|
Project: gm.project,
|
||||||
|
Location: gm.location,
|
||||||
|
ClusterName: gm.cluster,
|
||||||
|
// The rest resource labels are from metrics labels.
|
||||||
|
NamespaceName: valueOrUnknown(metricskey.LabelNamespaceName, tagsMap),
|
||||||
|
ImporterName: valueOrUnknown(metricskey.LabelImporterName, tagsMap),
|
||||||
|
ImporterResourceGroup: valueOrUnknown(metricskey.LabelImporterResourceGroup, tagsMap),
|
||||||
|
}
|
||||||
|
|
||||||
|
var newTags []tag.Tag
|
||||||
|
for _, t := range tags {
|
||||||
|
// Keep the metrics labels that are not resource labels
|
||||||
|
if !metricskey.KnativeImporterLabels.Has(t.Key.Name()) {
|
||||||
|
newTags = append(newTags, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newTags, ki
|
||||||
|
}
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
Copyright 2019 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
|
||||||
|
|
||||||
|
import (
|
||||||
|
"contrib.go.opencensus.io/exporter/stackdriver/monitoredresource"
|
||||||
|
"go.opencensus.io/stats/view"
|
||||||
|
"go.opencensus.io/tag"
|
||||||
|
"knative.dev/pkg/metrics/metricskey"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TODO should be moved to serving. See https://github.com/knative/pkg/issues/608
|
||||||
|
|
||||||
|
type KnativeRevision struct {
|
||||||
|
Project string
|
||||||
|
Location string
|
||||||
|
ClusterName string
|
||||||
|
NamespaceName string
|
||||||
|
ServiceName string
|
||||||
|
ConfigurationName string
|
||||||
|
RevisionName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kr *KnativeRevision) MonitoredResource() (resType string, labels map[string]string) {
|
||||||
|
labels = map[string]string{
|
||||||
|
metricskey.LabelProject: kr.Project,
|
||||||
|
metricskey.LabelLocation: kr.Location,
|
||||||
|
metricskey.LabelClusterName: kr.ClusterName,
|
||||||
|
metricskey.LabelNamespaceName: kr.NamespaceName,
|
||||||
|
metricskey.LabelServiceName: kr.ServiceName,
|
||||||
|
metricskey.LabelConfigurationName: kr.ConfigurationName,
|
||||||
|
metricskey.LabelRevisionName: kr.RevisionName,
|
||||||
|
}
|
||||||
|
return metricskey.ResourceTypeKnativeRevision, labels
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetKnativeRevisionMonitoredResource(
|
||||||
|
v *view.View, tags []tag.Tag, gm *gcpMetadata) ([]tag.Tag, monitoredresource.Interface) {
|
||||||
|
tagsMap := getTagsMap(tags)
|
||||||
|
kr := &KnativeRevision{
|
||||||
|
// The first three resource labels are from metadata.
|
||||||
|
Project: gm.project,
|
||||||
|
Location: gm.location,
|
||||||
|
ClusterName: gm.cluster,
|
||||||
|
// The rest resource labels are from metrics labels.
|
||||||
|
NamespaceName: valueOrUnknown(metricskey.LabelNamespaceName, tagsMap),
|
||||||
|
ServiceName: valueOrUnknown(metricskey.LabelServiceName, tagsMap),
|
||||||
|
ConfigurationName: valueOrUnknown(metricskey.LabelConfigurationName, tagsMap),
|
||||||
|
RevisionName: valueOrUnknown(metricskey.LabelRevisionName, tagsMap),
|
||||||
|
}
|
||||||
|
|
||||||
|
var newTags []tag.Tag
|
||||||
|
for _, t := range tags {
|
||||||
|
// Keep the metrics labels that are not resource labels
|
||||||
|
if !metricskey.KnativeRevisionLabels.Has(t.Key.Name()) {
|
||||||
|
newTags = append(newTags, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newTags, kr
|
||||||
|
}
|
|
@ -24,6 +24,9 @@ import (
|
||||||
"knative.dev/pkg/metrics/metricskey"
|
"knative.dev/pkg/metrics/metricskey"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO should be properly refactored and pieces should move to eventing and serving, as appropriate.
|
||||||
|
// See https://github.com/knative/pkg/issues/608
|
||||||
|
|
||||||
// Record decides whether to record one measurement via OpenCensus based on the
|
// Record decides whether to record one measurement via OpenCensus based on the
|
||||||
// following conditions:
|
// following conditions:
|
||||||
// 1) No package level metrics config. In this case it just proxies to OpenCensus
|
// 1) No package level metrics config. In this case it just proxies to OpenCensus
|
||||||
|
@ -32,7 +35,8 @@ import (
|
||||||
// using this function to get expected behavior.
|
// using this function to get expected behavior.
|
||||||
// 2) The backend is not Stackdriver.
|
// 2) The backend is not Stackdriver.
|
||||||
// 3) The backend is Stackdriver and it is allowed to use custom metrics.
|
// 3) The backend is Stackdriver and it is allowed to use custom metrics.
|
||||||
// 4) The backend is Stackdriver and the metric is "knative_revison" built-in metric.
|
// 4) The backend is Stackdriver and the metric is one of the built-in metrics: "knative_revision", "knative_broker",
|
||||||
|
// "knative_trigger", "knative_importer".
|
||||||
func Record(ctx context.Context, ms stats.Measurement) {
|
func Record(ctx context.Context, ms stats.Measurement) {
|
||||||
mc := getCurMetricsConfig()
|
mc := getCurMetricsConfig()
|
||||||
|
|
||||||
|
@ -50,7 +54,12 @@ func Record(ctx context.Context, ms stats.Measurement) {
|
||||||
|
|
||||||
// Condition 4)
|
// Condition 4)
|
||||||
metricType := path.Join(mc.stackdriverMetricTypePrefix, ms.Measure().Name())
|
metricType := path.Join(mc.stackdriverMetricTypePrefix, ms.Measure().Name())
|
||||||
if metricskey.KnativeRevisionMetrics.Has(metricType) {
|
isServingBuiltIn := metricskey.KnativeRevisionMetrics.Has(metricType)
|
||||||
|
isEventingBuiltIn := metricskey.KnativeTriggerMetrics.Has(metricType) ||
|
||||||
|
metricskey.KnativeBrokerMetrics.Has(metricType) ||
|
||||||
|
metricskey.KnativeImporterMetrics.Has(metricType)
|
||||||
|
|
||||||
|
if isServingBuiltIn || isEventingBuiltIn {
|
||||||
stats.Record(ctx, ms)
|
stats.Record(ctx, ms)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2019 The Knative Authors
|
Copyright 2019 The Knative Authors
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
You may obtain a copy of the License at
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
Unless required by applicable law or agreed to in writing, software
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@ -55,6 +58,8 @@ func newOpencensusSDExporter(o stackdriver.Options) (view.Exporter, error) {
|
||||||
return stackdriver.NewExporter(o)
|
return stackdriver.NewExporter(o)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO should be properly refactored to be able to inject the getMonitoredResourceFunc function.
|
||||||
|
// See https://github.com/knative/pkg/issues/608
|
||||||
func newStackdriverExporter(config *metricsConfig, logger *zap.SugaredLogger) (view.Exporter, error) {
|
func newStackdriverExporter(config *metricsConfig, logger *zap.SugaredLogger) (view.Exporter, error) {
|
||||||
gm := gcpMetadataFunc()
|
gm := gcpMetadataFunc()
|
||||||
mtf := getMetricTypeFunc(config.stackdriverMetricTypePrefix, config.stackdriverCustomMetricTypePrefix)
|
mtf := getMetricTypeFunc(config.stackdriverMetricTypePrefix, config.stackdriverCustomMetricTypePrefix)
|
||||||
|
@ -77,54 +82,19 @@ func getMonitoredResourceFunc(metricTypePrefix string, gm *gcpMetadata) func(v *
|
||||||
return func(view *view.View, tags []tag.Tag) ([]tag.Tag, monitoredresource.Interface) {
|
return func(view *view.View, tags []tag.Tag) ([]tag.Tag, monitoredresource.Interface) {
|
||||||
metricType := path.Join(metricTypePrefix, view.Measure.Name())
|
metricType := path.Join(metricTypePrefix, view.Measure.Name())
|
||||||
if metricskey.KnativeRevisionMetrics.Has(metricType) {
|
if metricskey.KnativeRevisionMetrics.Has(metricType) {
|
||||||
return getKnativeRevisionMonitoredResource(view, tags, gm)
|
return GetKnativeRevisionMonitoredResource(view, tags, gm)
|
||||||
|
} else if metricskey.KnativeBrokerMetrics.Has(metricType) {
|
||||||
|
return GetKnativeBrokerMonitoredResource(view, tags, gm)
|
||||||
|
} else if metricskey.KnativeTriggerMetrics.Has(metricType) {
|
||||||
|
return GetKnativeTriggerMonitoredResource(view, tags, gm)
|
||||||
|
} else if metricskey.KnativeImporterMetrics.Has(metricType) {
|
||||||
|
return GetKnativeImporterMonitoredResource(view, tags, gm)
|
||||||
}
|
}
|
||||||
// Unsupported metric by knative_revision, use "global" resource type.
|
// Unsupported metric by knative_revision, knative_broker, knative_trigger, and knative_importer, use "global" resource type.
|
||||||
return getGlobalMonitoredResource(view, tags)
|
return getGlobalMonitoredResource(view, tags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getKnativeRevisionMonitoredResource(
|
|
||||||
v *view.View, tags []tag.Tag, gm *gcpMetadata) ([]tag.Tag, monitoredresource.Interface) {
|
|
||||||
tagsMap := getTagsMap(tags)
|
|
||||||
kr := &KnativeRevision{
|
|
||||||
// The first three resource labels are from metadata.
|
|
||||||
Project: gm.project,
|
|
||||||
Location: gm.location,
|
|
||||||
ClusterName: gm.cluster,
|
|
||||||
// The rest resource labels are from metrics labels.
|
|
||||||
NamespaceName: valueOrUnknown(metricskey.LabelNamespaceName, tagsMap),
|
|
||||||
ServiceName: valueOrUnknown(metricskey.LabelServiceName, tagsMap),
|
|
||||||
ConfigurationName: valueOrUnknown(metricskey.LabelConfigurationName, tagsMap),
|
|
||||||
RevisionName: valueOrUnknown(metricskey.LabelRevisionName, tagsMap),
|
|
||||||
}
|
|
||||||
|
|
||||||
var newTags []tag.Tag
|
|
||||||
for _, t := range tags {
|
|
||||||
// Keep the metrics labels that are not resource labels
|
|
||||||
if !metricskey.KnativeRevisionLabels.Has(t.Key.Name()) {
|
|
||||||
newTags = append(newTags, t)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return newTags, kr
|
|
||||||
}
|
|
||||||
|
|
||||||
func getTagsMap(tags []tag.Tag) map[string]string {
|
|
||||||
tagsMap := map[string]string{}
|
|
||||||
for _, t := range tags {
|
|
||||||
tagsMap[t.Key.Name()] = t.Value
|
|
||||||
}
|
|
||||||
return tagsMap
|
|
||||||
}
|
|
||||||
|
|
||||||
func valueOrUnknown(key string, tagsMap map[string]string) string {
|
|
||||||
if value, ok := tagsMap[key]; ok {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
return metricskey.ValueUnknown
|
|
||||||
}
|
|
||||||
|
|
||||||
func getGlobalMonitoredResource(v *view.View, tags []tag.Tag) ([]tag.Tag, monitoredresource.Interface) {
|
func getGlobalMonitoredResource(v *view.View, tags []tag.Tag) ([]tag.Tag, monitoredresource.Interface) {
|
||||||
return tags, &Global{}
|
return tags, &Global{}
|
||||||
}
|
}
|
||||||
|
@ -132,7 +102,11 @@ func getGlobalMonitoredResource(v *view.View, tags []tag.Tag) ([]tag.Tag, monito
|
||||||
func getMetricTypeFunc(metricTypePrefix, customMetricTypePrefix string) func(view *view.View) string {
|
func getMetricTypeFunc(metricTypePrefix, customMetricTypePrefix string) func(view *view.View) string {
|
||||||
return func(view *view.View) string {
|
return func(view *view.View) string {
|
||||||
metricType := path.Join(metricTypePrefix, view.Measure.Name())
|
metricType := path.Join(metricTypePrefix, view.Measure.Name())
|
||||||
if metricskey.KnativeRevisionMetrics.Has(metricType) {
|
inServing := metricskey.KnativeRevisionMetrics.Has(metricType)
|
||||||
|
inEventing := metricskey.KnativeBrokerMetrics.Has(metricType) ||
|
||||||
|
metricskey.KnativeTriggerMetrics.Has(metricType) ||
|
||||||
|
metricskey.KnativeImporterMetrics.Has(metricType)
|
||||||
|
if inServing || inEventing {
|
||||||
return metricType
|
return metricType
|
||||||
}
|
}
|
||||||
// Unsupported metric by knative_revision, use custom domain.
|
// Unsupported metric by knative_revision, use custom domain.
|
||||||
|
|
Loading…
Reference in New Issue