diff --git a/Gopkg.lock b/Gopkg.lock index 4c5103ff..8359b60e 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -68,19 +68,6 @@ revision = "346938d642f2ec3594ed81d874461961cd0faa76" version = "v1.1.0" -[[projects]] - branch = "master" - name = "github.com/directxman12/k8s-prometheus-adapter" - packages = [ - "cmd/adapter/app", - "cmd/config-gen/utils", - "pkg/client", - "pkg/client/metrics", - "pkg/config", - "pkg/custom-provider" - ] - revision = "7b606a79fc2fdc4246e455e8f28503e0b4807a92" - [[projects]] name = "github.com/elazarl/go-bindata-assetfs" packages = ["."] @@ -815,6 +802,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "66b8ba4b829725e88ff6ba39c022bdf9670bdffa53ef9f8094c84e0c1447d2db" + inputs-digest = "14918e76a061ac7466e9c6fa723afb8a0c888021c78e6a75c8275d5205e2bb60" solver-name = "gps-cdcl" solver-version = 1 diff --git a/pkg/custom-provider/external_provider.go b/pkg/custom-provider/external_provider.go index b21035ac..1077e629 100644 --- a/pkg/custom-provider/external_provider.go +++ b/pkg/custom-provider/external_provider.go @@ -17,9 +17,12 @@ limitations under the License. package provider import ( + "context" "fmt" "time" + pmodel "github.com/prometheus/common/model" + "github.com/kubernetes-incubator/custom-metrics-apiserver/pkg/provider" apimeta "k8s.io/apimachinery/pkg/api/meta" "k8s.io/apimachinery/pkg/labels" @@ -29,6 +32,11 @@ import ( prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client" ) +//TODO: Some of these members may not be necessary. +//Some of them are definitely duplicated between the +//external and custom providers. They should probably share +//the same instances of these objects (especially the SeriesRegistry) +//to cut down on unnecessary chatter/bookkeeping. type externalPrometheusProvider struct { mapper apimeta.RESTMapper kubeClient dynamic.Interface @@ -38,6 +46,12 @@ type externalPrometheusProvider struct { SeriesRegistry } +//TODO: It probably makes more sense to, once this is functional and complete, roll the +//customPrometheusProvider and externalPrometheusProvider up into a single type +//that implements both interfaces or provide a thin wrapper that composes them. +//Just glancing at start.go looks like it would be much more straightforward +//to do one of those two things instead of trying to run the two providers +//independently. func NewExternalPrometheusProvider(mapper apimeta.RESTMapper, kubeClient dynamic.Interface, promClient prom.Client, namers []MetricNamer, updateInterval time.Duration, queryBuilder ExternalMetricQueryBuilder) (provider.ExternalMetricsProvider, Runnable) { lister := &cachingMetricsLister{ updateInterval: updateInterval, @@ -59,21 +73,17 @@ func NewExternalPrometheusProvider(mapper apimeta.RESTMapper, kubeClient dynamic } func (p *externalPrometheusProvider) GetExternalMetric(namespace string, metricName string, metricSelector labels.Selector) (*external_metrics.ExternalMetricValueList, error) { - //TODO: Steps - //1. Generate a Prometheus Query. - // Something like my_metric{namespace="namespace" some_label="some_value"} - //2. Send that query to Prometheus. - //3. Adapt the results. - //The query generation for external metrics is much more straightforward - //than for custom metrics because no renaming is applied. - //So we'll just start with some simple string operations and see how far that gets us. - //Then I'll circle back and figure out how much code reuse I can get out of the original implementation. query := p.queryBuilder.BuildPrometheusQuery(namespace, metricName, metricSelector) + selector := prom.Selector(query) + + //TODO: I don't yet know what a context is, but apparently I should use a real one. + queryResults, err := p.promClient.Query(context.TODO(), pmodel.Now(), selector) //TODO: Only here to stop compiler issues in this incomplete code. - fmt.Printf(query) + fmt.Printf("%s, %s", queryResults, err) - //TODO: Construct a real result. + //TODO: Check for errors. See what the custromPrometheusProvider does for errors. + //TODO: Adapt the results in queryResults to the appropriate return type. return nil, nil }