Skip to content

Commit

Permalink
wire up mongodb exporter for integrations v2 converter
Browse files Browse the repository at this point in the history
Signed-off-by: erikbaranowski <[email protected]>
  • Loading branch information
erikbaranowski committed Nov 3, 2023
1 parent 5234f70 commit 2b7206e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
4 changes: 3 additions & 1 deletion converter/internal/staticconvert/internal/build/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (b *IntegrationsConfigBuilder) appendV1Integrations() {
case *memcached_exporter.Config:
exports = b.appendMemcachedExporter(itg, nil)
case *mongodb_exporter.Config:
exports = b.appendMongodbExporter(itg)
exports = b.appendMongodbExporter(itg, nil)
case *mssql_exporter.Config:
exports = b.appendMssqlExporter(itg)
case *mysqld_exporter.Config:
Expand Down Expand Up @@ -232,6 +232,8 @@ func (b *IntegrationsConfigBuilder) appendV2Integrations() {
exports = b.appendKafkaExporter(v1_itg, itg.Common.InstanceKey)
case *memcached_exporter.Config:
exports = b.appendMemcachedExporter(v1_itg, itg.Common.InstanceKey)
case *mongodb_exporter.Config:
exports = b.appendMongodbExporter(v1_itg, itg.Common.InstanceKey)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
package build

import (
"fmt"

"github.com/grafana/agent/component/discovery"
"github.com/grafana/agent/component/prometheus/exporter/mongodb"
"github.com/grafana/agent/converter/internal/common"
"github.com/grafana/agent/pkg/integrations/mongodb_exporter"
"github.com/grafana/river/rivertypes"
)

func (b *IntegrationsConfigBuilder) appendMongodbExporter(config *mongodb_exporter.Config) discovery.Exports {
func (b *IntegrationsConfigBuilder) appendMongodbExporter(config *mongodb_exporter.Config, instanceKey *string) discovery.Exports {
args := toMongodbExporter(config)
compLabel := common.LabelForParts(b.globalCtx.LabelPrefix, config.Name())
b.f.Body().AppendBlock(common.NewBlockWithOverride(
[]string{"prometheus", "exporter", "mongodb"},
compLabel,
args,
))

return common.NewDiscoveryExports(fmt.Sprintf("prometheus.exporter.mongodb.%s.targets", compLabel))
return b.appendExporterBlock(args, config.Name(), instanceKey, "mongodb")
}

func toMongodbExporter(config *mongodb_exporter.Config) *mongodb.Arguments {
Expand Down
27 changes: 27 additions & 0 deletions converter/internal/staticconvert/testdata-v2/integrations_v2.river
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,33 @@ prometheus.scrape "integrations_memcached" {
job_name = "integrations/memcached"
}

prometheus.exporter.mongodb "integrations_mongodb_exporter" {
mongodb_uri = "mongodb://mongodb-a:27017"
direct_connect = true
}

discovery.relabel "integrations_mongodb" {
targets = prometheus.exporter.mongodb.integrations_mongodb_exporter.targets

rule {
source_labels = ["__address__"]
target_label = "service_name"
replacement = "replicaset1-node1"
}

rule {
source_labels = ["__address__"]
target_label = "mongodb_cluster"
replacement = "prod-cluster"
}
}

prometheus.scrape "integrations_mongodb" {
targets = discovery.relabel.integrations_mongodb.output
forward_to = [prometheus.remote_write.metrics_default.receiver]
job_name = "integrations/mongodb"
}

prometheus.exporter.agent "integrations_agent" { }

discovery.relabel "integrations_agent" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,14 @@ integrations:
relabel_configs:
- source_labels: [__address__]
target_label: instance
replacement: memcached-a
replacement: memcached-a
mongodb_configs:
- mongodb_uri: mongodb://mongodb-a:27017
autoscrape:
relabel_configs:
- source_labels: [__address__]
target_label: service_name
replacement: 'replicaset1-node1'
- source_labels: [__address__]
target_label: mongodb_cluster
replacement: 'prod-cluster'
1 change: 1 addition & 0 deletions converter/internal/staticconvert/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func validateIntegrationsV2(integrationsConfig *v2.SubsystemOptions) diag.Diagno
case *github_exporter.Config:
case *kafka_exporter.Config:
case *memcached_exporter.Config:
case *mongodb_exporter.Config:
default:
diags.Add(diag.SeverityLevelError, fmt.Sprintf("The converter does not support converting the provided %s integration.", v1_itg.Name()))
}
Expand Down

0 comments on commit 2b7206e

Please sign in to comment.