-
Notifications
You must be signed in to change notification settings - Fork 488
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add static conversion for blackbox and cloudwatch (#4818)
Signed-off-by: erikbaranowski <[email protected]>
- Loading branch information
1 parent
7fab464
commit 989aae1
Showing
7 changed files
with
271 additions
and
11 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
converter/internal/staticconvert/internal/build/blackbox_exporter.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package build | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/grafana/agent/component/discovery" | ||
"github.com/grafana/agent/component/prometheus/exporter/blackbox" | ||
"github.com/grafana/agent/converter/internal/common" | ||
"github.com/grafana/agent/converter/internal/prometheusconvert" | ||
"github.com/grafana/agent/pkg/integrations/blackbox_exporter" | ||
"github.com/grafana/agent/pkg/river/rivertypes" | ||
) | ||
|
||
func (b *IntegrationsV1ConfigBuilder) appendBlackboxExporter(config *blackbox_exporter.Config) discovery.Exports { | ||
args := toBlackboxExporter(config) | ||
compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) | ||
b.f.Body().AppendBlock(common.NewBlockWithOverride( | ||
[]string{"prometheus", "exporter", "blackbox"}, | ||
compLabel, | ||
args, | ||
)) | ||
|
||
return prometheusconvert.NewDiscoverExports(fmt.Sprintf("prometheus.exporter.blackbox.%s.targets", compLabel)) | ||
} | ||
|
||
func toBlackboxExporter(config *blackbox_exporter.Config) *blackbox.Arguments { | ||
return &blackbox.Arguments{ | ||
ConfigFile: config.BlackboxConfigFile, | ||
Config: rivertypes.OptionalSecret{}, | ||
Targets: toBlackboxTargets(config.BlackboxTargets), | ||
ProbeTimeoutOffset: time.Duration(config.ProbeTimeoutOffset), | ||
ConfigStruct: config.BlackboxConfig, | ||
} | ||
} | ||
|
||
func toBlackboxTargets(blackboxTargets []blackbox_exporter.BlackboxTarget) blackbox.TargetBlock { | ||
var targetBlock blackbox.TargetBlock | ||
|
||
for _, bt := range blackboxTargets { | ||
targetBlock = append(targetBlock, toBlackboxTarget(bt)) | ||
} | ||
|
||
return targetBlock | ||
} | ||
|
||
func toBlackboxTarget(target blackbox_exporter.BlackboxTarget) blackbox.BlackboxTarget { | ||
return blackbox.BlackboxTarget{ | ||
Name: target.Name, | ||
Target: target.Target, | ||
Module: target.Module, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
converter/internal/staticconvert/internal/build/cloudwatch_exporter.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package build | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/grafana/agent/component/discovery" | ||
"github.com/grafana/agent/component/prometheus/exporter/cloudwatch" | ||
"github.com/grafana/agent/converter/internal/common" | ||
"github.com/grafana/agent/converter/internal/prometheusconvert" | ||
"github.com/grafana/agent/pkg/integrations/cloudwatch_exporter" | ||
) | ||
|
||
func (b *IntegrationsV1ConfigBuilder) appendCloudwatchExporter(config *cloudwatch_exporter.Config) discovery.Exports { | ||
args := toCloudwatchExporter(config) | ||
compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name()) | ||
b.f.Body().AppendBlock(common.NewBlockWithOverride( | ||
[]string{"prometheus", "exporter", "cloudwatch"}, | ||
compLabel, | ||
args, | ||
)) | ||
|
||
return prometheusconvert.NewDiscoverExports(fmt.Sprintf("prometheus.exporter.cloudwatch.%s.targets", compLabel)) | ||
} | ||
|
||
func toCloudwatchExporter(config *cloudwatch_exporter.Config) *cloudwatch.Arguments { | ||
return &cloudwatch.Arguments{ | ||
STSRegion: config.STSRegion, | ||
FIPSDisabled: config.FIPSDisabled, | ||
Debug: config.Debug, | ||
DiscoveryExportedTags: config.Discovery.ExportedTags, | ||
Discovery: toDiscoveryJobs(config.Discovery.Jobs), | ||
Static: []cloudwatch.StaticJob{}, | ||
} | ||
} | ||
|
||
func toDiscoveryJobs(jobs []*cloudwatch_exporter.DiscoveryJob) []cloudwatch.DiscoveryJob { | ||
var out []cloudwatch.DiscoveryJob | ||
for _, job := range jobs { | ||
out = append(out, toDiscoveryJob(job)) | ||
} | ||
return out | ||
} | ||
|
||
func toDiscoveryJob(job *cloudwatch_exporter.DiscoveryJob) cloudwatch.DiscoveryJob { | ||
return cloudwatch.DiscoveryJob{ | ||
Auth: cloudwatch.RegionAndRoles{ | ||
Regions: job.InlineRegionAndRoles.Regions, | ||
Roles: toRoles(job.InlineRegionAndRoles.Roles), | ||
}, | ||
CustomTags: toTags(job.CustomTags), | ||
SearchTags: toTags(job.SearchTags), | ||
Type: job.Type, | ||
DimensionNameRequirements: job.DimensionNameRequirements, | ||
Metrics: toMetrics(job.Metrics), | ||
} | ||
} | ||
|
||
func toRoles(roles []cloudwatch_exporter.Role) []cloudwatch.Role { | ||
var out []cloudwatch.Role | ||
for _, role := range roles { | ||
out = append(out, toRole(role)) | ||
} | ||
return out | ||
} | ||
|
||
func toRole(role cloudwatch_exporter.Role) cloudwatch.Role { | ||
return cloudwatch.Role{ | ||
RoleArn: role.RoleArn, | ||
ExternalID: role.ExternalID, | ||
} | ||
} | ||
|
||
func toTags(tags []cloudwatch_exporter.Tag) cloudwatch.Tags { | ||
out := make(cloudwatch.Tags, 0) | ||
for _, tag := range tags { | ||
out[tag.Key] = tag.Value | ||
} | ||
return out | ||
} | ||
|
||
func toMetrics(metrics []cloudwatch_exporter.Metric) []cloudwatch.Metric { | ||
var out []cloudwatch.Metric | ||
for _, metric := range metrics { | ||
out = append(out, toMetric(metric)) | ||
} | ||
return out | ||
} | ||
|
||
func toMetric(metric cloudwatch_exporter.Metric) cloudwatch.Metric { | ||
return cloudwatch.Metric{ | ||
Name: metric.Name, | ||
Statistics: metric.Statistics, | ||
Period: metric.Period, | ||
Length: metric.Length, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
(Warning) Please review your agent command line flags and ensure they are set in your Flow mode config file where necessary. | ||
(Warning) Please review your agent command line flags and ensure they are set in your Flow mode config file where necessary. | ||
(Error) unsupported integration azure_exporter was provided. | ||
(Error) unsupported integration cadvisor was provided. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters