Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions metrics/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ import (
. "knative.dev/pkg/logging/testing"
)

// TODO UTs should move to eventing and serving, as appropriate.
// See https://github.com/knative/pkg/issues/608

const (
servingDomain = "knative.dev/serving"
badDomain = "test.domain"
testComponent = "testComponent"
testProj = "test-project"
anotherProj = "another-project"
servingDomain = "knative.dev/serving"
eventingDomain = "knative.dev/eventing"
badDomain = "test.domain"
testComponent = "testComponent"
testProj = "test-project"
anotherProj = "another-project"
)

var (
Expand Down
30 changes: 28 additions & 2 deletions metrics/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,24 @@ import (
"knative.dev/pkg/metrics/metricskey"
)

// TODO UTs should move to eventing and serving, as appropriate.
// See https://github.com/knative/pkg/issues/608

const (
testNS = "test"
testService = "test-service"
testRoute = "test-route"
testConfiguration = "test-configuration"
testRevision = "test-revision"

testBroker = "test-broker"
testEventType = "test-eventtype"
testEventSource = "test-eventsource"
testTrigger = "test-trigger"
testFilterType = "test-filtertype"
testFilterSource = "test-filtersource"
testImporter = "test-importer"
testImporterResourceGroup = "test-importer-rg"
)

var (
Expand All @@ -41,12 +53,26 @@ var (
TagKeys: []tag.Key{},
}

nsKey = tag.Tag{Key: mustNewTagKey(metricskey.LabelNamespaceName), Value: testNS}
nsKey = tag.Tag{Key: mustNewTagKey(metricskey.LabelNamespaceName), Value: testNS}

serviceKey = tag.Tag{Key: mustNewTagKey(metricskey.LabelServiceName), Value: testService}
routeKey = tag.Tag{Key: mustNewTagKey(metricskey.LabelRouteName), Value: testRoute}
revisionKey = tag.Tag{Key: mustNewTagKey(metricskey.LabelRevisionName), Value: testRevision}

testTags = []tag.Tag{nsKey, serviceKey, routeKey, revisionKey}
brokerKey = tag.Tag{Key: mustNewTagKey(metricskey.LabelBrokerName), Value: testBroker}
triggerKey = tag.Tag{Key: mustNewTagKey(metricskey.LabelTriggerName), Value: testTrigger}
filterTypeKey = tag.Tag{Key: mustNewTagKey(metricskey.LabelFilterType), Value: testFilterType}
filterSourceKey = tag.Tag{Key: mustNewTagKey(metricskey.LabelFilterSource), Value: testFilterSource}
importerKey = tag.Tag{Key: mustNewTagKey(metricskey.LabelImporterName), Value: testImporter}
importerResourceGroupKey = tag.Tag{Key: mustNewTagKey(metricskey.LabelImporterResourceGroup), Value: testImporterResourceGroup}
eventTypeKey = tag.Tag{Key: mustNewTagKey(metricskey.LabelEventType), Value: testEventType}
eventSourceKey = tag.Tag{Key: mustNewTagKey(metricskey.LabelEventSource), Value: testEventSource}

revisionTestTags = []tag.Tag{nsKey, serviceKey, routeKey, revisionKey}

brokerTestTags = []tag.Tag{nsKey, brokerKey, eventTypeKey, eventSourceKey}
triggerTestTags = []tag.Tag{nsKey, triggerKey, brokerKey, filterTypeKey, filterSourceKey}
importerTestTags = []tag.Tag{nsKey, importerKey, importerResourceGroupKey, eventTypeKey, eventSourceKey}
)

func mustNewTagKey(s string) tag.Key {
Expand Down
9 changes: 9 additions & 0 deletions metrics/gcp_metadata.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/*
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.
Expand All @@ -18,6 +21,12 @@ import (
"knative.dev/pkg/metrics/metricskey"
)

type gcpMetadata struct {
project string
location string
cluster string
}

func retrieveGCPMetadata() *gcpMetadata {
gm := gcpMetadata{
project: metricskey.ValueUnknown,
Expand Down
50 changes: 3 additions & 47 deletions metrics/metricskey/constants.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/*
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.
Expand All @@ -13,12 +16,7 @@ limitations under the License.

package metricskey

import "k8s.io/apimachinery/pkg/util/sets"

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 = "project_id"

Expand All @@ -31,49 +29,7 @@ const (
// 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"

// 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
// is not running on GKE.
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",
)
)
107 changes: 107 additions & 0 deletions metrics/metricskey/constants_eventing.go
Original file line number Diff line number Diff line change
@@ -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",
Comment thread
nachocano marked this conversation as resolved.
"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",
)
)
68 changes: 68 additions & 0 deletions metrics/metricskey/constants_serving.go
Original file line number Diff line number Diff line change
@@ -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",
)
)
Loading