123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- // Copyright The OpenTelemetry Authors
- // SPDX-License-Identifier: Apache-2.0
- package rabbitmqreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/rabbitmqreceiver"
- import (
- "context"
- "errors"
- "time"
- "go.opentelemetry.io/collector/component"
- "go.opentelemetry.io/collector/config/confighttp"
- "go.opentelemetry.io/collector/consumer"
- "go.opentelemetry.io/collector/receiver"
- "go.opentelemetry.io/collector/receiver/scraperhelper"
- "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/rabbitmqreceiver/internal/metadata"
- )
- var errConfigNotRabbit = errors.New("config was not a RabbitMQ receiver config")
- // NewFactory creates a new receiver factory
- 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,
- HTTPClientSettings: confighttp.HTTPClientSettings{
- Endpoint: defaultEndpoint,
- Timeout: 10 * time.Second,
- },
- MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(),
- }
- }
- func createMetricsReceiver(_ context.Context, params receiver.CreateSettings, rConf component.Config, consumer consumer.Metrics) (receiver.Metrics, error) {
- cfg, ok := rConf.(*Config)
- if !ok {
- return nil, errConfigNotRabbit
- }
- rabbitScraper := newScraper(params.Logger, cfg, params)
- scraper, err := scraperhelper.NewScraper(metadata.Type, rabbitScraper.scrape, scraperhelper.WithStart(rabbitScraper.start))
- if err != nil {
- return nil, err
- }
- return scraperhelper.NewScraperControllerReceiver(&cfg.ScraperControllerSettings, params, consumer, scraperhelper.AddScraper(scraper))
- }
|