Skip to content

Commit

Permalink
Cleaner job runner
Browse files Browse the repository at this point in the history
  • Loading branch information
kgeckhart committed May 15, 2024
1 parent 697fa2a commit e45f33d
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 163 deletions.
32 changes: 32 additions & 0 deletions pkg/job/cloudwatchrunner/customnamespace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cloudwatchrunner

import (
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/job/listmetrics"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/job/resourcemetadata"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/model"
)

type CustomNamespaceJob struct {
Job model.CustomNamespaceJob
}

func (c CustomNamespaceJob) Namespace() string {
return c.Job.Namespace
}

func (c CustomNamespaceJob) listMetricsParams() listmetrics.ProcessingParams {
return listmetrics.ProcessingParams{
Namespace: c.Job.Namespace,
Metrics: c.Job.Metrics,
RecentlyActiveOnly: c.Job.RecentlyActiveOnly,
DimensionNameRequirements: c.Job.DimensionNameRequirements,
}
}

func (c CustomNamespaceJob) resourceEnrichment() ResourceEnrichment {
return resourcemetadata.StaticResource{Name: c.Job.Name}
}

func (c CustomNamespaceJob) CustomTags() []model.Tag {
return c.Job.CustomTags
}
33 changes: 33 additions & 0 deletions pkg/job/cloudwatchrunner/discoveryjob.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cloudwatchrunner

import (
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/job/listmetrics"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/job/resourcemetadata"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/model"
)

type DiscoveryJob struct {
Job model.DiscoveryJob
Resources []*model.TaggedResource
}

func (d DiscoveryJob) Namespace() string {
return d.Job.Type
}

func (d DiscoveryJob) CustomTags() []model.Tag {
return d.Job.CustomTags
}

func (d DiscoveryJob) listMetricsParams() listmetrics.ProcessingParams {
return listmetrics.ProcessingParams{
Namespace: d.Job.Type,
Metrics: d.Job.Metrics,
RecentlyActiveOnly: d.Job.RecentlyActiveOnly,
DimensionNameRequirements: d.Job.DimensionNameRequirements,
}
}

func (d DiscoveryJob) resourceEnrichment() ResourceEnrichment {
return resourcemetadata.NewResourceAssociation(d.Job.DimensionsRegexps, d.Job.ExportedTagsOnMetrics, nil)
}
6 changes: 3 additions & 3 deletions pkg/job/runner.go → pkg/job/cloudwatchrunner/runner.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package job
package cloudwatchrunner

import (
"context"
Expand Down Expand Up @@ -41,11 +41,11 @@ type Params struct {
GetMetricDataMetricsPerQuery int
}

func NewRunner(logger logging.Logger, factory clients.Factory, params Params, config Job) *Runner {
func New(logger logging.Logger, factory clients.Factory, params Params, job Job) *Runner {
cloudwatchClient := factory.GetCloudwatchClient(params.Region, params.Role, params.CloudwatchConcurrency)
lmProcessor := listmetrics.NewDefaultProcessor(logger, cloudwatchClient)
gmdProcessor := getmetricdata.NewDefaultProcessor(logger, cloudwatchClient, params.GetMetricDataMetricsPerQuery, params.CloudwatchConcurrency.GetMetricData)
return internalNew(logger, lmProcessor, gmdProcessor, params, config)
return internalNew(logger, lmProcessor, gmdProcessor, params, job)
}

type Runner struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/job/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ type resourceAssociator interface {
AssociateMetricToResource(cwMetric *model.Metric) (*model.TaggedResource, bool)
}

type getMetricDataProcessor interface {
Run(ctx context.Context, namespace string, requests []*model.CloudwatchData) ([]*model.CloudwatchData, error)
}

func runDiscoveryJob(
ctx context.Context,
logger logging.Logger,
Expand Down
Loading

0 comments on commit e45f33d

Please sign in to comment.