Skip to content

Commit

Permalink
Add a separate flag for 'start' parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Nail Islamov committed Nov 20, 2018
1 parent 3bd75f5 commit 5ba0ad0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion cmd/adapter/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type PrometheusAdapter struct {
AdapterConfigFile string
// MetricsRelistInterval is the interval at which to relist the set of available metrics
MetricsRelistInterval time.Duration
// MetricsStartDuration is the period to query available metrics for
MetricsStartDuration time.Duration

metricsConfig *adaptercfg.MetricsDiscoveryConfig
}
Expand Down Expand Up @@ -83,6 +85,8 @@ func (cmd *PrometheusAdapter) addFlags() {
"and custom metrics API resources")
cmd.Flags().DurationVar(&cmd.MetricsRelistInterval, "metrics-relist-interval", cmd.MetricsRelistInterval, ""+
"interval at which to re-list the set of all available metrics from Prometheus")
cmd.Flags().DurationVar(&cmd.MetricsStartDuration, "metrics-start-duration", cmd.MetricsStartDuration, ""+
"period for which to query the set of available metrics from Prometheus ('start' parameter)")
}

func (cmd *PrometheusAdapter) loadConfig() error {
Expand Down Expand Up @@ -122,7 +126,7 @@ func (cmd *PrometheusAdapter) makeProvider(promClient prom.Client, stopCh <-chan
}

// construct the provider and start it
cmProvider, runner := cmprov.NewPrometheusProvider(mapper, dynClient, promClient, namers, cmd.MetricsRelistInterval)
cmProvider, runner := cmprov.NewPrometheusProvider(mapper, dynClient, promClient, namers, cmd.MetricsRelistInterval, cmd.MetricsStartDuration)
runner.RunUntil(stopCh)

return cmProvider, nil
Expand Down Expand Up @@ -173,6 +177,7 @@ func main() {
cmd := &PrometheusAdapter{
PrometheusURL: "https://localhost",
MetricsRelistInterval: 10 * time.Minute,
MetricsStartDuration: 10 * time.Minute,
}
cmd.Name = "prometheus-metrics-adapter"
cmd.addFlags()
Expand Down
6 changes: 4 additions & 2 deletions pkg/custom-provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ type prometheusProvider struct {
SeriesRegistry
}

func NewPrometheusProvider(mapper apimeta.RESTMapper, kubeClient dynamic.Interface, promClient prom.Client, namers []MetricNamer, updateInterval time.Duration) (provider.CustomMetricsProvider, Runnable) {
func NewPrometheusProvider(mapper apimeta.RESTMapper, kubeClient dynamic.Interface, promClient prom.Client, namers []MetricNamer, updateInterval time.Duration, startDuration time.Duration) (provider.CustomMetricsProvider, Runnable) {
lister := &cachingMetricsLister{
updateInterval: updateInterval,
startDuration: startDuration,
promClient: promClient,
namers: namers,

Expand Down Expand Up @@ -191,6 +192,7 @@ type cachingMetricsLister struct {

promClient prom.Client
updateInterval time.Duration
startDuration time.Duration
namers []MetricNamer
}

Expand All @@ -212,7 +214,7 @@ type selectorSeries struct {
}

func (l *cachingMetricsLister) updateMetrics() error {
startTime := pmodel.Now().Add(-1 * l.updateInterval)
startTime := pmodel.Now().Add(-1 * l.startDuration)

// don't do duplicate queries when it's just the matchers that change
seriesCacheByQuery := make(map[prom.Selector][]prom.Series)
Expand Down

0 comments on commit 5ba0ad0

Please sign in to comment.