mirror of
https://github.com/zalando-incubator/kube-metrics-adapter.git
synced 2024-12-22 11:06:04 +00:00
5a543781d7
Signed-off-by: Mikkel Oscar Lyderik Larsen <mikkel.larsen@zalando.de>
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package collector
|
|
|
|
import (
|
|
"time"
|
|
|
|
"golang.org/x/net/context"
|
|
autoscalingv2 "k8s.io/api/autoscaling/v2"
|
|
"k8s.io/apimachinery/pkg/api/resource"
|
|
"k8s.io/metrics/pkg/apis/custom_metrics"
|
|
)
|
|
|
|
type FakeCollectorPlugin struct {
|
|
metrics []CollectedMetric
|
|
config map[string]string
|
|
}
|
|
|
|
type FakeCollector struct {
|
|
metrics []CollectedMetric
|
|
interval time.Duration
|
|
stub func() ([]CollectedMetric, error)
|
|
}
|
|
|
|
func (c *FakeCollector) GetMetrics(_ context.Context) ([]CollectedMetric, error) {
|
|
if c.stub != nil {
|
|
v, err := c.stub()
|
|
return v, err
|
|
}
|
|
|
|
return c.metrics, nil
|
|
}
|
|
|
|
func (FakeCollector) Interval() time.Duration {
|
|
return time.Minute
|
|
}
|
|
|
|
func (p *FakeCollectorPlugin) NewCollector(
|
|
_ context.Context,
|
|
hpa *autoscalingv2.HorizontalPodAutoscaler,
|
|
config *MetricConfig,
|
|
interval time.Duration,
|
|
) (Collector, error) {
|
|
|
|
p.config = config.Config
|
|
return &FakeCollector{metrics: p.metrics, interval: interval}, nil
|
|
}
|
|
|
|
func makePlugin(metric int) *FakeCollectorPlugin {
|
|
return &FakeCollectorPlugin{
|
|
metrics: []CollectedMetric{
|
|
{
|
|
Custom: custom_metrics.MetricValue{Value: *resource.NewQuantity(int64(metric), resource.DecimalSI)},
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func makeCollectorWithStub(f func() ([]CollectedMetric, error)) *FakeCollector {
|
|
return &FakeCollector{stub: f}
|
|
}
|