Skip to content

Commit

Permalink
Start a unified scraper (#1432)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgeckhart authored Jul 2, 2024
1 parent 43c09fe commit 42a6833
Show file tree
Hide file tree
Showing 9 changed files with 946 additions and 0 deletions.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
github.com/grafana/regexp v0.0.0-20221123153739-15dc172cd2db
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/common v0.54.0
github.com/r3labs/diff/v3 v3.0.1
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.2
golang.org/x/sync v0.7.0
Expand All @@ -50,6 +51,8 @@ require (
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
golang.org/x/sys v0.19.0 // indirect
google.golang.org/protobuf v1.34.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,22 @@ github.com/prometheus/common v0.54.0 h1:ZlZy0BgJhTwVZUn7dLOkwCZHUkrAqd3WYtcFCWnM
github.com/prometheus/common v0.54.0/go.mod h1:/TQgMJP5CuVYveyT7n/0Ix8yLNNXy9yRSkhnLTHPDIQ=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/r3labs/diff/v3 v3.0.1 h1:CBKqf3XmNRHXKmdU7mZP1w7TV0pDyVCis1AUHtA4Xtg=
github.com/r3labs/diff/v3 v3.0.1/go.mod h1:f1S9bourRbiM66NskseyUdo0fTmEE0qKrikYJX63dgo=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/urfave/cli/v2 v2.27.2 h1:6e0H+AkS+zDckwPCUrZkKX38mRaau4nL2uipkJpbkcI=
github.com/urfave/cli/v2 v2.27.2/go.mod h1:g0+79LmHHATl7DAcHO99smiR/T7uGLw84w8Y42x+4eM=
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913/go.mod h1:4aEEwZQutDLsQv2Deui4iYQ6DWTxR14g6m8Wv88+Xqk=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
Expand All @@ -107,5 +114,6 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
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/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) CustomTags() []model.Tag {
return c.Job.CustomTags
}

func (c CustomNamespaceJob) resourceEnrichment() ResourceEnrichment {
// TODO add implementation in followup
return nil
}
33 changes: 33 additions & 0 deletions pkg/job/cloudwatchrunner/discovery.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/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 {
// TODO add implementation in followup
return nil
}
19 changes: 19 additions & 0 deletions pkg/job/cloudwatchrunner/runner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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/logging"
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/model"
)

type ResourceEnrichment interface {
Create(logger logging.Logger) resourcemetadata.MetricResourceEnricher
}

type Job interface {
Namespace() string
CustomTags() []model.Tag
listMetricsParams() listmetrics.ProcessingParams
resourceEnrichment() ResourceEnrichment
}
10 changes: 10 additions & 0 deletions pkg/job/listmetrics/processor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package listmetrics

import "github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/model"

type ProcessingParams struct {
Namespace string
Metrics []*model.MetricConfig
RecentlyActiveOnly bool
DimensionNameRequirements []string
}
26 changes: 26 additions & 0 deletions pkg/job/resourcemetadata/resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package resourcemetadata

import (
"context"

"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/model"
)

type Resource struct {
// Name is an identifiable value for the resource and is variable dependent on the match made
// It will be the AWS ARN (Amazon Resource Name) if a unique resource was found
// It will be "global" if a unique resource was not found
// CustomNamespaces will have the custom namespace Name
Name string
// Tags is a set of tags associated to the resource
Tags []model.Tag
}

type Resources struct {
StaticResource *Resource
AssociatedResources []*Resource
}

type MetricResourceEnricher interface {
Enrich(ctx context.Context, metrics []*model.Metric) ([]*model.Metric, Resources)
}
Loading

0 comments on commit 42a6833

Please sign in to comment.