mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-05 17:27:51 +00:00
Updating Errors, and adding license
This commit is contained in:
parent
8ef8c8a291
commit
980bc01d67
3 changed files with 27 additions and 15 deletions
|
|
@ -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")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue