// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 package mysqlreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mysqlreceiver" import ( "context" "time" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/receiver/scraperhelper" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mysqlreceiver/internal/metadata" ) func NewFactory() receiver.Factory { return receiver.NewFactory( metadata.Type, createDefaultConfig, receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability)) } func createDefaultConfig() component.Config { cfg := scraperhelper.NewDefaultScraperControllerSettings(metadata.Type) cfg.CollectionInterval = 10 * time.Second return &Config{ ScraperControllerSettings: cfg, AllowNativePasswords: true, Username: "root", NetAddr: confignet.NetAddr{ Endpoint: "localhost:3306", Transport: "tcp", }, MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), StatementEvents: StatementEventsConfig{ DigestTextLimit: defaultStatementEventsDigestTextLimit, Limit: defaultStatementEventsLimit, TimeLimit: defaultStatementEventsTimeLimit, }, } } func createMetricsReceiver( _ context.Context, params receiver.CreateSettings, rConf component.Config, consumer consumer.Metrics, ) (receiver.Metrics, error) { cfg := rConf.(*Config) ns := newMySQLScraper(params, cfg) scraper, err := scraperhelper.NewScraper(metadata.Type, ns.scrape, scraperhelper.WithStart(ns.start), scraperhelper.WithShutdown(ns.shutdown)) if err != nil { return nil, err } return scraperhelper.NewScraperControllerReceiver( &cfg.ScraperControllerSettings, params, consumer, scraperhelper.AddScraper(scraper), ) }