Fixing dependency in custom-provider

This commit is contained in:
John Delivuk 2019-02-11 12:12:57 -05:00
parent ed9eb31b3a
commit 8ef8c8a291
No known key found for this signature in database
GPG key ID: 8597474A0655625E
7 changed files with 27 additions and 22 deletions

View file

@ -37,6 +37,7 @@ import (
"k8s.io/metrics/pkg/apis/custom_metrics" "k8s.io/metrics/pkg/apis/custom_metrics"
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client" prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
"github.com/directxman12/k8s-prometheus-adapter/pkg/naming"
) )
// Runnable represents something that can be run until told to stop. // Runnable represents something that can be run until told to stop.
@ -55,7 +56,7 @@ type prometheusProvider struct {
SeriesRegistry SeriesRegistry
} }
func NewPrometheusProvider(mapper apimeta.RESTMapper, kubeClient dynamic.Interface, promClient prom.Client, namers []MetricNamer, updateInterval time.Duration, maxAge time.Duration) (provider.CustomMetricsProvider, Runnable) { func NewPrometheusProvider(mapper apimeta.RESTMapper, kubeClient dynamic.Interface, promClient prom.Client, namers []naming.MetricNamer, updateInterval time.Duration, maxAge time.Duration) (provider.CustomMetricsProvider, Runnable) {
lister := &cachingMetricsLister{ lister := &cachingMetricsLister{
updateInterval: updateInterval, updateInterval: updateInterval,
maxAge: maxAge, maxAge: maxAge,
@ -193,7 +194,7 @@ type cachingMetricsLister struct {
promClient prom.Client promClient prom.Client
updateInterval time.Duration updateInterval time.Duration
maxAge time.Duration maxAge time.Duration
namers []MetricNamer namers []naming.MetricNamer
} }
func (l *cachingMetricsLister) Run() { func (l *cachingMetricsLister) Run() {

View file

@ -28,6 +28,7 @@ import (
config "github.com/directxman12/k8s-prometheus-adapter/cmd/config-gen/utils" config "github.com/directxman12/k8s-prometheus-adapter/cmd/config-gen/utils"
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client" prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
fakeprom "github.com/directxman12/k8s-prometheus-adapter/pkg/client/fake" fakeprom "github.com/directxman12/k8s-prometheus-adapter/pkg/client/fake"
"github.com/directxman12/k8s-prometheus-adapter/pkg/naming"
pmodel "github.com/prometheus/common/model" pmodel "github.com/prometheus/common/model"
) )
@ -39,7 +40,7 @@ func setupPrometheusProvider() (provider.CustomMetricsProvider, *fakeprom.FakePr
fakeKubeClient := &fakedyn.FakeDynamicClient{} fakeKubeClient := &fakedyn.FakeDynamicClient{}
cfg := config.DefaultConfig(1*time.Minute, "") cfg := config.DefaultConfig(1*time.Minute, "")
namers, err := NamersFromConfig(cfg, restMapper()) namers, err := naming.NamersFromConfig(cfg, restMapper())
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
prov, _ := NewPrometheusProvider(restMapper(), fakeKubeClient, fakeProm, namers, fakeProviderUpdateInterval, fakeProviderStartDuration) prov, _ := NewPrometheusProvider(restMapper(), fakeKubeClient, fakeProm, namers, fakeProviderUpdateInterval, fakeProviderStartDuration)

View file

@ -24,6 +24,7 @@ import (
apimeta "k8s.io/apimachinery/pkg/api/meta" apimeta "k8s.io/apimachinery/pkg/api/meta"
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client" prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
"github.com/directxman12/k8s-prometheus-adapter/pkg/naming"
"github.com/golang/glog" "github.com/golang/glog"
pmodel "github.com/prometheus/common/model" pmodel "github.com/prometheus/common/model"
) )
@ -45,7 +46,7 @@ const (
type SeriesRegistry interface { type SeriesRegistry interface {
// SetSeries replaces the known series in this registry. // SetSeries replaces the known series in this registry.
// Each slice in series should correspond to a MetricNamer in namers. // Each slice in series should correspond to a MetricNamer in namers.
SetSeries(series [][]prom.Series, namers []MetricNamer) error SetSeries(series [][]prom.Series, namers []naming.MetricNamer) error
// ListAllMetrics lists all metrics known to this registry // ListAllMetrics lists all metrics known to this registry
ListAllMetrics() []provider.CustomMetricInfo ListAllMetrics() []provider.CustomMetricInfo
// SeriesForMetric looks up the minimum required series information to make a query for the given metric // SeriesForMetric looks up the minimum required series information to make a query for the given metric
@ -60,7 +61,7 @@ type seriesInfo struct {
seriesName string seriesName string
// namer is the MetricNamer used to name this series // namer is the MetricNamer used to name this series
namer MetricNamer namer naming.MetricNamer
} }
// overridableSeriesRegistry is a basic SeriesRegistry // overridableSeriesRegistry is a basic SeriesRegistry
@ -75,7 +76,7 @@ type basicSeriesRegistry struct {
mapper apimeta.RESTMapper mapper apimeta.RESTMapper
} }
func (r *basicSeriesRegistry) SetSeries(newSeriesSlices [][]prom.Series, namers []MetricNamer) error { func (r *basicSeriesRegistry) SetSeries(newSeriesSlices [][]prom.Series, namers []naming.MetricNamer) error {
if len(newSeriesSlices) != len(namers) { if len(newSeriesSlices) != len(namers) {
return fmt.Errorf("need one set of series per namer") return fmt.Errorf("need one set of series per namer")
} }
@ -99,7 +100,7 @@ func (r *basicSeriesRegistry) SetSeries(newSeriesSlices [][]prom.Series, namers
} }
// namespace metrics aren't counted as namespaced // namespace metrics aren't counted as namespaced
if resource == nsGroupResource { if resource == naming.NsGroupResource {
info.Namespaced = false info.Namespaced = false
} }

View file

@ -31,6 +31,7 @@ import (
config "github.com/directxman12/k8s-prometheus-adapter/cmd/config-gen/utils" config "github.com/directxman12/k8s-prometheus-adapter/cmd/config-gen/utils"
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client" prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
"github.com/directxman12/k8s-prometheus-adapter/pkg/naming"
) )
// restMapper creates a RESTMapper with just the types we need for // restMapper creates a RESTMapper with just the types we need for
@ -50,9 +51,9 @@ func restMapper() apimeta.RESTMapper {
return mapper return mapper
} }
func setupMetricNamer() []MetricNamer { func setupMetricNamer() []naming.MetricNamer {
cfg := config.DefaultConfig(1*time.Minute, "kube_") cfg := config.DefaultConfig(1*time.Minute, "kube_")
namers, err := NamersFromConfig(cfg, restMapper()) namers, err := naming.NamersFromConfig(cfg, restMapper())
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
return namers return namers
} }

View file

@ -3,19 +3,19 @@ package provider
import "errors" import "errors"
var ( var (
// ErrorNewOperatorNotSupportedByPrometheus creates an error that represents the fact that we were requested to service a query that // ErrNewOperatorNotSupportedByPrometheus creates an error that represents the fact that we were requested to service a query that
// Prometheus would be unable to support. // Prometheus would be unable to support.
ErrorNewOperatorNotSupportedByPrometheus = errors.New("operator not supported by prometheus") ErrNewOperatorNotSupportedByPrometheus = errors.New("operator not supported by prometheus")
// ErrorNewOperatorRequiresValues creates an error that represents the fact that we were requested to service a query // ErrNewOperatorRequiresValues creates an error that represents the fact that we were requested to service a query
// that was malformed in its operator/value combination. // that was malformed in its operator/value combination.
ErrorNewOperatorRequiresValues = errors.New("operator requires values") ErrNewOperatorRequiresValues = errors.New("operator requires values")
// ErrorNewOperatorDoesNotSupportValues creates an error that represents the fact that we were requested to service a query // ErrNewOperatorDoesNotSupportValues creates an error that represents the fact that we were requested to service a query
// that was malformed in its operator/value combination. // that was malformed in its operator/value combination.
ErrorNewOperatorDoesNotSupportValues = errors.New("operator does not support values") ErrNewOperatorDoesNotSupportValues = errors.New("operator does not support values")
// ErrorNewLabelNotSpecified creates an error that represents the fact that we were requested to service a query // ErrNewLabelNotSpecified creates an error that represents the fact that we were requested to service a query
// that was malformed in its label specification. // that was malformed in its label specification.
ErrorNewLabelNotSpecified = errors.New("label not specified") ErrNewLabelNotSpecified = errors.New("label not specified")
) )

View file

@ -21,6 +21,7 @@ type ExternalSeriesRegistry interface {
// overridableSeriesRegistry is a basic SeriesRegistry // overridableSeriesRegistry is a basic SeriesRegistry
type externalSeriesRegistry struct { type externalSeriesRegistry struct {
// We lock when reading/writing metrics, and rawMetrics to prevent inconsistencies.
mu sync.RWMutex mu sync.RWMutex
// metrics is the list of all known metrics, ready to return from the API // metrics is the list of all known metrics, ready to return from the API

View file

@ -92,11 +92,11 @@ func (n *queryBuilder) processQueryParts(queryParts []queryPart) ([]string, map[
// We obviously can't generate label filters for these cases. // We obviously can't generate label filters for these cases.
fmt.Println("This is queryPart", qPart.labelName, qPart.operator, qPart.values) fmt.Println("This is queryPart", qPart.labelName, qPart.operator, qPart.values)
if qPart.labelName == "" { if qPart.labelName == "" {
return nil, nil, ErrorNewLabelNotSpecified return nil, nil, ErrNewLabelNotSpecified
} }
if !n.operatorIsSupported(qPart.operator) { if !n.operatorIsSupported(qPart.operator) {
return nil, nil, ErrorNewOperatorNotSupportedByPrometheus return nil, nil, ErrNewOperatorNotSupportedByPrometheus
} }
matcher, err := n.selectMatcher(qPart.operator, qPart.values) matcher, err := n.selectMatcher(qPart.operator, qPart.values)
@ -128,7 +128,7 @@ func (n *queryBuilder) selectMatcher(operator selection.Operator, values []strin
case selection.DoesNotExist: case selection.DoesNotExist:
return prom.LabelEq, nil return prom.LabelEq, nil
case selection.Equals, selection.DoubleEquals, selection.NotEquals, selection.In, selection.NotIn: case selection.Equals, selection.DoubleEquals, selection.NotEquals, selection.In, selection.NotIn:
return nil, ErrorNewOperatorRequiresValues return nil, ErrNewOperatorRequiresValues
} }
} else if numValues == 1 { } else if numValues == 1 {
switch operator { switch operator {
@ -168,7 +168,7 @@ func (n *queryBuilder) selectTargetValue(operator selection.Operator, values []s
// whose value is NOT "". // whose value is NOT "".
return "", nil return "", nil
case selection.Equals, selection.DoubleEquals, selection.NotEquals, selection.In, selection.NotIn: case selection.Equals, selection.DoubleEquals, selection.NotEquals, selection.In, selection.NotIn:
return "", ErrorNewOperatorRequiresValues return "", ErrNewOperatorRequiresValues
} }
} else if numValues == 1 { } else if numValues == 1 {
switch operator { switch operator {
@ -194,7 +194,7 @@ func (n *queryBuilder) selectTargetValue(operator selection.Operator, values []s
// for their label selector. // for their label selector.
return strings.Join(values, "|"), nil return strings.Join(values, "|"), nil
case selection.Exists, selection.DoesNotExist: case selection.Exists, selection.DoesNotExist:
return "", ErrorNewOperatorDoesNotSupportValues return "", ErrNewOperatorDoesNotSupportValues
} }
} }