in pkg/trimaran/loadvariationriskbalancing/collector.go [57:99]
func newCollector(obj runtime.Object) (*Collector, error) {
// get the plugin arguments
args := getArgs(obj)
klog.V(4).Infof("Using LoadVariationRiskBalancingArgs: MetricProvider.Type=%q, MetricProvider.Address=%q,"+
" SafeVarianceMargin=%f, SafeVarianceSensitivity=%f, WatcherAddress=%q",
args.MetricProvider.Type, args.MetricProvider.Address, args.SafeVarianceMargin,
args.SafeVarianceSensitivity, args.WatcherAddress)
var client loadwatcherapi.Client
if args.WatcherAddress != "" {
client, _ = loadwatcherapi.NewServiceClient(args.WatcherAddress)
} else {
opts := watcher.MetricsProviderOpts{
Name: string(args.MetricProvider.Type),
Address: args.MetricProvider.Address,
AuthToken: args.MetricProvider.Token,
}
client, _ = loadwatcherapi.NewLibraryClient(opts)
}
collector := &Collector{
client: client,
args: args,
}
// populate metrics before returning
err := collector.updateMetrics()
if err != nil {
klog.Warningf("unable to populate metrics initially: %v", err)
}
// start periodic updates
go func() {
metricsUpdaterTicker := time.NewTicker(time.Second * metricsUpdateIntervalSeconds)
for range metricsUpdaterTicker.C {
err = collector.updateMetrics()
if err != nil {
klog.Warningf("unable to update metrics: %v", err)
}
}
}()
return collector, nil
}