mirror of https://github.com/knative/pkg.git
Assorted linting fixes. (#1507)
- Remove unused code. - Remove unnecessary conversion. - Prevent copies of structs that contain sync.Mutex.
This commit is contained in:
parent
096656a2d4
commit
cb729b8ae6
|
|
@ -27,19 +27,10 @@ import (
|
||||||
const (
|
const (
|
||||||
testNS = "test"
|
testNS = "test"
|
||||||
testService = "test-service"
|
testService = "test-service"
|
||||||
testRoute = "test-route"
|
|
||||||
testRevision = "test-revision"
|
testRevision = "test-revision"
|
||||||
testConfiguration = "test-configuration"
|
testConfiguration = "test-configuration"
|
||||||
testContainer = "test-container"
|
testContainer = "test-container"
|
||||||
testPod = "test-pod"
|
testPod = "test-pod"
|
||||||
|
|
||||||
testBroker = "test-broker"
|
|
||||||
testEventType = "test-eventtype"
|
|
||||||
testEventSource = "test-eventsource"
|
|
||||||
testTrigger = "test-trigger"
|
|
||||||
testFilterType = "test-filtertype"
|
|
||||||
testSource = "test-source"
|
|
||||||
testSourceResourceGroup = "test-source-rg"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
|
|
||||||
|
|
@ -646,11 +646,11 @@ type stackDriverFake struct {
|
||||||
address string
|
address string
|
||||||
srv *grpc.Server
|
srv *grpc.Server
|
||||||
t *testing.T
|
t *testing.T
|
||||||
published chan stackdriverpb.CreateTimeSeriesRequest
|
published chan *stackdriverpb.CreateTimeSeriesRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sd *stackDriverFake) start() error {
|
func (sd *stackDriverFake) start() error {
|
||||||
sd.published = make(chan stackdriverpb.CreateTimeSeriesRequest, 100)
|
sd.published = make(chan *stackdriverpb.CreateTimeSeriesRequest, 100)
|
||||||
ln, err := net.Listen("tcp", sd.address)
|
ln, err := net.Listen("tcp", sd.address)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
@ -666,7 +666,7 @@ func (sd *stackDriverFake) start() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sd *stackDriverFake) CreateTimeSeries(ctx context.Context, req *stackdriverpb.CreateTimeSeriesRequest) (*emptypb.Empty, error) {
|
func (sd *stackDriverFake) CreateTimeSeries(ctx context.Context, req *stackdriverpb.CreateTimeSeriesRequest) (*emptypb.Empty, error) {
|
||||||
sd.published <- *req
|
sd.published <- req
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -688,8 +688,7 @@ func (sd *stackDriverFake) GetMetricDescriptor(context.Context, *stackdriverpb.G
|
||||||
return nil, fmt.Errorf("Unimplemented")
|
return nil, fmt.Errorf("Unimplemented")
|
||||||
}
|
}
|
||||||
func (sd *stackDriverFake) CreateMetricDescriptor(ctx context.Context, req *stackdriverpb.CreateMetricDescriptorRequest) (*metricpb.MetricDescriptor, error) {
|
func (sd *stackDriverFake) CreateMetricDescriptor(ctx context.Context, req *stackdriverpb.CreateMetricDescriptorRequest) (*metricpb.MetricDescriptor, error) {
|
||||||
resp := *req.MetricDescriptor
|
return req.MetricDescriptor, nil
|
||||||
return &resp, nil
|
|
||||||
}
|
}
|
||||||
func (sd *stackDriverFake) DeleteMetricDescriptor(context.Context, *stackdriverpb.DeleteMetricDescriptorRequest) (*emptypb.Empty, error) {
|
func (sd *stackDriverFake) DeleteMetricDescriptor(context.Context, *stackdriverpb.DeleteMetricDescriptorRequest) (*emptypb.Empty, error) {
|
||||||
sd.t.Fatalf("DeleteMetricDescriptor")
|
sd.t.Fatalf("DeleteMetricDescriptor")
|
||||||
|
|
|
||||||
|
|
@ -274,12 +274,6 @@ func sdCustomMetricsRecorder(mc metricsConfig, allowCustomMetrics bool) func(con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// clientConfig stores the stackdriver configs for cerating additional connections.
|
|
||||||
type clientConfig struct {
|
|
||||||
storeConfig *metricsConfig
|
|
||||||
storeLogger *zap.SugaredLogger
|
|
||||||
}
|
|
||||||
|
|
||||||
// getStackdriverExporterClientOptions creates client options for the opencensus Stackdriver exporter from the given stackdriverClientConfig.
|
// getStackdriverExporterClientOptions creates client options for the opencensus Stackdriver exporter from the given stackdriverClientConfig.
|
||||||
// On error, an empty array of client options is returned.
|
// On error, an empty array of client options is returned.
|
||||||
func getStackdriverExporterClientOptions(config *metricsConfig) ([]option.ClientOption, error) {
|
func getStackdriverExporterClientOptions(config *metricsConfig) ([]option.ClientOption, error) {
|
||||||
|
|
|
||||||
|
|
@ -39,38 +39,11 @@ import (
|
||||||
// TODO UTs should move to eventing and serving, as appropriate.
|
// TODO UTs should move to eventing and serving, as appropriate.
|
||||||
// See https://github.com/knative/pkg/issues/608
|
// See https://github.com/knative/pkg/issues/608
|
||||||
|
|
||||||
var (
|
var testGcpMetadata = gcpMetadata{
|
||||||
revisionTestTags = map[string]string{
|
project: "test-project",
|
||||||
metricskey.LabelNamespaceName: testNS,
|
location: "test-location",
|
||||||
metricskey.LabelServiceName: testService,
|
cluster: "test-cluster",
|
||||||
metricskey.LabelRouteName: testRoute, // Not a label key for knative_revision resource
|
}
|
||||||
metricskey.LabelRevisionName: testRevision,
|
|
||||||
}
|
|
||||||
brokerTestTags = map[string]string{
|
|
||||||
metricskey.LabelNamespaceName: testNS,
|
|
||||||
metricskey.LabelBrokerName: testBroker,
|
|
||||||
metricskey.LabelEventType: testEventType, // Not a label key for knative_broker resource
|
|
||||||
}
|
|
||||||
triggerTestTags = map[string]string{
|
|
||||||
metricskey.LabelNamespaceName: testNS,
|
|
||||||
metricskey.LabelTriggerName: testTrigger,
|
|
||||||
metricskey.LabelBrokerName: testBroker,
|
|
||||||
metricskey.LabelFilterType: testFilterType, // Not a label key for knative_trigger resource
|
|
||||||
}
|
|
||||||
sourceTestTags = map[string]string{
|
|
||||||
metricskey.LabelNamespaceName: testNS,
|
|
||||||
metricskey.LabelName: testSource,
|
|
||||||
metricskey.LabelResourceGroup: testSourceResourceGroup,
|
|
||||||
metricskey.LabelEventType: testEventType, // Not a label key for knative_source resource
|
|
||||||
metricskey.LabelEventSource: testEventSource, // Not a label key for knative_source resource
|
|
||||||
}
|
|
||||||
|
|
||||||
testGcpMetadata = gcpMetadata{
|
|
||||||
project: "test-project",
|
|
||||||
location: "test-location",
|
|
||||||
cluster: "test-cluster",
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func fakeGcpMetadataFunc() *gcpMetadata {
|
func fakeGcpMetadataFunc() *gcpMetadata {
|
||||||
// the caller of this function could modify the struct, so we need a copy if we don't want the original modified.
|
// the caller of this function could modify the struct, so we need a copy if we don't want the original modified.
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ func TestHTTPSpanIgnoringPaths(t *testing.T) {
|
||||||
middleware.ServeHTTP(fw, req)
|
middleware.ServeHTTP(fw, req)
|
||||||
|
|
||||||
// Assert our next handler was called
|
// Assert our next handler was called
|
||||||
if got, want := string(fw.lastWrite), "fake"; got != want {
|
if got, want := fw.lastWrite, "fake"; got != want {
|
||||||
t.Errorf("HTTP response: %q, want: %q", got, want)
|
t.Errorf("HTTP response: %q, want: %q", got, want)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue