Fixing some refactoring bugs, first half-decent external metrics attempt.

Fixed:
* `basicMetricLister` wasn't applying the appropriate start time because I had forgotten to set the `lookback`.

There are still a number of issues:
* The `externalPrometheusProvider` is not hooked up to the web application yet, so it doesn't serve requests.
* The namespace and label approach used in `external_info_map.go` is horrifically incorrect. It doesn't appropriately store multiple series with the same name but different labels.
* The configuration is still not updated to appropriately handle external metrics, it's sort of half-piggy-backing on the pre-existing work.
This commit is contained in:
Tony Compton 2018-07-20 12:35:49 -04:00
parent 056cb7f7f2
commit 9641e70005
14 changed files with 637 additions and 77 deletions

View file

@ -24,6 +24,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
"github.com/directxman12/k8s-prometheus-adapter/pkg/config"
"github.com/golang/glog"
pmodel "github.com/prometheus/common/model"
)
@ -83,12 +84,33 @@ func NewBasicSeriesRegistry(lister MetricListerWithNotification, mapper apimeta.
metricLister: lister,
}
lister.SetNotificationReceiver(registry.onNewDataAvailable)
lister.AddNotificationReceiver(registry.onNewDataAvailable)
return &registry
}
func (r *basicSeriesRegistry) filterMetrics(result metricUpdateResult) metricUpdateResult {
namers := make([]MetricNamer, 0)
series := make([][]prom.Series, 0)
targetType := config.MetricType("Custom")
for i, namer := range result.namers {
if namer.MetricType() == targetType {
namers = append(namers, namer)
series = append(series, result.series[i])
}
}
return metricUpdateResult{
namers: namers,
series: series,
}
}
func (r *basicSeriesRegistry) onNewDataAvailable(result metricUpdateResult) {
result = r.filterMetrics(result)
newSeriesSlices := result.series
namers := result.namers