Skip to content

Commit

Permalink
replace custom LogCacheClient with a simple LogCacheFetcher that no l…
Browse files Browse the repository at this point in the history
…onger takes care of also building the actual logcache.Client
  • Loading branch information
geigerj0 committed Jun 14, 2024
1 parent 16f04ba commit 3331a67
Show file tree
Hide file tree
Showing 16 changed files with 745 additions and 1,062 deletions.
2 changes: 1 addition & 1 deletion packages/eventgenerator/spec
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ files:
- autoscaler/db/sqldb/* # gosub
- autoscaler/envelopeprocessor/* # gosub
- autoscaler/eventgenerator/aggregator/* # gosub
- autoscaler/eventgenerator/client/* # gosub
- autoscaler/eventgenerator/cmd/eventgenerator/* # gosub
- autoscaler/eventgenerator/config/* # gosub
- autoscaler/eventgenerator/generator/* # gosub
- autoscaler/eventgenerator/metric/* # gosub
- autoscaler/eventgenerator/server/* # gosub
- autoscaler/healthendpoint/* # gosub
- autoscaler/helpers/* # gosub
Expand Down
10 changes: 5 additions & 5 deletions src/autoscaler/eventgenerator/aggregator/metric_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"
"time"

"code.cloudfoundry.org/app-autoscaler/src/autoscaler/eventgenerator/client"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/eventgenerator/metric"

"code.cloudfoundry.org/app-autoscaler/src/autoscaler/models"
"code.cloudfoundry.org/lager/v3"
Expand All @@ -15,16 +15,16 @@ import (
type MetricPoller struct {
logger lager.Logger
doneChan chan bool
metricClient client.MetricClient
metricClient metric.Fetcher
appMonitorsChan chan *models.AppMonitor
appMetricChan chan *models.AppMetric
}

func NewMetricPoller(logger lager.Logger, metricClient client.MetricClient, appMonitorsChan chan *models.AppMonitor, appMetricChan chan *models.AppMetric) *MetricPoller {
func NewMetricPoller(logger lager.Logger, metricFetcher metric.Fetcher, appMonitorsChan chan *models.AppMonitor, appMetricChan chan *models.AppMetric) *MetricPoller {
return &MetricPoller{
logger: logger.Session("MetricPoller"),
appMonitorsChan: appMonitorsChan,
metricClient: metricClient,
metricClient: metricFetcher,
doneChan: make(chan bool),
appMetricChan: appMetricChan,
}
Expand Down Expand Up @@ -62,7 +62,7 @@ func (m *MetricPoller) retrieveMetric(appMonitor *models.AppMonitor) error {
endTime := time.Now()
startTime := endTime.Add(0 - statWindow)

metrics, err := m.metricClient.GetMetrics(appId, metricType, startTime, endTime)
metrics, err := m.metricClient.FetchMetrics(appId, metricType, startTime, endTime)
if err != nil {
return fmt.Errorf("retrieveMetric Failed: %w", err)
}
Expand Down
16 changes: 9 additions & 7 deletions src/autoscaler/eventgenerator/aggregator/metric_poller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"time"

. "code.cloudfoundry.org/app-autoscaler/src/autoscaler/eventgenerator/aggregator"
. "code.cloudfoundry.org/app-autoscaler/src/autoscaler/eventgenerator/client"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/eventgenerator/config"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/eventgenerator/metric"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/models"
"code.cloudfoundry.org/app-autoscaler/src/autoscaler/testhelpers"
rpc "code.cloudfoundry.org/go-log-cache/v2/rpc/logcache_v1"
Expand All @@ -29,7 +29,7 @@ var _ = Describe("MetricPoller", func() {
appMonitorsChan chan *models.AppMonitor
appMetricChan chan *models.AppMetric
metricPoller *MetricPoller
metricClient MetricClient
metricFetcher metric.Fetcher
mockLogCache *testhelpers.MockLogCache
appMonitor *models.AppMonitor
)
Expand All @@ -51,13 +51,14 @@ var _ = Describe("MetricPoller", func() {
Context("When metric-collector is not running", func() {

BeforeEach(func() {
metricClient = NewMetricClientFactory().GetMetricClient(logger, &config.Config{
metricFetcher, err := metric.NewLogCacheFetcherFactory(metric.StandardLogCacheFetcherCreator).CreateFetcher(logger, config.Config{
MetricCollector: config.MetricCollectorConfig{
MetricCollectorURL: "this.endpoint.does.not.exist:1234",
},
})
Expect(err).ToNot(HaveOccurred())

metricPoller = NewMetricPoller(logger, metricClient, appMonitorsChan, appMetricChan)
metricPoller = NewMetricPoller(logger, metricFetcher, appMonitorsChan, appMetricChan)
metricPoller.Start()

Expect(appMonitorsChan).Should(BeSent(appMonitor))
Expand Down Expand Up @@ -188,7 +189,7 @@ var _ = Describe("MetricPoller", func() {
err = mockLogCache.Start(3000 + GinkgoParallelProcess())
Expect(err).ToNot(HaveOccurred())

metricClient = NewMetricClientFactory().GetMetricClient(logger, &config.Config{
metricFetcher, err = metric.NewLogCacheFetcherFactory(metric.StandardLogCacheFetcherCreator).CreateFetcher(logger, config.Config{
MetricCollector: config.MetricCollectorConfig{
MetricCollectorURL: mockLogCache.URL(),
TLSClientCerts: models.TLSCerts{
Expand All @@ -198,10 +199,11 @@ var _ = Describe("MetricPoller", func() {
},
},
})
Expect(err).ToNot(HaveOccurred())
})

JustBeforeEach(func() {
metricPoller = NewMetricPoller(logger, metricClient, appMonitorsChan, appMetricChan)
metricPoller = NewMetricPoller(logger, metricFetcher, appMonitorsChan, appMetricChan)
metricPoller.Start()

Expect(appMonitorsChan).Should(BeSent(appMonitor))
Expand Down Expand Up @@ -265,7 +267,7 @@ var _ = Describe("MetricPoller", func() {

Context("Stop", func() {
BeforeEach(func() {
metricPoller = NewMetricPoller(logger, metricClient, appMonitorsChan, appMetricChan)
metricPoller = NewMetricPoller(logger, metricFetcher, appMonitorsChan, appMetricChan)
metricPoller.Start()
metricPoller.Stop()
Eventually(logger.Buffer).Should(Say("stopped"))
Expand Down
Loading

0 comments on commit 3331a67

Please sign in to comment.