collector/receiver/prometheusreceiver/factory.go (40 lines of code) (raw):
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package prometheusreceiver // import "github.com/GoogleCloudPlatform/run-gmp-sidecar/collector/receiver/prometheusreceiver"
import (
"context"
"errors"
promconfig "github.com/prometheus/prometheus/config"
_ "github.com/prometheus/prometheus/discovery/install" // init() of this package registers service discovery impl.
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/featuregate"
"go.opentelemetry.io/collector/receiver"
"github.com/GoogleCloudPlatform/run-gmp-sidecar/collector/receiver/prometheusreceiver/internal/metadata"
)
var useCreatedMetricGate = featuregate.GlobalRegistry().MustRegister(
"receiver.prometheusreceiver.UseCreatedMetric",
featuregate.StageAlpha,
featuregate.WithRegisterDescription("When enabled, the Prometheus receiver will"+
" retrieve the start time for Summary, Histogram and Sum metrics from _created metric"),
)
var errRenamingDisallowed = errors.New("metric renaming using metric_relabel_configs is disallowed")
// NewFactory creates a new Prometheus receiver factory.
func NewFactory() receiver.Factory {
return receiver.NewFactory(
metadata.Type,
createDefaultConfig,
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
}
func createDefaultConfig() component.Config {
return &Config{
PrometheusConfig: &promconfig.Config{
GlobalConfig: promconfig.DefaultGlobalConfig,
},
}
}
func createMetricsReceiver(
_ context.Context,
set receiver.Settings,
cfg component.Config,
nextConsumer consumer.Metrics,
) (receiver.Metrics, error) {
return newPrometheusReceiver(set, cfg.(*Config), nextConsumer), nil
}