func doWork() ([]source_api.Source, sinks.ExternalSinkManager, manager.Manager, error) { c := cache.NewCache(*argCacheDuration, time.Minute) sources, err := newSources(c) if err != nil { return nil, nil, nil, err } sinkManager, err := sinks.NewExternalSinkManager(nil, c, *argSinkFrequency) if err != nil { return nil, nil, nil, err } // Spawn the Model Housekeeping goroutine even if the model is not enabled. // This will allow the model to be activated/deactivated in runtime. // Set the housekeeping period to 2 * argModelResolution + 25 sec // TODO(afein): select a more well-defined housekeeping interval modelDuration := 2 * *argModelResolution modelDuration = time.Time{}.Add(modelDuration).Add(25 * time.Second).Sub(time.Time{}) if (*argCacheDuration).Nanoseconds() < modelDuration.Nanoseconds() { modelDuration = *argCacheDuration } manager, err := manager.NewManager(sources, sinkManager, *argStatsResolution, *argCacheDuration, c, *argUseModel, *argModelResolution, modelDuration) if err != nil { return nil, nil, nil, err } if err := manager.SetSinkUris(argSinks); err != nil { return nil, nil, nil, err } manager.Start() return sources, sinkManager, manager, nil }
func doWork() ([]source_api.Source, sinks.ExternalSinkManager, manager.Manager, error) { c := cache.NewCache(*argCacheDuration, time.Minute) sources, err := newSources(c) if err != nil { return nil, nil, nil, err } sinkManager, err := sinks.NewExternalSinkManager(nil) if err != nil { return nil, nil, nil, err } manager, err := manager.NewManager(sources, sinkManager, *argStatsResolution, *argCacheDuration, c, *argUseModel, *argModelResolution, *argAlignStats) if err != nil { return nil, nil, nil, err } if err := manager.SetSinkUris(argSinks); err != nil { return nil, nil, nil, err } // Spawn the Model Housekeeping goroutine even if the model is not enabled. // This will allow the model to be activated/deactivated in runtime. modelDuration := 2 * *argModelResolution if (*argCacheDuration).Nanoseconds() < modelDuration.Nanoseconds() { modelDuration = *argCacheDuration } go util.Until(manager.HousekeepModel, modelDuration, util.NeverStop) go util.Until(manager.Housekeep, *argPollDuration, util.NeverStop) return sources, sinkManager, manager, nil }
func doWork() ([]source_api.Source, sinks.ExternalSinkManager, manager.Manager, error) { c := cache.NewCache(*argCacheDuration, time.Minute) sources, err := newSources(c) if err != nil { // Do not fail heapster is source setup fails for any reason. glog.Errorf("failed to setup sinks - %v", err) } sinkManager, err := sinks.NewExternalSinkManager(nil, c, *argSinkFrequency) if err != nil { return nil, nil, nil, err } // Spawn the Model Housekeeping goroutine even if the model is not enabled. // This will allow the model to be activated/deactivated in runtime. modelDuration := *argModelFrequency if (*argCacheDuration).Nanoseconds() < modelDuration.Nanoseconds() { modelDuration = *argCacheDuration } manager, err := manager.NewManager(sources, sinkManager, *argStatsResolution, *argCacheDuration, c, *argUseModel, *argModelResolution, modelDuration) if err != nil { return nil, nil, nil, err } if err := manager.SetSinkUris(argSinks); err != nil { // Do not fail heapster is sink setup fails for any reason. glog.Errorf("failed to setup sinks - %v", err) } manager.Start() return sources, sinkManager, manager, nil }
func TestModelMetricPassing(t *testing.T) { if testing.Short() { t.Skip("skipping heapster model integration test.") } assert := assert.New(t) resolution := 2 * time.Second sources := []source_api.Source{newTestSource()} cache := cache.NewCache(time.Hour, time.Hour) assert.NotNil(cache) sinkManager, err := sinks.NewExternalSinkManager([]sink_api.ExternalSink{}, cache, resolution) assert.NoError(err) manager, err := manager.NewManager(sources, sinkManager, resolution, time.Hour, cache, true, resolution, resolution) assert.NoError(err) start := time.Now() manager.Start() defer manager.Stop() time.Sleep(10 * time.Second) model := manager.GetModel() pods := model.GetPods(testNamespace) assert.Equal(podCount, len(pods)) metrics, _, err := model.GetPodMetric(model_api.PodMetricRequest{ NamespaceName: testNamespace, PodName: "pod-0", MetricRequest: model_api.MetricRequest{ Start: start, End: time.Time{}, MetricName: "cpu-usage", }, }) assert.NoError(err) //TODO: Expect more than 1 metric once #551 is fixed assert.NotEmpty(metrics) assert.InEpsilon(loadAverageMilli, metrics[0].Value, 50) }