github.com/yankunsam/loki/v2@v2.6.3-0.20220817130409-389df5235c27/clients/pkg/promtail/targets/gcplog/target.go (about) 1 package gcplog 2 3 import ( 4 "fmt" 5 6 "github.com/go-kit/log" 7 "github.com/prometheus/prometheus/model/relabel" 8 9 "github.com/grafana/loki/clients/pkg/promtail/api" 10 "github.com/grafana/loki/clients/pkg/promtail/scrapeconfig" 11 "github.com/grafana/loki/clients/pkg/promtail/targets/target" 12 ) 13 14 // Target is a common interface implemented by both GCPLog targets. 15 type Target interface { 16 target.Target 17 Stop() error 18 } 19 20 // NewGCPLogTarget creates a GCPLog target either with the push or pull implementation, depending on the configured 21 // subscription type. 22 func NewGCPLogTarget( 23 metrics *Metrics, 24 logger log.Logger, 25 handler api.EntryHandler, 26 relabel []*relabel.Config, 27 jobName string, 28 config *scrapeconfig.GcplogTargetConfig, 29 ) (Target, error) { 30 switch config.SubscriptionType { 31 case "pull", "": 32 return newPullTarget(metrics, logger, handler, relabel, jobName, config) 33 case "push": 34 return newPushTarget(metrics, logger, handler, jobName, config, relabel) 35 default: 36 return nil, fmt.Errorf("invalid subscription type: %s. valid options are 'push' and 'pull'", config.SubscriptionType) 37 } 38 }