Auto-update dependencies (#102)

Produced via:
  `dep ensure -update knative.dev/test-infra knative.dev/pkg`
/assign mattmoor
This commit is contained in:
mattmoor-sockpuppet 2019-09-17 07:31:48 -07:00 committed by Knative Prow Robot
parent 3f124e23c8
commit 41c23b2a46
17 changed files with 702 additions and 62 deletions

8
Gopkg.lock generated
View File

@ -927,7 +927,7 @@
[[projects]]
branch = "master"
digest = "1:8c823908d13842f7140f59dc246b98d523f436e884ff7c5cd44aae9c3889c890"
digest = "1:3c7d420e299c96fab540a977299b43f1606b9d16b0593e7083c84345dcbde5bf"
name = "knative.dev/pkg"
packages = [
"apis",
@ -946,18 +946,18 @@
"metrics/metricskey",
]
pruneopts = "T"
revision = "d8d1bc27181b1a612f7648632b84b9706b57df34"
revision = "5cdf30f51ef152232da0e56ef39d35de6c057f3d"
[[projects]]
branch = "master"
digest = "1:615f3c6b974179c583edf50234fd87c5731d02ef941f314cbd4dd2766d3a619a"
digest = "1:964a4f9e12d5021b9d550e04c36cf23feb880e286ceede1b246d5c0e43b523b9"
name = "knative.dev/test-infra"
packages = [
"scripts",
"tools/dep-collector",
]
pruneopts = "UT"
revision = "4adb699576a34afae2e163f0ad5a0d2db0b30a5b"
revision = "efad44559f944cfc58dc5bca076eeb3ec20fb346"
[solve-meta]
analyzer-name = "dep"

7
vendor/knative.dev/pkg/Gopkg.lock generated vendored
View File

@ -744,10 +744,10 @@
[[projects]]
branch = "master"
digest = "1:bcfc1adc3202f2ff120bc4686c613c8f34af0f9e3de49b55d3bbecd70dc6651b"
digest = "1:3b865f5fdc62cc6f52865a3bf29146a384fd5b2f250d8d86c0c2a41a4ffa10c4"
name = "google.golang.org/api"
packages = [
"container/v1",
"container/v1beta1",
"gensupport",
"googleapi",
"googleapi/internal/uritemplates",
@ -1313,7 +1313,7 @@
"golang.org/x/oauth2",
"golang.org/x/oauth2/google",
"golang.org/x/sync/errgroup",
"google.golang.org/api/container/v1",
"google.golang.org/api/container/v1beta1",
"google.golang.org/grpc",
"gopkg.in/yaml.v2",
"k8s.io/api/admission/v1beta1",
@ -1369,6 +1369,7 @@
"k8s.io/client-go/testing",
"k8s.io/client-go/tools/cache",
"k8s.io/client-go/tools/clientcmd",
"k8s.io/client-go/tools/metrics",
"k8s.io/client-go/tools/record",
"k8s.io/client-go/util/flowcontrol",
"k8s.io/client-go/util/workqueue",

View File

@ -8,7 +8,7 @@ required = [
"k8s.io/code-generator/cmd/client-gen",
"k8s.io/code-generator/cmd/lister-gen",
"k8s.io/code-generator/cmd/informer-gen",
"google.golang.org/api/container/v1",
"google.golang.org/api/container/v1beta1",
"github.com/evanphx/json-patch",
"knative.dev/test-infra/scripts",
"knative.dev/test-infra/tools/dep-collector",

View File

@ -25,6 +25,9 @@ import (
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
"go.uber.org/zap"
"k8s.io/client-go/tools/cache"
kubemetrics "k8s.io/client-go/tools/metrics"
"k8s.io/client-go/util/workqueue"
"knative.dev/pkg/metrics"
)
@ -48,30 +51,133 @@ var (
)
func init() {
// Create views to see our measurements. This can return an error if
// a previously-registered view has the same name with a different value.
// View name defaults to the measure name if unspecified.
err := view.Register(
&view.View{
// Register to receive metrics from kubernetes workqueues.
wp := &metrics.WorkqueueProvider{
Adds: stats.Int64(
"workqueue_adds_total",
"Total number of adds handled by workqueue",
stats.UnitNone,
),
Depth: stats.Int64(
"workqueue_depth",
"Current depth of workqueue",
stats.UnitNone,
),
Latency: stats.Float64(
"workqueue_queue_latency_seconds",
"How long in seconds an item stays in workqueue before being requested.",
"s",
),
Retries: stats.Int64(
"workqueue_retries_total",
"Total number of retries handled by workqueue",
"s",
),
WorkDuration: stats.Float64(
"workqueue_work_duration_seconds",
"How long in seconds processing an item from workqueue takes.",
"s",
),
}
workqueue.SetProvider(wp)
// Register to receive metrics from kubernetes reflectors (what powers informers)
// NOTE: today these don't actually seem to wire up to anything in Kubernetes.
rp := &metrics.ReflectorProvider{
ItemsInList: stats.Float64(
"reflector_items_in_list",
"How many items an API list returns to the reflectors",
stats.UnitNone,
),
// TODO(mattmoor): This is not in the latest version, so it will
// be removed in a future version.
ItemsInMatch: stats.Float64(
"reflector_items_in_match",
"",
stats.UnitNone,
),
ItemsInWatch: stats.Float64(
"reflector_items_in_watch",
"How many items an API watch returns to the reflectors",
stats.UnitNone,
),
LastResourceVersion: stats.Float64(
"reflector_last_resource_version",
"Last resource version seen for the reflectors",
stats.UnitNone,
),
ListDuration: stats.Float64(
"reflector_list_duration_seconds",
"How long an API list takes to return and decode for the reflectors",
stats.UnitNone,
),
Lists: stats.Int64(
"reflector_lists_total",
"Total number of API lists done by the reflectors",
stats.UnitNone,
),
ShortWatches: stats.Int64(
"reflector_short_watches_total",
"Total number of short API watches done by the reflectors",
stats.UnitNone,
),
WatchDuration: stats.Float64(
"reflector_watch_duration_seconds",
"How long an API watch takes to return and decode for the reflectors",
stats.UnitNone,
),
Watches: stats.Int64(
"reflector_watches_total",
"Total number of API watches done by the reflectors",
stats.UnitNone,
),
}
cache.SetReflectorMetricsProvider(rp)
cp := &metrics.ClientProvider{
Latency: stats.Float64(
"client_latency",
"How long Kubernetes API requests take",
"s",
),
Result: stats.Int64(
"client_results",
"Total number of API requests (broken down by status code)",
stats.UnitNone,
),
}
kubemetrics.Register(cp.NewLatencyMetric(), cp.NewResultMetric())
views := []*view.View{{
Description: "Depth of the work queue",
Measure: workQueueDepthStat,
Aggregation: view.LastValue(),
TagKeys: []tag.Key{reconcilerTagKey},
},
&view.View{
}, {
Description: "Number of reconcile operations",
Measure: reconcileCountStat,
Aggregation: view.Count(),
TagKeys: []tag.Key{reconcilerTagKey, keyTagKey, successTagKey},
},
&view.View{
}, {
Description: "Latency of reconcile operations",
Measure: reconcileLatencyStat,
Aggregation: reconcileDistribution,
TagKeys: []tag.Key{reconcilerTagKey, keyTagKey, successTagKey},
},
)
if err != nil {
}}
for _, view := range wp.DefaultViews() {
views = append(views, view)
}
for _, view := range rp.DefaultViews() {
views = append(views, view)
}
for _, view := range cp.DefaultViews() {
views = append(views, view)
}
// Create views to see our measurements. This can return an error if
// a previously-registered view has the same name with a different value.
// View name defaults to the measure name if unspecified.
if err := view.Register(views...); err != nil {
panic(err)
}
}

View File

@ -0,0 +1,62 @@
/*
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 (
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"k8s.io/client-go/tools/metrics"
)
// ClientProvider implements the pattern of Kubernetes MetricProvider that may
// be used to produce suitable metrics for use with metrics.Register()
type ClientProvider struct {
Latency *stats.Float64Measure
Result *stats.Int64Measure
}
// NewLatencyMetric implements MetricsProvider
func (cp *ClientProvider) NewLatencyMetric() metrics.LatencyMetric {
return latencyMetric{
measure: cp.Latency,
}
}
// LatencyView returns a view of the Latency metric.
func (cp *ClientProvider) LatencyView() *view.View {
return measureView(cp.Latency, view.Distribution(BucketsNBy10(0.00001, 8)...))
}
// NewResultMetric implements MetricsProvider
func (cp *ClientProvider) NewResultMetric() metrics.ResultMetric {
return resultMetric{
measure: cp.Result,
}
}
// ResultView returns a view of the Result metric.
func (cp *ClientProvider) ResultView() *view.View {
return measureView(cp.Result, view.Count())
}
// DefaultViews returns a list of views suitable for passing to view.Register
func (cp *ClientProvider) DefaultViews() []*view.View {
return []*view.View{
cp.LatencyView(),
cp.ResultView(),
}
}

View File

@ -0,0 +1,152 @@
/*
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"
"net/url"
"sync/atomic"
"time"
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/tools/metrics"
"k8s.io/client-go/util/workqueue"
)
var (
// tagName is used to associate the provided name with each metric created
// through the WorkqueueProvider's methods to implement workqueue.MetricsProvider.
// For the kubernetes workqueue implementations this is the queue name provided
// to the workqueue constructor.
tagName = tag.MustNewKey("name")
// tagVerb is used to associate the verb of the client action with latency metrics.
tagVerb = tag.MustNewKey("verb")
// tagCode is used to associate the status code the client gets back from an API call.
tagCode = tag.MustNewKey("code")
// tagMethod is used to associate the HTTP method the client used for the rest call.
tagMethod = tag.MustNewKey("method")
// tagHost is used to associate the host to which the HTTP request was made.
tagHost = tag.MustNewKey("host")
// tagPath is used to associate the path to which the HTTP request as made.
tagPath = tag.MustNewKey("path")
)
type counterMetric struct {
mutators []tag.Mutator
measure *stats.Int64Measure
}
var (
_ cache.CounterMetric = (*counterMetric)(nil)
_ workqueue.CounterMetric = (*counterMetric)(nil)
)
// Inc implements CounterMetric
func (m counterMetric) Inc() {
Record(context.Background(), m.measure.M(1), stats.WithTags(m.mutators...))
}
type gaugeMetric struct {
mutators []tag.Mutator
measure *stats.Int64Measure
total int64
}
var (
_ workqueue.GaugeMetric = (*gaugeMetric)(nil)
)
// Inc implements CounterMetric
func (m *gaugeMetric) Inc() {
total := atomic.AddInt64(&m.total, 1)
Record(context.Background(), m.measure.M(total), stats.WithTags(m.mutators...))
}
// Dec implements GaugeMetric
func (m *gaugeMetric) Dec() {
total := atomic.AddInt64(&m.total, -1)
Record(context.Background(), m.measure.M(total), stats.WithTags(m.mutators...))
}
type floatMetric struct {
mutators []tag.Mutator
measure *stats.Float64Measure
}
var (
_ workqueue.SummaryMetric = (*floatMetric)(nil)
_ cache.GaugeMetric = (*floatMetric)(nil)
)
// Observe implements SummaryMetric
func (m floatMetric) Observe(v float64) {
Record(context.Background(), m.measure.M(v), stats.WithTags(m.mutators...))
}
// Set implements GaugeMetric
func (m floatMetric) Set(v float64) {
m.Observe(v)
}
type latencyMetric struct {
measure *stats.Float64Measure
}
var (
_ metrics.LatencyMetric = (*latencyMetric)(nil)
)
// Observe implements LatencyMetric
func (m latencyMetric) Observe(verb string, u url.URL, t time.Duration) {
Record(context.Background(), m.measure.M(t.Seconds()), stats.WithTags(
tag.Insert(tagVerb, verb),
tag.Insert(tagHost, u.Host),
tag.Insert(tagPath, u.Path),
))
}
type resultMetric struct {
measure *stats.Int64Measure
}
var (
_ metrics.ResultMetric = (*resultMetric)(nil)
)
// Increment implements ResultMetric
func (m resultMetric) Increment(code, method, host string) {
Record(context.Background(), m.measure.M(1), stats.WithTags(
tag.Insert(tagCode, code),
tag.Insert(tagMethod, method),
tag.Insert(tagHost, host),
))
}
// measureView returns a view of the supplied metric.
func measureView(m stats.Measure, agg *view.Aggregation) *view.View {
return &view.View{
Name: m.Name(),
Description: m.Description(),
Measure: m,
Aggregation: agg,
TagKeys: []tag.Key{tagName},
}
}

View File

@ -58,7 +58,7 @@ func CheckCountData(t *testing.T, name string, wantTags map[string]string, wantV
checkRowTags(t, row, name, wantTags)
if s, ok := row.Data.(*view.CountData); !ok {
t.Errorf("For metric %s: Reporter expected a CountData type", name)
t.Errorf("%s: got %T, want CountData", name, row.Data)
} else if s.Value != wantValue {
t.Errorf("For metric %s: value = %v, want: %d", name, s.Value, wantValue)
}
@ -74,7 +74,7 @@ func CheckDistributionData(t *testing.T, name string, wantTags map[string]string
checkRowTags(t, row, name, wantTags)
if s, ok := row.Data.(*view.DistributionData); !ok {
t.Errorf("For metric %s: Reporter expected a DistributionData type", name)
t.Errorf("%s: got %T, want DistributionData", name, row.Data)
} else {
if s.Count != expectedCount {
t.Errorf("For metric %s: reporter count = %d, want = %d", name, s.Count, expectedCount)
@ -97,7 +97,7 @@ func CheckLastValueData(t *testing.T, name string, wantTags map[string]string, w
checkRowTags(t, row, name, wantTags)
if s, ok := row.Data.(*view.LastValueData); !ok {
t.Errorf("For metric %s: Reporter.Report() expected a LastValueData type", name)
t.Errorf("%s: got %T, want LastValueData", name, row.Data)
} else if s.Value != wantValue {
t.Errorf("For metric %s: Reporter.Report() expected %v got %v", name, s.Value, wantValue)
}
@ -112,7 +112,7 @@ func CheckSumData(t *testing.T, name string, wantTags map[string]string, wantVal
checkRowTags(t, row, name, wantTags)
if s, ok := row.Data.(*view.SumData); !ok {
t.Errorf("For metric %s: Reporter expected a SumData type", name)
t.Errorf("%s: got %T, want SumData", name, row.Data)
} else if s.Value != wantValue {
t.Errorf("For metric %s: value = %v, want: %v", name, s.Value, wantValue)
}

View File

@ -37,18 +37,20 @@ import (
// 3) The backend is Stackdriver and it is allowed to use custom metrics.
// 4) The backend is Stackdriver and the metric is one of the built-in metrics: "knative_revision", "knative_broker",
// "knative_trigger", "knative_source".
func Record(ctx context.Context, ms stats.Measurement) {
func Record(ctx context.Context, ms stats.Measurement, ros ...stats.Options) {
mc := getCurMetricsConfig()
ros = append(ros, stats.WithMeasurements(ms))
// Condition 1)
if mc == nil {
stats.Record(ctx, ms)
stats.RecordWithOptions(ctx, ros...)
return
}
// Condition 2) and 3)
if !mc.isStackdriverBackend || mc.allowStackdriverCustomMetrics {
stats.Record(ctx, ms)
stats.RecordWithOptions(ctx, ros...)
return
}
@ -60,7 +62,7 @@ func Record(ctx context.Context, ms stats.Measurement) {
metricskey.KnativeSourceMetrics.Has(metricType)
if isServingBuiltIn || isEventingBuiltIn {
stats.Record(ctx, ms)
stats.RecordWithOptions(ctx, ros...)
}
}
@ -74,3 +76,13 @@ func Buckets125(low, high float64) []float64 {
}
return buckets
}
// BucketsNBy10 generates an array of N buckets starting from low and
// multiplying by 10 n times.
func BucketsNBy10(low float64, n int) []float64 {
buckets := []float64{low}
for last, i := low, len(buckets); i < n; last, i = 10*last, i+1 {
buckets = append(buckets, 10*last)
}
return buckets
}

View File

@ -0,0 +1,176 @@
/*
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 (
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
"k8s.io/client-go/tools/cache"
)
// ReflectorProvider implements reflector.MetricsProvider and may be used with
// reflector.SetProvider to have metrics exported to the provided metrics.
type ReflectorProvider struct {
ItemsInList *stats.Float64Measure
// TODO(mattmoor): This is not in the latest version, so it will
// be removed in a future version.
ItemsInMatch *stats.Float64Measure
ItemsInWatch *stats.Float64Measure
LastResourceVersion *stats.Float64Measure
ListDuration *stats.Float64Measure
Lists *stats.Int64Measure
ShortWatches *stats.Int64Measure
WatchDuration *stats.Float64Measure
Watches *stats.Int64Measure
}
var (
_ cache.MetricsProvider = (*ReflectorProvider)(nil)
)
// NewItemsInListMetric implements MetricsProvider
func (rp *ReflectorProvider) NewItemsInListMetric(name string) cache.SummaryMetric {
return floatMetric{
mutators: []tag.Mutator{tag.Insert(tagName, name)},
measure: rp.ItemsInList,
}
}
// ItemsInListView returns a view of the ItemsInList metric.
func (rp *ReflectorProvider) ItemsInListView() *view.View {
return measureView(rp.ItemsInList, view.Distribution(BucketsNBy10(0.1, 6)...))
}
// NewItemsInMatchMetric implements MetricsProvider
func (rp *ReflectorProvider) NewItemsInMatchMetric(name string) cache.SummaryMetric {
return floatMetric{
mutators: []tag.Mutator{tag.Insert(tagName, name)},
measure: rp.ItemsInMatch,
}
}
// ItemsInMatchView returns a view of the ItemsInMatch metric.
func (rp *ReflectorProvider) ItemsInMatchView() *view.View {
return measureView(rp.ItemsInMatch, view.Distribution(BucketsNBy10(0.1, 6)...))
}
// NewItemsInWatchMetric implements MetricsProvider
func (rp *ReflectorProvider) NewItemsInWatchMetric(name string) cache.SummaryMetric {
return floatMetric{
mutators: []tag.Mutator{tag.Insert(tagName, name)},
measure: rp.ItemsInWatch,
}
}
// ItemsInWatchView returns a view of the ItemsInWatch metric.
func (rp *ReflectorProvider) ItemsInWatchView() *view.View {
return measureView(rp.ItemsInWatch, view.Distribution(BucketsNBy10(0.1, 6)...))
}
// NewLastResourceVersionMetric implements MetricsProvider
func (rp *ReflectorProvider) NewLastResourceVersionMetric(name string) cache.GaugeMetric {
return floatMetric{
mutators: []tag.Mutator{tag.Insert(tagName, name)},
measure: rp.LastResourceVersion,
}
}
// LastResourceVersionView returns a view of the LastResourceVersion metric.
func (rp *ReflectorProvider) LastResourceVersionView() *view.View {
return measureView(rp.LastResourceVersion, view.LastValue())
}
// NewListDurationMetric implements MetricsProvider
func (rp *ReflectorProvider) NewListDurationMetric(name string) cache.SummaryMetric {
return floatMetric{
mutators: []tag.Mutator{tag.Insert(tagName, name)},
measure: rp.ListDuration,
}
}
// ListDurationView returns a view of the ListDuration metric.
func (rp *ReflectorProvider) ListDurationView() *view.View {
return measureView(rp.ListDuration, view.Distribution(BucketsNBy10(0.1, 6)...))
}
// NewListsMetric implements MetricsProvider
func (rp *ReflectorProvider) NewListsMetric(name string) cache.CounterMetric {
return counterMetric{
mutators: []tag.Mutator{tag.Insert(tagName, name)},
measure: rp.Lists,
}
}
// ListsView returns a view of the Lists metric.
func (rp *ReflectorProvider) ListsView() *view.View {
return measureView(rp.Lists, view.Count())
}
// NewShortWatchesMetric implements MetricsProvider
func (rp *ReflectorProvider) NewShortWatchesMetric(name string) cache.CounterMetric {
return counterMetric{
mutators: []tag.Mutator{tag.Insert(tagName, name)},
measure: rp.ShortWatches,
}
}
// ShortWatchesView returns a view of the ShortWatches metric.
func (rp *ReflectorProvider) ShortWatchesView() *view.View {
return measureView(rp.ShortWatches, view.Count())
}
// NewWatchDurationMetric implements MetricsProvider
func (rp *ReflectorProvider) NewWatchDurationMetric(name string) cache.SummaryMetric {
return floatMetric{
mutators: []tag.Mutator{tag.Insert(tagName, name)},
measure: rp.WatchDuration,
}
}
// WatchDurationView returns a view of the WatchDuration metric.
func (rp *ReflectorProvider) WatchDurationView() *view.View {
return measureView(rp.WatchDuration, view.Distribution(BucketsNBy10(0.1, 6)...))
}
// NewWatchesMetric implements MetricsProvider
func (rp *ReflectorProvider) NewWatchesMetric(name string) cache.CounterMetric {
return counterMetric{
mutators: []tag.Mutator{tag.Insert(tagName, name)},
measure: rp.Watches,
}
}
// WatchesView returns a view of the Watches metric.
func (rp *ReflectorProvider) WatchesView() *view.View {
return measureView(rp.Watches, view.Count())
}
// DefaultViews returns a list of views suitable for passing to view.Register
func (rp *ReflectorProvider) DefaultViews() []*view.View {
return []*view.View{
rp.ItemsInListView(),
rp.ItemsInMatchView(),
rp.ItemsInWatchView(),
rp.LastResourceVersionView(),
rp.ListDurationView(),
rp.ListsView(),
rp.ShortWatchesView(),
rp.WatchDurationView(),
rp.WatchesView(),
}
}

View File

@ -0,0 +1,114 @@
/*
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 (
"go.opencensus.io/stats"
"go.opencensus.io/stats/view"
"go.opencensus.io/tag"
"k8s.io/client-go/util/workqueue"
)
// WorkqueueProvider implements workqueue.MetricsProvider and may be used with
// workqueue.SetProvider to have metrics exported to the provided metrics.
type WorkqueueProvider struct {
Adds *stats.Int64Measure
Depth *stats.Int64Measure
Latency *stats.Float64Measure
Retries *stats.Int64Measure
WorkDuration *stats.Float64Measure
}
var (
_ workqueue.MetricsProvider = (*WorkqueueProvider)(nil)
)
// NewAddsMetric implements MetricsProvider
func (wp *WorkqueueProvider) NewAddsMetric(name string) workqueue.CounterMetric {
return counterMetric{
mutators: []tag.Mutator{tag.Insert(tagName, name)},
measure: wp.Adds,
}
}
// AddsView returns a view of the Adds metric.
func (wp *WorkqueueProvider) AddsView() *view.View {
return measureView(wp.Adds, view.Count())
}
// NewDepthMetric implements MetricsProvider
func (wp *WorkqueueProvider) NewDepthMetric(name string) workqueue.GaugeMetric {
return &gaugeMetric{
mutators: []tag.Mutator{tag.Insert(tagName, name)},
measure: wp.Depth,
}
}
// DepthView returns a view of the Depth metric.
func (wp *WorkqueueProvider) DepthView() *view.View {
return measureView(wp.Depth, view.LastValue())
}
// NewLatencyMetric implements MetricsProvider
func (wp *WorkqueueProvider) NewLatencyMetric(name string) workqueue.SummaryMetric {
return floatMetric{
mutators: []tag.Mutator{tag.Insert(tagName, name)},
measure: wp.Latency,
}
}
// LatencyView returns a view of the Latency metric.
func (wp *WorkqueueProvider) LatencyView() *view.View {
return measureView(wp.Latency, view.Distribution(BucketsNBy10(1e-08, 10)...))
}
// NewRetriesMetric implements MetricsProvider
func (wp *WorkqueueProvider) NewRetriesMetric(name string) workqueue.CounterMetric {
return counterMetric{
mutators: []tag.Mutator{tag.Insert(tagName, name)},
measure: wp.Retries,
}
}
// RetriesView returns a view of the Retries metric.
func (wp *WorkqueueProvider) RetriesView() *view.View {
return measureView(wp.Retries, view.Count())
}
// NewWorkDurationMetric implements MetricsProvider
func (wp *WorkqueueProvider) NewWorkDurationMetric(name string) workqueue.SummaryMetric {
return floatMetric{
mutators: []tag.Mutator{tag.Insert(tagName, name)},
measure: wp.WorkDuration,
}
}
// WorkDurationView returns a view of the WorkDuration metric.
func (wp *WorkqueueProvider) WorkDurationView() *view.View {
return measureView(wp.WorkDuration, view.Distribution(BucketsNBy10(1e-08, 10)...))
}
// DefaultViews returns a list of views suitable for passing to view.Register
func (wp *WorkqueueProvider) DefaultViews() []*view.View {
return []*view.View{
wp.AddsView(),
wp.DepthView(),
wp.LatencyView(),
wp.RetriesView(),
wp.WorkDurationView(),
}
}

View File

@ -46,13 +46,11 @@ type GenerateNameReactor struct {
// mocking
func (r *GenerateNameReactor) Handles(action clientgotesting.Action) bool {
create, ok := action.(clientgotesting.CreateAction)
if !ok {
return false
}
objMeta, err := meta.Accessor(create.GetObject())
if err != nil {
return false
}

View File

@ -18,16 +18,5 @@ limitations under the License.
Package clustermanager provides support for managing clusters for e2e tests,
responsible for creating/deleting cluster, and cluster life cycle management if
running in Prow
usage example:
func acquireCluster() {
clusterOps := GKEClient{}.Setup(2, "n1-standard-8", "us-east1", "a", "myproject")
// Cast to GKEOperation
GKEOps := clusterOps.(GKECluster)
if err = GKEOps.Acquire(); err != nil {
log.Fatalf("Failed acquire cluster: '%v'", err)
}
log.Printf("GKE project is: %s", GKEOps.Project)
log.Printf("GKE cluster is: %v", GKEOps.Cluster)
}
*/
package clustermanager

View File

@ -23,12 +23,12 @@ import (
"strings"
"time"
container "google.golang.org/api/container/v1beta1"
"knative.dev/pkg/testutils/clustermanager/boskos"
"knative.dev/pkg/testutils/common"
"golang.org/x/net/context"
"golang.org/x/oauth2/google"
"google.golang.org/api/container/v1"
)
const (
@ -60,6 +60,7 @@ type GKERequest struct {
Region string
Zone string
BackupRegions []string
Addons []string
}
// GKECluster implements ClusterOperations
@ -114,14 +115,18 @@ func (gsc *GKESDKClient) getOperation(project, location, opName string) (*contai
// nodeType: default to n1-standard-4 if not provided
// region: default to regional cluster if not provided, and use default backup regions
// zone: default is none, must be provided together with region
func (gs *GKEClient) Setup(numNodes *int64, nodeType *string, region *string, zone *string, project *string) ClusterOperations {
// project: no default
// addons: cluster addons to be added to cluster
func (gs *GKEClient) Setup(numNodes *int64, nodeType *string, region *string, zone *string, project *string, addons []string) ClusterOperations {
gc := &GKECluster{
Request: &GKERequest{
NumNodes: DefaultGKENumNodes,
NodeType: DefaultGKENodeType,
Region: DefaultGKERegion,
Zone: DefaultGKEZone,
BackupRegions: DefaultGKEBackupRegions},
BackupRegions: DefaultGKEBackupRegions,
Addons: addons,
},
}
if nil != project { // use provided project and create cluster
@ -237,6 +242,10 @@ func (gc *GKECluster) Acquire() error {
rb := &container.CreateClusterRequest{
Cluster: &container.Cluster{
Name: clusterName,
// Installing addons after cluster creation takes at least 5
// minutes, so install addons as part of cluster creation, which
// doesn't seem to add much time on top of cluster creation
AddonsConfig: gc.getAddonsConfig(),
InitialNodeCount: gc.Request.NumNodes,
NodeConfig: &container.NodeConfig{
MachineType: gc.Request.NodeType,
@ -321,6 +330,27 @@ func (gc *GKECluster) Delete() error {
return nil
}
// getAddonsConfig gets AddonsConfig from Request, contains the logic of
// converting string argument to typed AddonsConfig, for example `IstioConfig`.
// Currently supports istio
func (gc *GKECluster) getAddonsConfig() *container.AddonsConfig {
const (
// Define all supported addons here
istio = "istio"
)
ac := &container.AddonsConfig{}
for _, name := range gc.Request.Addons {
switch strings.ToLower(name) {
case istio:
ac.IstioConfig = &container.IstioConfig{Disabled: false}
default:
panic(fmt.Sprintf("addon type %q not supported. Has to be one of: %q", name, istio))
}
}
return ac
}
// wait depends on unique opName(operation ID created by cloud), and waits until
// it's done
func (gc *GKECluster) wait(location, opName string, wait time.Duration) error {

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Copyright 2019 The Knative Authors
#
@ -226,7 +226,7 @@ function create_test_cluster() {
local test_wrapper="${kubedir}/e2e-test.sh"
mkdir ${kubedir}/cluster
ln -s "$(which kubectl)" ${kubedir}/cluster/kubectl.sh
echo "#!/bin/bash" > ${test_wrapper}
echo "#!/usr/bin/env bash" > ${test_wrapper}
echo "cd $(pwd) && set -x" >> ${test_wrapper}
echo "${E2E_SCRIPT} ${test_cmd_args}" >> ${test_wrapper}
chmod +x ${test_wrapper}

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Copyright 2018 The Knative Authors
#
@ -283,9 +283,9 @@ function acquire_cluster_admin_role() {
local key=$(mktemp)
echo "Certificate in ${cert}, key in ${key}"
gcloud --format="value(masterAuth.clientCertificate)" \
container clusters describe $2 ${geoflag} | base64 -d > ${cert}
container clusters describe $2 ${geoflag} | base64 --decode > ${cert}
gcloud --format="value(masterAuth.clientKey)" \
container clusters describe $2 ${geoflag} | base64 -d > ${key}
container clusters describe $2 ${geoflag} | base64 --decode > ${key}
kubectl config set-credentials cluster-admin \
--client-certificate=${cert} --client-key=${key}
fi
@ -584,5 +584,5 @@ readonly REPO_NAME_FORMATTED="Knative $(capitalize ${REPO_NAME//-/ })"
# Public latest nightly or release yaml files.
readonly KNATIVE_SERVING_RELEASE="$(get_latest_knative_yaml_source "serving" "serving")"
readonly KNATIVE_BUILD_RELEASE="$(get_latest_knative_yaml_source "build" "build")"
readonly KNATIVE_EVENTING_RELEASE="$(get_latest_knative_yaml_source "eventing" "release")"
readonly KNATIVE_MONITORING_RELEASE="$(get_latest_knative_yaml_source "serving" "monitoring")"

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Copyright 2018 The Knative Authors
#

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# Copyright 2018 The Knative Authors
#