mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-06 01:38:10 +00:00
Undoing the rename of prometheusProvider to make it easier to focus on the new functionality.
This commit is contained in:
parent
5533ff7580
commit
c30cc6c396
4 changed files with 16 additions and 16 deletions
|
|
@ -189,7 +189,7 @@ func (o PrometheusAdapterServerOptions) RunCustomMetricsAdapterServer(stopCh <-c
|
|||
return fmt.Errorf("unable to construct naming scheme from metrics rules: %v", err)
|
||||
}
|
||||
|
||||
cmProvider, runner := cmprov.NewCustomPrometheusProvider(dynamicMapper, dynamicClient, promClient, namers, o.MetricsRelistInterval)
|
||||
cmProvider, runner := cmprov.NewPrometheusProvider(dynamicMapper, dynamicClient, promClient, namers, o.MetricsRelistInterval)
|
||||
runner.RunUntil(stopCh)
|
||||
|
||||
server, err := config.Complete().New("prometheus-custom-metrics-adapter", cmProvider, nil)
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ type Runnable interface {
|
|||
RunUntil(stopChan <-chan struct{})
|
||||
}
|
||||
|
||||
type customPrometheusProvider struct {
|
||||
type prometheusProvider struct {
|
||||
mapper apimeta.RESTMapper
|
||||
kubeClient dynamic.Interface
|
||||
promClient prom.Client
|
||||
|
|
@ -56,7 +56,7 @@ type customPrometheusProvider struct {
|
|||
SeriesRegistry
|
||||
}
|
||||
|
||||
func NewCustomPrometheusProvider(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) (provider.CustomMetricsProvider, Runnable) {
|
||||
lister := &cachingMetricsLister{
|
||||
updateInterval: updateInterval,
|
||||
promClient: promClient,
|
||||
|
|
@ -67,7 +67,7 @@ func NewCustomPrometheusProvider(mapper apimeta.RESTMapper, kubeClient dynamic.I
|
|||
},
|
||||
}
|
||||
|
||||
return &customPrometheusProvider{
|
||||
return &prometheusProvider{
|
||||
mapper: mapper,
|
||||
kubeClient: kubeClient,
|
||||
promClient: promClient,
|
||||
|
|
@ -76,7 +76,7 @@ func NewCustomPrometheusProvider(mapper apimeta.RESTMapper, kubeClient dynamic.I
|
|||
}, lister
|
||||
}
|
||||
|
||||
func (p *customPrometheusProvider) metricFor(value pmodel.SampleValue, groupResource schema.GroupResource, namespace string, name string, metricName string) (*custom_metrics.MetricValue, error) {
|
||||
func (p *prometheusProvider) metricFor(value pmodel.SampleValue, groupResource schema.GroupResource, namespace string, name string, metricName string) (*custom_metrics.MetricValue, error) {
|
||||
kind, err := p.mapper.KindFor(groupResource.WithVersion(""))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -95,7 +95,7 @@ func (p *customPrometheusProvider) metricFor(value pmodel.SampleValue, groupReso
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (p *customPrometheusProvider) metricsFor(valueSet pmodel.Vector, info provider.CustomMetricInfo, list runtime.Object) (*custom_metrics.MetricValueList, error) {
|
||||
func (p *prometheusProvider) metricsFor(valueSet pmodel.Vector, info provider.CustomMetricInfo, list runtime.Object) (*custom_metrics.MetricValueList, error) {
|
||||
if !apimeta.IsListType(list) {
|
||||
return nil, apierr.NewInternalError(fmt.Errorf("result of label selector list operation was not a list"))
|
||||
}
|
||||
|
|
@ -129,7 +129,7 @@ func (p *customPrometheusProvider) metricsFor(valueSet pmodel.Vector, info provi
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (p *customPrometheusProvider) buildQuery(info provider.CustomMetricInfo, namespace string, names ...string) (pmodel.Vector, error) {
|
||||
func (p *prometheusProvider) buildQuery(info provider.CustomMetricInfo, namespace string, names ...string) (pmodel.Vector, error) {
|
||||
query, found := p.QueryForMetric(info, namespace, names...)
|
||||
if !found {
|
||||
return nil, provider.NewMetricNotFoundError(info.GroupResource, info.Metric)
|
||||
|
|
@ -151,7 +151,7 @@ func (p *customPrometheusProvider) buildQuery(info provider.CustomMetricInfo, na
|
|||
return *queryResults.Vector, nil
|
||||
}
|
||||
|
||||
func (p *customPrometheusProvider) getSingle(info provider.CustomMetricInfo, namespace, name string) (*custom_metrics.MetricValue, error) {
|
||||
func (p *prometheusProvider) getSingle(info provider.CustomMetricInfo, namespace, name string) (*custom_metrics.MetricValue, error) {
|
||||
queryResults, err := p.buildQuery(info, namespace, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -179,7 +179,7 @@ func (p *customPrometheusProvider) getSingle(info provider.CustomMetricInfo, nam
|
|||
return p.metricFor(resultValue, info.GroupResource, "", name, info.Metric)
|
||||
}
|
||||
|
||||
func (p *customPrometheusProvider) getMultiple(info provider.CustomMetricInfo, namespace string, selector labels.Selector) (*custom_metrics.MetricValueList, error) {
|
||||
func (p *prometheusProvider) getMultiple(info provider.CustomMetricInfo, namespace string, selector labels.Selector) (*custom_metrics.MetricValueList, error) {
|
||||
fullResources, err := p.mapper.ResourcesFor(info.GroupResource.WithVersion(""))
|
||||
if err == nil && len(fullResources) == 0 {
|
||||
err = fmt.Errorf("no fully versioned resources known for group-resource %v", info.GroupResource)
|
||||
|
|
@ -225,7 +225,7 @@ func (p *customPrometheusProvider) getMultiple(info provider.CustomMetricInfo, n
|
|||
return p.metricsFor(queryResults, info, matchingObjectsRaw)
|
||||
}
|
||||
|
||||
func (p *customPrometheusProvider) GetRootScopedMetricByName(groupResource schema.GroupResource, name string, metricName string) (*custom_metrics.MetricValue, error) {
|
||||
func (p *prometheusProvider) GetRootScopedMetricByName(groupResource schema.GroupResource, name string, metricName string) (*custom_metrics.MetricValue, error) {
|
||||
info := provider.CustomMetricInfo{
|
||||
GroupResource: groupResource,
|
||||
Metric: metricName,
|
||||
|
|
@ -235,7 +235,7 @@ func (p *customPrometheusProvider) GetRootScopedMetricByName(groupResource schem
|
|||
return p.getSingle(info, "", name)
|
||||
}
|
||||
|
||||
func (p *customPrometheusProvider) GetRootScopedMetricBySelector(groupResource schema.GroupResource, selector labels.Selector, metricName string) (*custom_metrics.MetricValueList, error) {
|
||||
func (p *prometheusProvider) GetRootScopedMetricBySelector(groupResource schema.GroupResource, selector labels.Selector, metricName string) (*custom_metrics.MetricValueList, error) {
|
||||
info := provider.CustomMetricInfo{
|
||||
GroupResource: groupResource,
|
||||
Metric: metricName,
|
||||
|
|
@ -244,7 +244,7 @@ func (p *customPrometheusProvider) GetRootScopedMetricBySelector(groupResource s
|
|||
return p.getMultiple(info, "", selector)
|
||||
}
|
||||
|
||||
func (p *customPrometheusProvider) GetNamespacedMetricByName(groupResource schema.GroupResource, namespace string, name string, metricName string) (*custom_metrics.MetricValue, error) {
|
||||
func (p *prometheusProvider) GetNamespacedMetricByName(groupResource schema.GroupResource, namespace string, name string, metricName string) (*custom_metrics.MetricValue, error) {
|
||||
info := provider.CustomMetricInfo{
|
||||
GroupResource: groupResource,
|
||||
Metric: metricName,
|
||||
|
|
@ -254,7 +254,7 @@ func (p *customPrometheusProvider) GetNamespacedMetricByName(groupResource schem
|
|||
return p.getSingle(info, namespace, name)
|
||||
}
|
||||
|
||||
func (p *customPrometheusProvider) GetNamespacedMetricBySelector(groupResource schema.GroupResource, namespace string, selector labels.Selector, metricName string) (*custom_metrics.MetricValueList, error) {
|
||||
func (p *prometheusProvider) GetNamespacedMetricBySelector(groupResource schema.GroupResource, namespace string, selector labels.Selector, metricName string) (*custom_metrics.MetricValueList, error) {
|
||||
info := provider.CustomMetricInfo{
|
||||
GroupResource: groupResource,
|
||||
Metric: metricName,
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ func setupPrometheusProvider(t *testing.T) (provider.CustomMetricsProvider, *fak
|
|||
namers, err := NamersFromConfig(cfg, restMapper())
|
||||
require.NoError(t, err)
|
||||
|
||||
prov, _ := NewCustomPrometheusProvider(restMapper(), fakeKubeClient, fakeProm, namers, fakeProviderUpdateInterval)
|
||||
prov, _ := NewPrometheusProvider(restMapper(), fakeKubeClient, fakeProm, namers, fakeProviderUpdateInterval)
|
||||
|
||||
containerSel := prom.MatchSeries("", prom.NameMatches("^container_.*"), prom.LabelNeq("container_name", "POD"), prom.LabelNeq("namespace", ""), prom.LabelNeq("pod_name", ""))
|
||||
namespacedSel := prom.MatchSeries("", prom.LabelNeq("namespace", ""), prom.NameNotMatches("^container_.*"))
|
||||
|
|
@ -141,7 +141,7 @@ func TestListAllMetrics(t *testing.T) {
|
|||
fakeProm.acceptibleInterval = pmodel.Interval{Start: startTime, End: 0}
|
||||
|
||||
// update the metrics (without actually calling RunUntil, so we can avoid timing issues)
|
||||
lister := prov.(*customPrometheusProvider).SeriesRegistry.(*cachingMetricsLister)
|
||||
lister := prov.(*prometheusProvider).SeriesRegistry.(*cachingMetricsLister)
|
||||
require.NoError(t, lister.updateMetrics())
|
||||
|
||||
// list/sort the metrics
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ type externalPrometheusProvider struct {
|
|||
}
|
||||
|
||||
//TODO: It probably makes more sense to, once this is functional and complete, roll the
|
||||
//customPrometheusProvider and externalPrometheusProvider up into a single type
|
||||
//prometheusProvider 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue