// Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 package httpcheckreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/httpcheckreceiver" import ( "context" "errors" "time" "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/receiver/scraperhelper" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/httpcheckreceiver/internal/metadata" ) var errConfigNotHTTPCheck = errors.New("config was not a HTTP check 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 = 60 * time.Second return &Config{ ScraperControllerSettings: cfg, MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), Targets: []*targetConfig{}, } } func createMetricsReceiver(_ context.Context, params receiver.CreateSettings, rConf component.Config, consumer consumer.Metrics) (receiver.Metrics, error) { cfg, ok := rConf.(*Config) if !ok { return nil, errConfigNotHTTPCheck } httpcheckScraper := newScraper(cfg, params) scraper, err := scraperhelper.NewScraper(metadata.Type, httpcheckScraper.scrape, scraperhelper.WithStart(httpcheckScraper.start)) if err != nil { return nil, err } return scraperhelper.NewScraperControllerReceiver(&cfg.ScraperControllerSettings, params, consumer, scraperhelper.AddScraper(scraper)) }