func NewLabelingInput(delegate pipeline.Input, labels map[string]string) pipeline.Input {
	return &labelingInput{Component: delegate, delegate: delegate, labels: labels}
}
NewLabelingInput creates an Input that adds the given additional labels to incoming
MetricReports before passing reports to the given delegate. If a report already contains a label
with the same name, the original label is retained and a warning is logged.
package inputs
import (
	"fmt"
	"github.com/GoogleCloudPlatform/ubbagent/metrics"
	"github.com/GoogleCloudPlatform/ubbagent/pipeline"
	"github.com/golang/glog"
	"github.com/hashicorp/go-multierror"
)
type selector struct {
	inputs  map[string]pipeline.Input
	tracker pipeline.UsageTracker
}
func (s *selector) AddReport(report metrics.MetricReport) error {
	a, ok := s.inputs[report.Name]
	if !ok {
		return fmt.Errorf("selector: unknown metric: %v", report.Name)
	}
	return a.AddReport(report)
}
func (s *selector) Use() {
	s.tracker.Use()
}
func (s *selector) Release() error {
	return s.tracker.Release(func() error {
		components := make([]pipeline.Component, len(s.inputs))
		i := 0
		for _, v := range s.inputs {
			components[i] = v
			i++
		}
		return pipeline.ReleaseAll(components)
	})
}
func NewSelector(inputs map[string]pipeline.Input) pipeline.Input {
	for _, a := range inputs {
		a.Use()
	}
	return &selector{inputs: inputs}
}
type callbackInput struct {
	delegate pipeline.Input
	shutdown func() error
	tracker  pipeline.UsageTracker
}
func (p *callbackInput) AddReport(report metrics.MetricReport) error {
	return p.delegate.AddReport(report)
}
func (p *callbackInput) Use() {
	p.tracker.Use()
}
func (p *callbackInput) Release() error {
	return p.tracker.Release(func() error {
		callbackErr := p.shutdown()
		releaseError := p.delegate.Release()
		return multierror.Append(callbackErr, releaseError).ErrorOrNil()
	})
}
func NewCallbackInput(delegate pipeline.Input, shutdown func() error) pipeline.Input {
	delegate.Use()
	return &callbackInput{delegate: delegate, shutdown: shutdown}
}
type labelingInput struct {
	pipeline.Component
	delegate pipeline.Input
	labels   map[string]string
}
func (i *labelingInput) AddReport(report metrics.MetricReport) error {
	for k, v := range i.labels {
		if _, exists := report.Labels[k]; exists {
			glog.Warningf("labelingInput: received report that already had label '%v'; skipping", k)
			continue
		}
		if report.Labels == nil {
			report.Labels = make(map[string]string)
		}
		report.Labels[k] = v
	}
	return i.delegate.AddReport(report)
}