mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-06 01:38:10 +00:00
Merge pull request #444 from dgrisonnet/context
Propagate metric providers context
This commit is contained in:
commit
0f60f49639
2 changed files with 5 additions and 5 deletions
|
|
@ -138,14 +138,14 @@ func (p *prometheusProvider) metricsFor(valueSet pmodel.Vector, namespace string
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *prometheusProvider) buildQuery(info provider.CustomMetricInfo, namespace string, metricSelector labels.Selector, names ...string) (pmodel.Vector, error) {
|
func (p *prometheusProvider) buildQuery(ctx context.Context, info provider.CustomMetricInfo, namespace string, metricSelector labels.Selector, names ...string) (pmodel.Vector, error) {
|
||||||
query, found := p.QueryForMetric(info, namespace, metricSelector, names...)
|
query, found := p.QueryForMetric(info, namespace, metricSelector, names...)
|
||||||
if !found {
|
if !found {
|
||||||
return nil, provider.NewMetricNotFoundError(info.GroupResource, info.Metric)
|
return nil, provider.NewMetricNotFoundError(info.GroupResource, info.Metric)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: use an actual context
|
// TODO: use an actual context
|
||||||
queryResults, err := p.promClient.Query(context.TODO(), pmodel.Now(), query)
|
queryResults, err := p.promClient.Query(ctx, pmodel.Now(), query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("unable to fetch metrics from prometheus: %v", err)
|
klog.Errorf("unable to fetch metrics from prometheus: %v", err)
|
||||||
// don't leak implementation details to the user
|
// don't leak implementation details to the user
|
||||||
|
|
@ -162,7 +162,7 @@ func (p *prometheusProvider) buildQuery(info provider.CustomMetricInfo, namespac
|
||||||
|
|
||||||
func (p *prometheusProvider) GetMetricByName(ctx context.Context, name types.NamespacedName, info provider.CustomMetricInfo, metricSelector labels.Selector) (*custom_metrics.MetricValue, error) {
|
func (p *prometheusProvider) GetMetricByName(ctx context.Context, name types.NamespacedName, info provider.CustomMetricInfo, metricSelector labels.Selector) (*custom_metrics.MetricValue, error) {
|
||||||
// construct a query
|
// construct a query
|
||||||
queryResults, err := p.buildQuery(info, name.Namespace, metricSelector, name.Name)
|
queryResults, err := p.buildQuery(ctx, info, name.Namespace, metricSelector, name.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -201,7 +201,7 @@ func (p *prometheusProvider) GetMetricBySelector(ctx context.Context, namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
// construct the actual query
|
// construct the actual query
|
||||||
queryResults, err := p.buildQuery(info, namespace, metricSelector, resourceNames...)
|
queryResults, err := p.buildQuery(ctx, info, namespace, metricSelector, resourceNames...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ func (p *externalPrometheusProvider) GetExternalMetric(ctx context.Context, name
|
||||||
return nil, provider.NewMetricNotFoundError(p.selectGroupResource(namespace), info.Metric)
|
return nil, provider.NewMetricNotFoundError(p.selectGroupResource(namespace), info.Metric)
|
||||||
}
|
}
|
||||||
// Here is where we're making the query, need to be before here xD
|
// Here is where we're making the query, need to be before here xD
|
||||||
queryResults, err := p.promClient.Query(context.TODO(), pmodel.Now(), selector)
|
queryResults, err := p.promClient.Query(ctx, pmodel.Now(), selector)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
klog.Errorf("unable to fetch metrics from prometheus: %v", err)
|
klog.Errorf("unable to fetch metrics from prometheus: %v", err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue