From 91a38b35be17ebbe1dd6981f7a2a65fc24eb45fb Mon Sep 17 00:00:00 2001 From: knative-automation Date: Thu, 24 Dec 2020 06:56:04 -0800 Subject: [PATCH] upgrade to latest dependencies (#411) Signed-off-by: Knative Automation --- go.mod | 2 +- go.sum | 4 +- vendor/knative.dev/pkg/metrics/config.go | 40 ++++------------- .../knative.dev/pkg/metrics/gcp_metadata.go | 2 + .../knative.dev/pkg/metrics/nostackdriver.go | 35 +++++++++++++++ .../pkg/metrics/stackdriver_exporter.go | 43 +++++++++++++++++-- vendor/knative.dev/pkg/metrics/testing.go | 4 ++ vendor/modules.txt | 2 +- 8 files changed, 92 insertions(+), 40 deletions(-) create mode 100644 vendor/knative.dev/pkg/metrics/nostackdriver.go diff --git a/go.mod b/go.mod index d65b05a4..1095bccd 100644 --- a/go.mod +++ b/go.mod @@ -18,5 +18,5 @@ require ( k8s.io/code-generator v0.18.12 k8s.io/kube-openapi v0.0.0-20200410145947-bcb3869e6f29 knative.dev/hack v0.0.0-20201214230143-4ed1ecb8db24 - knative.dev/pkg v0.0.0-20201223002104-9d0775512af8 + knative.dev/pkg v0.0.0-20201224024804-27db5ac24cfb ) diff --git a/go.sum b/go.sum index f18e0bc6..87c8f08a 100644 --- a/go.sum +++ b/go.sum @@ -1172,8 +1172,8 @@ k8s.io/utils v0.0.0-20200603063816-c1c6865ac451 h1:v8ud2Up6QK1lNOKFgiIVrZdMg7Mpm k8s.io/utils v0.0.0-20200603063816-c1c6865ac451/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= 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-20201223002104-9d0775512af8 h1:0UaGaAn57/Egp7cfD/Cq6tNYr2QYyGZ8KSzC46CxYq4= -knative.dev/pkg v0.0.0-20201223002104-9d0775512af8/go.mod h1:hckgW978SdzPA2H5EDvRPY8xsnPuDZLJLbPf8Jte7Q0= +knative.dev/pkg v0.0.0-20201224024804-27db5ac24cfb h1:XVcmpSvfDMZ5Z+1pebSm5Msq5sQey/V4NHF2+dFNU1o= +knative.dev/pkg v0.0.0-20201224024804-27db5ac24cfb/go.mod h1:hckgW978SdzPA2H5EDvRPY8xsnPuDZLJLbPf8Jte7Q0= pgregory.net/rapid v0.3.3/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= diff --git a/vendor/knative.dev/pkg/metrics/config.go b/vendor/knative.dev/pkg/metrics/config.go index 535c8e9b..c4c9c7f8 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 ec6ae878..3c1a6a09 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 00000000..b5c71eb7 --- /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 ab14ef26..a875acce 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 eb048f9c..28b2e587 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 c5f0700b..38507243 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -655,7 +655,7 @@ k8s.io/utils/trace # knative.dev/hack v0.0.0-20201214230143-4ed1ecb8db24 ## explicit knative.dev/hack -# knative.dev/pkg v0.0.0-20201223002104-9d0775512af8 +# knative.dev/pkg v0.0.0-20201224024804-27db5ac24cfb ## explicit knative.dev/pkg/apis knative.dev/pkg/apis/duck