diff --git a/go.mod b/go.mod index 931a80161a3..aaf20f418ae 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,7 @@ require ( k8s.io/client-go v11.0.1-0.20190805182717-6502b5e7b1b5+incompatible k8s.io/utils v0.0.0-20200603063816-c1c6865ac451 knative.dev/hack v0.0.0-20201214230143-4ed1ecb8db24 - knative.dev/pkg v0.0.0-20201224004104-42c8f15d4157 + knative.dev/pkg v0.0.0-20201231084629-fb3dc711206a knative.dev/reconciler-test v0.0.0-20201124190335-83a44efcdfef sigs.k8s.io/yaml v1.2.0 ) diff --git a/go.sum b/go.sum index 898ff85c32f..628e1275f9b 100644 --- a/go.sum +++ b/go.sum @@ -1107,8 +1107,8 @@ knative.dev/hack v0.0.0-20201118155651-b31d3bb6bff9/go.mod h1:PHt8x8yX5Z9pPquBEf knative.dev/hack v0.0.0-20201214230143-4ed1ecb8db24 h1:kIztWfvnIFV8Lhlea02K3YO2mIzcDyQNzrBLn0Oq9sA= knative.dev/hack v0.0.0-20201214230143-4ed1ecb8db24/go.mod h1:PHt8x8yX5Z9pPquBEfIj0X66f8iWkWfR0S/sarACJrI= knative.dev/pkg v0.0.0-20201117221452-0fccc54273ed/go.mod h1:nxlh3CUvx6WBPr1WKD96AHxFZPD2UKRDo9RUp8ILTyQ= -knative.dev/pkg v0.0.0-20201224004104-42c8f15d4157 h1:AYX+gYd9Q4EXCsrdzLzQGF0yNVaxJ4yncUnZxxAdURA= -knative.dev/pkg v0.0.0-20201224004104-42c8f15d4157/go.mod h1:hckgW978SdzPA2H5EDvRPY8xsnPuDZLJLbPf8Jte7Q0= +knative.dev/pkg v0.0.0-20201231084629-fb3dc711206a h1:LjZzFXE9VuhuPJFMn7KdjmsukoLOwQasfBuEJPc53ys= +knative.dev/pkg v0.0.0-20201231084629-fb3dc711206a/go.mod h1:hckgW978SdzPA2H5EDvRPY8xsnPuDZLJLbPf8Jte7Q0= knative.dev/reconciler-test v0.0.0-20201124190335-83a44efcdfef h1:8PttDFSsac32mq6Va+uPOyOR5CfX8JQT9g+MnHNyJ94= knative.dev/reconciler-test v0.0.0-20201124190335-83a44efcdfef/go.mod h1:YSs1y1rgnjs8w39/drLIOQbWvZUQwqApvd+EizO8UsA= pgregory.net/rapid v0.3.3 h1:jCjBsY4ln4Atz78QoBWxUEvAHaFyNDQg9+WU62aCn1U= diff --git a/vendor/knative.dev/pkg/metrics/config.go b/vendor/knative.dev/pkg/metrics/config.go index 535c8e9bced..c4c9c7f84e2 100644 --- a/vendor/knative.dev/pkg/metrics/config.go +++ b/vendor/knative.dev/pkg/metrics/config.go @@ -22,7 +22,6 @@ import ( "errors" "fmt" "os" - "path" "strconv" "strings" "time" @@ -65,6 +64,12 @@ const ( prometheusHostEnvName = "METRICS_PROMETHEUS_HOST" ) +var ( + // TestOverrideBundleCount is a variable for testing to reduce the size (number of metrics) buffered before + // Stackdriver will send a bundled metric report. Only applies if non-zero. + TestOverrideBundleCount = 0 +) + // Metrics backend "enum". const ( // stackdriver is used for Stackdriver backend @@ -248,37 +253,8 @@ func createMetricsConfig(ctx context.Context, ops ExporterOptions) (*metricsConf mc.prometheusPort = pp mc.prometheusHost = prometheusHost() case stackdriver: - // If stackdriverClientConfig is not provided for stackdriver backend destination, OpenCensus will try to - // use the application default credentials. If that is not available, Opencensus would fail to create the - // metrics exporter. - scc := NewStackdriverClientConfigFromMap(m) - mc.stackdriverClientConfig = *scc - mc.isStackdriverBackend = true - var allowCustomMetrics bool - var err error - mc.stackdriverMetricTypePrefix = path.Join(mc.domain, mc.component) - - customMetricsSubDomain := m[stackdriverCustomMetricSubDomainKey] - if customMetricsSubDomain == "" { - customMetricsSubDomain = defaultCustomMetricSubDomain - } - mc.stackdriverCustomMetricTypePrefix = path.Join(customMetricTypePrefix, customMetricsSubDomain, mc.component) - if ascmStr := m[allowStackdriverCustomMetricsKey]; ascmStr != "" { - allowCustomMetrics, err = strconv.ParseBool(ascmStr) - if err != nil { - return nil, fmt.Errorf("invalid %s value %q", allowStackdriverCustomMetricsKey, ascmStr) - } - } - - mc.recorder = sdCustomMetricsRecorder(mc, allowCustomMetrics) - - if scc.UseSecret { - secret, err := getStackdriverSecret(ctx, ops.Secrets) - if err != nil { - return nil, err - } - - mc.secret = secret + if err := sdinit(ctx, m, &mc, ops); err != nil { + return nil, err } } diff --git a/vendor/knative.dev/pkg/metrics/gcp_metadata.go b/vendor/knative.dev/pkg/metrics/gcp_metadata.go index ec6ae878e38..3c1a6a09ad4 100644 --- a/vendor/knative.dev/pkg/metrics/gcp_metadata.go +++ b/vendor/knative.dev/pkg/metrics/gcp_metadata.go @@ -1,3 +1,5 @@ +// +build !nostackdriver + /* Copyright 2019 The Knative Authors diff --git a/vendor/knative.dev/pkg/metrics/nostackdriver.go b/vendor/knative.dev/pkg/metrics/nostackdriver.go new file mode 100644 index 00000000000..b5c71eb77a3 --- /dev/null +++ b/vendor/knative.dev/pkg/metrics/nostackdriver.go @@ -0,0 +1,35 @@ +// +build nostackdriver + +/* +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 ( + "context" + "errors" + + "go.opencensus.io/stats/view" + "go.uber.org/zap" +) + +func sdinit(ctx context.Context, m map[string]string, mc *metricsConfig, ops ExporterOptions) error { + return errors.New("Stackdriver support is not included") +} + +func newStackdriverExporter(config *metricsConfig, logger *zap.SugaredLogger) (view.Exporter, ResourceExporterFactory, error) { + return nil, nil, errors.New("Stackdriver support is not included") +} diff --git a/vendor/knative.dev/pkg/metrics/stackdriver_exporter.go b/vendor/knative.dev/pkg/metrics/stackdriver_exporter.go index ab14ef266c2..a875accef76 100644 --- a/vendor/knative.dev/pkg/metrics/stackdriver_exporter.go +++ b/vendor/knative.dev/pkg/metrics/stackdriver_exporter.go @@ -1,3 +1,5 @@ +// +build !nostackdriver + /* Copyright 2019 The Knative Authors @@ -20,6 +22,7 @@ import ( "context" "fmt" "path" + "strconv" "sync" "time" @@ -88,10 +91,6 @@ var ( // metricToResourceLabels provides a quick lookup from a custom metric name to the set of tags // which should be promoted to Stackdriver Resource labels via opencensus resources. metricToResourceLabels = map[string]*resourceTemplate{} - - // TestOverrideBundleCount is a variable for testing to reduce the size (number of metrics) buffered before - // Stackdriver will send a bundled metric report. Only applies if non-zero. - TestOverrideBundleCount = 0 ) type resourceTemplate struct { @@ -99,6 +98,42 @@ type resourceTemplate struct { LabelKeys sets.String } +func sdinit(ctx context.Context, m map[string]string, mc *metricsConfig, ops ExporterOptions) error { + // If stackdriverClientConfig is not provided for stackdriver backend destination, OpenCensus will try to + // use the application default credentials. If that is not available, Opencensus would fail to create the + // metrics exporter. + scc := NewStackdriverClientConfigFromMap(m) + mc.stackdriverClientConfig = *scc + mc.isStackdriverBackend = true + var allowCustomMetrics bool + var err error + mc.stackdriverMetricTypePrefix = path.Join(mc.domain, mc.component) + + customMetricsSubDomain := m[stackdriverCustomMetricSubDomainKey] + if customMetricsSubDomain == "" { + customMetricsSubDomain = defaultCustomMetricSubDomain + } + mc.stackdriverCustomMetricTypePrefix = path.Join(customMetricTypePrefix, customMetricsSubDomain, mc.component) + if ascmStr := m[allowStackdriverCustomMetricsKey]; ascmStr != "" { + allowCustomMetrics, err = strconv.ParseBool(ascmStr) + if err != nil { + return fmt.Errorf("invalid %s value %q", allowStackdriverCustomMetricsKey, ascmStr) + } + } + + mc.recorder = sdCustomMetricsRecorder(*mc, allowCustomMetrics) + + if scc.UseSecret { + secret, err := getStackdriverSecret(ctx, ops.Secrets) + if err != nil { + return err + } + + mc.secret = secret + } + return nil +} + // SetStackdriverSecretLocation sets the name and namespace of the Secret that can be used to authenticate with Stackdriver. // The Secret is only used if both: // 1. This function has been explicitly called to set the name and namespace diff --git a/vendor/knative.dev/pkg/metrics/testing.go b/vendor/knative.dev/pkg/metrics/testing.go index eb048f9cbaa..28b2e587808 100644 --- a/vendor/knative.dev/pkg/metrics/testing.go +++ b/vendor/knative.dev/pkg/metrics/testing.go @@ -16,6 +16,10 @@ limitations under the License. package metrics +const ( + testComponent = "testComponent" +) + // InitForTesting initialize the necessary global variables for unit tests. func InitForTesting() { setCurMetricsConfig(&metricsConfig{ diff --git a/vendor/modules.txt b/vendor/modules.txt index fcf8cd9a851..4c4f3b014cb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -970,7 +970,7 @@ k8s.io/utils/trace ## explicit knative.dev/hack knative.dev/hack/shell -# knative.dev/pkg v0.0.0-20201224004104-42c8f15d4157 +# knative.dev/pkg v0.0.0-20201231084629-fb3dc711206a ## explicit knative.dev/pkg/apiextensions/storageversion knative.dev/pkg/apiextensions/storageversion/cmd/migrate