mirror of
https://github.com/kubernetes-sigs/prometheus-adapter.git
synced 2026-04-06 01:38:10 +00:00
* Wiped out a ton of warnings about comments. * Created consts for `MetricType` values. * `externalInfoMap` can now track multiple series with the same name/namespace and different labels. * `namespace` parameter of external metrics queries is now respected (albeit very rudimentarily) * Metric converter values for external metrics are now converted the same way as for custom metrics (probably still some opportunity for consolidation). * Lots of TODOs actually done. * Deleted a lot of commented out code.
37 lines
1 KiB
Go
37 lines
1 KiB
Go
package provider
|
|
|
|
import (
|
|
"errors"
|
|
|
|
prom "github.com/directxman12/k8s-prometheus-adapter/pkg/client"
|
|
"github.com/prometheus/common/model"
|
|
"k8s.io/metrics/pkg/apis/external_metrics"
|
|
)
|
|
|
|
type matrixConverter struct {
|
|
}
|
|
|
|
//NewMatrixConverter creates a MatrixConverter capable of converting
|
|
//matrix Prometheus query results into external metric types.
|
|
func NewMatrixConverter() MetricConverter {
|
|
return &matrixConverter{}
|
|
}
|
|
|
|
func (c *matrixConverter) Convert(queryResult prom.QueryResult) (*external_metrics.ExternalMetricValueList, error) {
|
|
if queryResult.Type != model.ValMatrix {
|
|
return nil, errors.New("matrixConverter can only convert scalar query results")
|
|
}
|
|
|
|
toConvert := queryResult.Matrix
|
|
|
|
if toConvert == nil {
|
|
return nil, errors.New("the provided input did not contain matrix query results")
|
|
}
|
|
|
|
return c.convert(toConvert)
|
|
}
|
|
|
|
func (c *matrixConverter) convert(result *model.Matrix) (*external_metrics.ExternalMetricValueList, error) {
|
|
//TODO: AC - Implementation.
|
|
return nil, errors.New("converting Matrix results is not yet supported")
|
|
}
|