Auto-update dependencies (#99)

Produced via:
  `dep ensure -update knative.dev/test-infra knative.dev/pkg`
/assign mattmoor
This commit is contained in:
mattmoor-sockpuppet 2019-09-13 08:16:37 -07:00 committed by Knative Prow Robot
parent 21bff291f8
commit 6185837d36
10 changed files with 178 additions and 45 deletions

6
Gopkg.lock generated
View File

@ -927,7 +927,7 @@
[[projects]]
branch = "master"
digest = "1:dfd153fff295bf8023d8f9eca57d4c3fd76790619093b1e6d216810b82fed7a2"
digest = "1:bdd1f7aa0a13b578d332f970e36861a834ff8559e06b0b718fa5d8df78e448d8"
name = "knative.dev/pkg"
packages = [
"apis",
@ -946,7 +946,7 @@
"metrics/metricskey",
]
pruneopts = "T"
revision = "87ad483365174cda3ee83f1c0832df930f9adb52"
revision = "34157973944a3419f1e38fce8dfb11a2fb5aadbb"
[[projects]]
branch = "master"
@ -957,7 +957,7 @@
"tools/dep-collector",
]
pruneopts = "UT"
revision = "816123d5e71fb88533d1564c331443387967e1dc"
revision = "ca04b8453a8779f3c800c5e4bcda43ff53ec6f80"
[solve-meta]
analyzer-name = "dep"

View File

@ -312,13 +312,13 @@ func ErrDisallowedUpdateDeprecatedFields(fieldPaths ...string) *FieldError {
}
// ErrInvalidArrayValue constructs a FieldError for a repetetive `field`
// at `index` that has received an invalid string value.
// at `index` that has received an invalid value.
func ErrInvalidArrayValue(value interface{}, field string, index int) *FieldError {
return ErrInvalidValue(value, CurrentField).ViaFieldIndex(field, index)
}
// ErrInvalidValue constructs a FieldError for a field that has received an
// invalid string value.
// invalid value.
func ErrInvalidValue(value interface{}, fieldPath string) *FieldError {
return &FieldError{
Message: fmt.Sprintf("invalid value: %v", value),
@ -326,6 +326,15 @@ func ErrInvalidValue(value interface{}, fieldPath string) *FieldError {
}
}
// ErrGeneric constructs a FieldError to allow for the different error strings for the
// the different cases.
func ErrGeneric(diagnostic string, fieldPaths ...string) *FieldError {
return &FieldError{
Message: diagnostic,
Paths: fieldPaths,
}
}
// ErrMissingOneOf is a variadic helper method for constructing a FieldError for
// not having at least one field in a mutually exclusive field group.
func ErrMissingOneOf(fieldPaths ...string) *FieldError {

View File

@ -18,9 +18,10 @@ package source
import (
"context"
"strconv"
"go.opencensus.io/stats/view"
"knative.dev/pkg/metrics"
"strconv"
"go.opencensus.io/stats"
"go.opencensus.io/tag"

View File

@ -254,12 +254,11 @@ func (sc *SpoofingClient) logZipkinTrace(spoofResp *Response) {
traceID := spoofResp.Header.Get(zipkin.ZipkinTraceIDHeader)
sc.logf("Logging Zipkin Trace for: %s", traceID)
// Sleep to ensure all traces are correctly pushed on the backend.
time.Sleep(5 * time.Second)
json, err := zipkin.JSONTrace(traceID)
json, err := zipkin.JSONTrace(traceID, /* We don't know the expected number of spans */ -1, 5 * time.Second)
if err != nil {
sc.logf("Error getting zipkin trace: %v", err)
if _, ok := err.(*zipkin.TimeoutError); !ok {
sc.logf("Error getting zipkin trace: %v", err)
}
}
sc.logf("%s", json)

View File

@ -40,5 +40,6 @@ Coverage Percentage: <Percentage value of coverage>
`GetCoveragePercentageXMLDisplay()` is a utility method that can be used by
repos to produce coverage percentage for each resource in a Junit XML results
file. The method takes [CoveragePercentages](../coveragecalculator/calculator.go)
as input and produces a Junit result file format.
file. The method takes
[CoveragePercentages](../coveragecalculator/calculator.go) as input and produces
a Junit result file format.

View File

@ -14,17 +14,18 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
//util has constants and helper methods useful for zipkin tracing support.
// util has constants and helper methods useful for zipkin tracing support.
package zipkin
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"sync"
"time"
"github.com/openzipkin/zipkin-go/model"
"go.opencensus.io/trace"
"k8s.io/client-go/kubernetes"
"knative.dev/pkg/test/logging"
@ -32,7 +33,7 @@ import (
)
const (
//ZipkinTraceIDHeader HTTP response header key to be used to store Zipkin Trace ID.
// ZipkinTraceIDHeader HTTP response header key to be used to store Zipkin Trace ID.
ZipkinTraceIDHeader = "ZIPKIN_TRACE_ID"
// ZipkinPort is port exposed by the Zipkin Pod
@ -43,11 +44,11 @@ const (
ZipkinTraceEndpoint = "http://localhost:9411/api/v2/trace/"
// App is the name of this component.
// This will be used as a label selector
// This will be used as a label selector.
app = "zipkin"
// Namespace we are using for istio components
istioNs = "istio-system"
// istioNS is the namespace we are using for istio components.
istioNS = "istio-system"
)
var (
@ -66,21 +67,21 @@ var (
// SetupZipkinTracing sets up zipkin tracing which involves:
// 1. Setting up port-forwarding from localhost to zipkin pod on the cluster
// (pid of the process doing Port-Forward is stored in a global variable).
// 2. Enable AlwaysSample config for tracing.
func SetupZipkinTracing(kubeClientset *kubernetes.Clientset, logf logging.FormatLogger) {
// 2. Enable AlwaysSample config for tracing for the SpoofingClient.
func SetupZipkinTracing(kubeClientset *kubernetes.Clientset, logf logging.FormatLogger) bool {
setupOnce.Do(func() {
if err := monitoring.CheckPortAvailability(ZipkinPort); err != nil {
logf("Zipkin port not available on the machine: %v", err)
return
}
zipkinPods, err := monitoring.GetPods(kubeClientset, app, istioNs)
zipkinPods, err := monitoring.GetPods(kubeClientset, app, istioNS)
if err != nil {
logf("Error retrieving Zipkin pod details: %v", err)
return
}
zipkinPortForwardPID, err = monitoring.PortForward(logf, zipkinPods, ZipkinPort, ZipkinPort, istioNs)
zipkinPortForwardPID, err = monitoring.PortForward(logf, zipkinPods, ZipkinPort, ZipkinPort, istioNS)
if err != nil {
logf("Error starting kubectl port-forward command: %v", err)
return
@ -93,17 +94,31 @@ func SetupZipkinTracing(kubeClientset *kubernetes.Clientset, logf logging.Format
logf("Successfully setup SpoofingClient for Zipkin Tracing")
ZipkinTracingEnabled = true
})
return ZipkinTracingEnabled
}
// CleanupZipkinTracingSetup cleans up the Zipkin tracing setup on the machine. This involves killing the process performing port-forward.
// This should be called exactly once in TestMain. Likely in the form:
//
// func TestMain(m *testing.M) {
// os.Exit(func() int {
// // Any setup required for the tests.
// defer zipkin.CleanupZipkinTracingSetup(logger)
// return m.Run()
// }())
// }
func CleanupZipkinTracingSetup(logf logging.FormatLogger) {
teardownOnce.Do(func() {
// Because CleanupZipkinTracingSetup only runs once, make sure that now that it has been
// run, SetupZipkinTracing will no longer setup any port forwarding.
setupOnce.Do(func() {})
if !ZipkinTracingEnabled {
return
}
if err := monitoring.Cleanup(zipkinPortForwardPID); err != nil {
logf("Encountered error killing port-forward process in CleanupZipkingTracingSetup() : %v", err)
logf("Encountered error killing port-forward process in CleanupZipkinTracingSetup() : %v", err)
return
}
@ -117,29 +132,56 @@ func CheckZipkinPortAvailability() error {
return monitoring.CheckPortAvailability(ZipkinPort)
}
// JSONTrace returns a trace for the given traceId in JSON format
func JSONTrace(traceID string) (string, error) {
// JSONTrace returns a trace for the given traceID. It will continually try to get the trace. If the
// trace it gets has the expected number of spans, then it will be returned. If not, it will try
// again. If it reaches timeout, then it returns everything it has so far with an error.
func JSONTrace(traceID string, expected int, timeout time.Duration) (trace []model.SpanModel, err error) {
t := time.After(timeout)
for ; len(trace) != expected; {
select {
case <-t:
return trace, &TimeoutError{}
default:
trace, err = jsonTrace(traceID)
if err != nil {
return trace, err
}
}
}
return trace, nil
}
// TimeoutError is an error returned by JSONTrace if it times out before getting the expected number
// of traces.
type TimeoutError struct {}
func (*TimeoutError) Error() string {
return "timeout getting JSONTrace"
}
// jsonTrace gets a trace from Zipkin and returns it.
func jsonTrace(traceID string) ([]model.SpanModel, error) {
var empty []model.SpanModel
// Check if zipkin port forwarding is setup correctly
if err := CheckZipkinPortAvailability(); err == nil {
return "", err
return empty, err
}
resp, err := http.Get(ZipkinTraceEndpoint + traceID)
if err != nil {
return "", err
return empty, err
}
defer resp.Body.Close()
trace, err := ioutil.ReadAll(resp.Body)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
return empty, err
}
var prettyJSON bytes.Buffer
err = json.Indent(&prettyJSON, trace, "", "\t")
var models []model.SpanModel
err = json.Unmarshal(body, &models)
if err != nil {
return "", err
return empty, err
}
return prettyJSON.String(), nil
return models, nil
}

View File

@ -37,6 +37,15 @@ var (
defaultWaitDuration = time.Minute * 20
)
type Operation interface {
AcquireGKEProject(*string) (*boskoscommon.Resource, error)
ReleaseGKEProject(*string, string) error
}
type Client struct {
*boskosclient.Client
}
func newClient(host *string) *boskosclient.Client {
if nil == host {
hostName := common.GetOSEnv("JOB_NAME")
@ -48,7 +57,7 @@ func newClient(host *string) *boskosclient.Client {
// AcquireGKEProject acquires GKE Boskos Project with "free" state, and not
// owned by anyone, sets its state to "busy" and assign it an owner of *host,
// which by default is env var `JOB_NAME`.
func AcquireGKEProject(host *string) (*boskoscommon.Resource, error) {
func (c *Client) AcquireGKEProject(host *string) (*boskoscommon.Resource, error) {
ctx, cancel := context.WithTimeout(context.Background(), defaultWaitDuration)
defer cancel()
p, err := newClient(host).AcquireWait(ctx, GKEProjectResource, boskoscommon.Free, boskoscommon.Busy)
@ -66,7 +75,7 @@ func AcquireGKEProject(host *string) (*boskoscommon.Resource, error) {
// "dirty" for Janitor picking up.
// This function is very powerful, it can release Boskos resource acquired by
// other processes, regardless of where the other process is running.
func ReleaseGKEProject(host *string, name string) error {
func (c *Client) ReleaseGKEProject(host *string, name string) error {
client := newClient(host)
if err := client.Release(name, boskoscommon.Dirty); nil != err {
return fmt.Errorf("boskos failed to release GKE project '%s': %v", name, err)

View File

@ -0,0 +1,69 @@
/*
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 fake
import (
"fmt"
boskoscommon "k8s.io/test-infra/boskos/common"
"knative.dev/pkg/testutils/clustermanager/boskos"
)
// FakeBoskosClient implements boskos.Operation
type FakeBoskosClient struct {
resources []*boskoscommon.Resource
}
// AcquireGKEProject fakes to be no op
func (c *FakeBoskosClient) AcquireGKEProject(host *string) (*boskoscommon.Resource, error) {
for _, res := range c.resources {
if res.State == boskoscommon.Free {
res.State = boskoscommon.Busy
return res, nil
}
}
return nil, fmt.Errorf("no GKE project available")
}
// ReleaseGKEProject fakes to be no op
func (c *FakeBoskosClient) ReleaseGKEProject(host *string, name string) error {
if nil == host {
return fmt.Errorf("host has to be set")
}
for _, res := range c.resources {
if res.Name == name {
if res.Owner == *host {
res.Owner = ""
res.State = boskoscommon.Free
return nil
} else {
return fmt.Errorf("Got owner: '%s', expect owner: '%s'", res.Owner, *host)
}
}
}
return fmt.Errorf("resource doesn't exist yet: '%s'", name)
}
// NewGKEProject adds Boskos resources for testing purpose
func (c *FakeBoskosClient) NewGKEProject(name string) {
c.resources = append(c.resources, &boskoscommon.Resource{
Type: boskos.GKEProjectResource,
Name: name,
State: boskoscommon.Free,
})
}

View File

@ -71,6 +71,7 @@ type GKECluster struct {
NeedCleanup bool
Cluster *container.Cluster
operations GKESDKOperations
boskosOps boskos.Operation
}
// GKESDKOperations wraps GKE SDK related functions
@ -152,12 +153,15 @@ func (gs *GKEClient) Setup(numNodes *int64, nodeType *string, region *string, zo
}
gc.operations = &GKESDKClient{containerService}
gc.boskosOps = &boskos.Client{}
return gc
}
// Initialize sets up GKE SDK client, checks environment for cluster and
// projects to decide whether use existing cluster/project or creating new ones.
func (gc *GKECluster) Initialize() error {
// Try obtain project name via `kubectl`, `gcloud`
if nil == gc.Project {
if err := gc.checkEnvironment(); nil != err {
return fmt.Errorf("failed checking existing cluster: '%v'", err)
@ -165,14 +169,13 @@ func (gc *GKECluster) Initialize() error {
return nil
}
}
if nil == gc.Cluster {
if common.IsProw() {
project, err := boskos.AcquireGKEProject(nil)
if nil != err {
return fmt.Errorf("failed acquire boskos project: '%v'", err)
}
gc.Project = &project.Name
// Get project name from boskos if running in Prow
if nil == gc.Project && common.IsProw() {
project, err := gc.boskosOps.AcquireGKEProject(nil)
if nil != err {
return fmt.Errorf("failed acquire boskos project: '%v'", err)
}
gc.Project = &project.Name
}
if nil == gc.Project || "" == *gc.Project {
return errors.New("gcp project must be set")

View File

@ -9,7 +9,7 @@ import (
"contrib.go.opencensus.io/exporter/stackdriver"
oczipkin "contrib.go.opencensus.io/exporter/zipkin"
"github.com/openzipkin/zipkin-go"
zipkin "github.com/openzipkin/zipkin-go"
httpreporter "github.com/openzipkin/zipkin-go/reporter/http"
"go.opencensus.io/trace"
"go.uber.org/zap"