This cleans up the CLI code significantly. Also makes some of this re-usable for providers who want to do so. This also removes the main.go from the top of the tree of the repro, instead moving it into cmd/virtual-kubelet. This allows us to better utilize the package namespace (and e.g. mv the `vkubelet` package to the top of the tree).
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package opencensus
|
|
|
|
import (
|
|
"github.com/cpuguy83/strongerrors"
|
|
"github.com/pkg/errors"
|
|
"go.opencensus.io/trace"
|
|
)
|
|
|
|
type TracingExporterOptions struct {
|
|
Tags map[string]string
|
|
ServiceName string
|
|
}
|
|
|
|
var (
|
|
tracingExporters = make(map[string]TracingExporterInitFunc)
|
|
)
|
|
|
|
// TracingExporterInitFunc is the function that is called to initialize an exporter.
|
|
// This is used when registering an exporter and called when a user specifed they want to use the exporter.
|
|
type TracingExporterInitFunc func(TracingExporterOptions) (trace.Exporter, error)
|
|
|
|
// RegisterTracingExporter registers a tracing exporter.
|
|
// For a user to select an exporter, it must be registered here.
|
|
func RegisterTracingExporter(name string, f TracingExporterInitFunc) {
|
|
tracingExporters[name] = f
|
|
}
|
|
|
|
// GetTracingExporter gets the specified tracing exporter passing in the options to the exporter init function.
|
|
// For an exporter to be availbale here it must be registered with `RegisterTracingExporter`.
|
|
func GetTracingExporter(name string, opts TracingExporterOptions) (trace.Exporter, error) {
|
|
f, ok := tracingExporters[name]
|
|
if !ok {
|
|
return nil, strongerrors.NotFound(errors.Errorf("tracing exporter %q not found", name))
|
|
}
|
|
return f(opts)
|
|
}
|
|
|
|
// AvailableTraceExporters gets the list of registered exporters
|
|
func AvailableTraceExporters() []string {
|
|
out := make([]string, 0, len(tracingExporters))
|
|
for k := range tracingExporters {
|
|
out = append(out, k)
|
|
}
|
|
return out
|
|
}
|