mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-07 22:25:03 +00:00
Added sample model class to retrieve timestamp in custom metrics provider.go class
This commit is contained in:
parent
80df37b920
commit
f4f1cadbda
1 changed files with 5 additions and 15 deletions
|
|
@ -80,7 +80,7 @@ func NewPrometheusProvider(mapper apimeta.RESTMapper, kubeClient dynamic.Interfa
|
||||||
}, lister
|
}, lister
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *prometheusProvider) metricFor(value pmodel.SampleValue, name types.NamespacedName, info provider.CustomMetricInfo, metricSelector labels.Selector) (*custom_metrics.MetricValue, error) {
|
func (p *prometheusProvider) metricFor(sample *model.Sample, value pmodel.SampleValue, name types.NamespacedName, info provider.CustomMetricInfo, metricSelector labels.Selector) (*custom_metrics.MetricValue, error) {
|
||||||
ref, err := helpers.ReferenceFor(p.mapper, name, info)
|
ref, err := helpers.ReferenceFor(p.mapper, name, info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -99,18 +99,8 @@ func (p *prometheusProvider) metricFor(value pmodel.SampleValue, name types.Name
|
||||||
Name: info.Metric,
|
Name: info.Metric,
|
||||||
},
|
},
|
||||||
|
|
||||||
// TODO(directxman12): use the right timestamp
|
|
||||||
|
|
||||||
|
|
||||||
/*Making the changes in the timestamp as per issue
|
|
||||||
number #545*/
|
|
||||||
|
|
||||||
// Previously set timestamp
|
|
||||||
//Timestamp: metav1.Time{Time: time.Now()},
|
|
||||||
|
|
||||||
// Newly set timestamp
|
|
||||||
Timestamp: metav1.Time{
|
Timestamp: metav1.Time{
|
||||||
Time: value.Timestamp.Time(),
|
Time: sample.Timestamp.Time(),
|
||||||
},
|
},
|
||||||
Value: *q,
|
Value: *q,
|
||||||
}
|
}
|
||||||
|
|
@ -126,7 +116,7 @@ func (p *prometheusProvider) metricFor(value pmodel.SampleValue, name types.Name
|
||||||
return metric, nil
|
return metric, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *prometheusProvider) metricsFor(valueSet pmodel.Vector, namespace string, names []string, info provider.CustomMetricInfo, metricSelector labels.Selector) (*custom_metrics.MetricValueList, error) {
|
func (p *prometheusProvider) metricsFor(sample *model.Sample, valueSet pmodel.Vector, namespace string, names []string, info provider.CustomMetricInfo, metricSelector labels.Selector) (*custom_metrics.MetricValueList, error) {
|
||||||
values, found := p.MatchValuesToNames(info, valueSet)
|
values, found := p.MatchValuesToNames(info, valueSet)
|
||||||
if !found {
|
if !found {
|
||||||
return nil, provider.NewMetricNotFoundError(info.GroupResource, info.Metric)
|
return nil, provider.NewMetricNotFoundError(info.GroupResource, info.Metric)
|
||||||
|
|
@ -138,7 +128,7 @@ func (p *prometheusProvider) metricsFor(valueSet pmodel.Vector, namespace string
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
value, err := p.metricFor(values[name], types.NamespacedName{Namespace: namespace, Name: name}, info, metricSelector)
|
value, err := p.metricFor(sample, values[name], types.NamespacedName{Namespace: namespace, Name: name}, info, metricSelector)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
@ -219,7 +209,7 @@ func (p *prometheusProvider) GetMetricBySelector(ctx context.Context, namespace
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the resulting metrics
|
// return the resulting metrics
|
||||||
return p.metricsFor(queryResults, namespace, resourceNames, info, metricSelector)
|
return p.metricsFor(sample, queryResults, namespace, resourceNames, info, metricSelector)
|
||||||
}
|
}
|
||||||
|
|
||||||
type cachingMetricsLister struct {
|
type cachingMetricsLister struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue