From 980bc01d6785c026d34eec5a79cd8641c9f410b6 Mon Sep 17 00:00:00 2001 From: John Delivuk Date: Fri, 22 Feb 2019 10:04:10 -0500 Subject: [PATCH] Updating Errors, and adding license --- pkg/external-provider/errors.go | 18 +++++++++--------- pkg/external-provider/provider.go | 14 +++++++++++++- pkg/external-provider/query_builder.go | 10 +++++----- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/pkg/external-provider/errors.go b/pkg/external-provider/errors.go index c55a18e7..ba741019 100644 --- a/pkg/external-provider/errors.go +++ b/pkg/external-provider/errors.go @@ -3,19 +3,19 @@ package provider import "errors" var ( - // ErrNewOperatorNotSupportedByPrometheus creates an error that represents the fact that we were requested to service a query that + // ErrUnsupportedOperator creates an error that represents the fact that we were requested to service a query that // Prometheus would be unable to support. - ErrNewOperatorNotSupportedByPrometheus = errors.New("operator not supported by prometheus") + ErrUnsupportedOperator = errors.New("operator not supported by prometheus") - // ErrNewOperatorRequiresValues creates an error that represents the fact that we were requested to service a query + // ErrMalformedQuery creates an error that represents the fact that we were requested to service a query // that was malformed in its operator/value combination. - ErrNewOperatorRequiresValues = errors.New("operator requires values") + ErrMalformedQuery = errors.New("operator requires values") - // ErrNewOperatorDoesNotSupportValues creates an error that represents the fact that we were requested to service a query - // that was malformed in its operator/value combination. - ErrNewOperatorDoesNotSupportValues = errors.New("operator does not support values") + // ErrQueryUnsupportedValues creates an error that represents an unsupported return value from the + // specified query. + ErrQueryUnsupportedValues = errors.New("operator does not support values") - // ErrNewLabelNotSpecified creates an error that represents the fact that we were requested to service a query + // ErrLabelNotSpecified creates an error that represents the fact that we were requested to service a query // that was malformed in its label specification. - ErrNewLabelNotSpecified = errors.New("label not specified") + ErrLabelNotSpecified = errors.New("label not specified") ) diff --git a/pkg/external-provider/provider.go b/pkg/external-provider/provider.go index 74a13e95..48a544e2 100644 --- a/pkg/external-provider/provider.go +++ b/pkg/external-provider/provider.go @@ -1,3 +1,16 @@ +/* +Copyright 2017 The Kubernetes 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 provider import ( @@ -21,7 +34,6 @@ import ( "github.com/directxman12/k8s-prometheus-adapter/pkg/naming" ) -// TODO: Make sure everything has the proper licensing disclosure at the top. type externalPrometheusProvider struct { promClient prom.Client metricConverter MetricConverter diff --git a/pkg/external-provider/query_builder.go b/pkg/external-provider/query_builder.go index 51317d01..88702fd2 100644 --- a/pkg/external-provider/query_builder.go +++ b/pkg/external-provider/query_builder.go @@ -92,11 +92,11 @@ func (n *queryBuilder) processQueryParts(queryParts []queryPart) ([]string, map[ // We obviously can't generate label filters for these cases. fmt.Println("This is queryPart", qPart.labelName, qPart.operator, qPart.values) if qPart.labelName == "" { - return nil, nil, ErrNewLabelNotSpecified + return nil, nil, ErrLabelNotSpecified } if !n.operatorIsSupported(qPart.operator) { - return nil, nil, ErrNewOperatorNotSupportedByPrometheus + return nil, nil, ErrUnsupportedOperator } matcher, err := n.selectMatcher(qPart.operator, qPart.values) @@ -128,7 +128,7 @@ func (n *queryBuilder) selectMatcher(operator selection.Operator, values []strin case selection.DoesNotExist: return prom.LabelEq, nil case selection.Equals, selection.DoubleEquals, selection.NotEquals, selection.In, selection.NotIn: - return nil, ErrNewOperatorRequiresValues + return nil, ErrMalformedQuery } } else if numValues == 1 { switch operator { @@ -168,7 +168,7 @@ func (n *queryBuilder) selectTargetValue(operator selection.Operator, values []s // whose value is NOT "". return "", nil case selection.Equals, selection.DoubleEquals, selection.NotEquals, selection.In, selection.NotIn: - return "", ErrNewOperatorRequiresValues + return "", ErrMalformedQuery } } else if numValues == 1 { switch operator { @@ -194,7 +194,7 @@ func (n *queryBuilder) selectTargetValue(operator selection.Operator, values []s // for their label selector. return strings.Join(values, "|"), nil case selection.Exists, selection.DoesNotExist: - return "", ErrNewOperatorDoesNotSupportValues + return "", ErrQueryUnsupportedValues } }