// InitGlobalTracer creates a new Jaeger Tracer, and sets it as global OpenTracing Tracer.
// It returns a closer func that can be used to flush buffers before shutdown.
967274
func (c Configuration) InitGlobalTracer(
	serviceName string,
	options ...Option,
) (io.Closer, error) {
	if c.Disabled {
		return &nullCloser{}, nil
	}
	tracer, closer, err := c.New(serviceName, options...)
	if err != nil {
		return nil, err
	}
	opentracing.SetGlobalTracer(tracer)
	return closer, nil
}
355091
func InitLogger(cfg *LogConfig) error {
	log.SetLevel(stringToLogLevel(cfg.Level))
	log.AddHook(&contextHook{})

	if cfg.Format == "" {
		cfg.Format = DefaultLogFormat
	}
	formatter := stringToLogFormatter(cfg.Format, cfg.DisableTimestamp)
	log.SetFormatter(formatter)

	if len(cfg.File.Filename) != 0 {
		if err := initFileLog(&cfg.File, nil); err != nil {
			return errors.Trace(err)
		}
	}

	if len(cfg.SlowQueryFile) != 0 {
		SlowQueryLogger = log.New()
		tmp := cfg.File
		tmp.Filename = cfg.SlowQueryFile
		if err := initFileLog(&tmp, SlowQueryLogger); err != nil {
			return errors.Trace(err)
		}
		SlowQueryLogger.Formatter = &slowLogFormatter{}
	}

	return nil
}
1314989
func DeleteGlobal(key string) error {
	collections.globalMutex.Lock()
	obj := collections.globals[key]
	collections.globalMutex.Unlock()
	if obj == nil {
		log.Errorf("global %s not found", key)
		return errors.New("global not found")
	}

	// Check if we handle this object
	if objCallbackHandler.GlobalCb == nil {
		log.Errorf("No callback registered for global object")
		return errors.New("Invalid object type")
	}

	// Perform callback
	err := objCallbackHandler.GlobalCb.GlobalDelete(obj)
	if err != nil {
		log.Errorf("GlobalDelete retruned error for: %+v. Err: %v", obj, err)
		return err
	}

	// delete it from modeldb
	collections.globalMutex.Lock()
	err = obj.Delete()
	collections.globalMutex.Unlock()
	if err != nil {
		log.Errorf("Error deleting global %s. Err: %v", obj.Key, err)
	}

	// delete it from cache
	collections.globalMutex.Lock()
	delete(collections.globals, key)
	collections.globalMutex.Unlock()

	return nil
}
1097909
func HasGlobalCT() bool {
	eps := GetEndpoints()
	for _, e := range eps {
		if !e.Options.IsEnabled(option.ConntrackLocal) {
			return true
		}
	}
	return false
}
815377
func getGlobalInfo() (globalInfo map[string]interface{}) {
	globalInfo = map[string]interface{}{
		"isDistXL":         globalIsDistXL,
		"isXL":             globalIsXL,
		"isBrowserEnabled": globalIsBrowserEnabled,
		"isWorm":           globalWORMEnabled,
		"isEnvBrowser":     globalIsEnvBrowser,
		"isEnvCreds":       globalIsEnvCreds,
		"isEnvRegion":      globalIsEnvRegion,
		"isSSL":            globalIsSSL,
		"serverRegion":     globalServerRegion,
		// Add more relevant global settings here.
	}

	return globalInfo
}
544597
func WithNoopTracer(tracerNoop bool) TracerOption {
	return func(o *Tracer) error {
		if tracerNoop {
			o.noop = 1
		} else {
			o.noop = 0
		}
		return nil
	}
}
1011105
func (prober *flexVolumeProber) initWatcher() error {
	err := prober.watcher.Init(func(event fsnotify.Event) {
		if err := prober.handleWatchEvent(event); err != nil {
			klog.Errorf("Flexvolume prober watch: %s", err)
		}
	}, func(err error) {
		klog.Errorf("Received an error from watcher: %s", err)
	})
	if err != nil {
		return fmt.Errorf("Error initializing watcher: %s", err)
	}

	if err := prober.addWatchRecursive(prober.pluginDir); err != nil {
		return fmt.Errorf("Error adding watch on Flexvolume directory: %s", err)
	}

	prober.watcher.Run()

	return nil
}
1345822
func (s *GlobalCluster) SetGlobalClusterIdentifier(v string) *GlobalCluster {
	s.GlobalClusterIdentifier = &v
	return s
}
178599
func (s *DeleteGlobalClusterInput) SetGlobalClusterIdentifier(v string) *DeleteGlobalClusterInput {
	s.GlobalClusterIdentifier = &v
	return s
}
305676
func FindGlobal(key string) *Global {
	collections.globalMutex.Lock()
	defer collections.globalMutex.Unlock()

	obj := collections.globals[key]
	if obj == nil {
		return nil
	}

	return obj
}
881693
func InitGlobalSettings(stateDriver core.StateDriver, inst *core.InstanceInfo) error {

	/*
		Query global settings from state store
		1. if forward mode or private net is empty, retry after 1 seccond
		2. if forward mode doesn't match, return error
		3. if stored private net is wrong, return error
	*/

	gCfg := mastercfg.GlobConfig{}
	gCfg.StateDriver = stateDriver

	// wait until able to get fwd mode and private subnet
	for {
		if err := gCfg.Read(""); err != nil {
			logrus.Warnf("Error reading global settings from cluster store, error: %v", err.Error())
		} else {
			if gCfg.FwdMode == "" || gCfg.PvtSubnet == "" {
				if gCfg.FwdMode == "" {
					logrus.Warnf("No forwarding mode found from cluster store")
				}
				if gCfg.PvtSubnet == "" {
					logrus.Warnf("No private subnet found from cluster store")
				}

			} else {
				logrus.Infof("Got global forwarding mode: %v", gCfg.FwdMode)
				logrus.Infof("Got global private subnet: %v", gCfg.PvtSubnet)
				break
			}
		}
		logrus.Warnf("Sleep 1 second and retry pulling global settings")
		time.Sleep(1 * time.Second)
	}

	// make sure local config matches netmaster config
	if inst.FwdMode != "" && inst.FwdMode != gCfg.FwdMode {
		err := fmt.Errorf("netplugin's local forward mode %q doesn't match global settings %q", inst.FwdMode, gCfg.FwdMode)
		logrus.Errorf(err.Error())
		return err
	}
	inst.FwdMode = gCfg.FwdMode

	logrus.Infof("Using forwarding mode: %v", inst.FwdMode)
	net, err := netutils.CIDRToMask(gCfg.PvtSubnet)
	if err != nil {
		err := fmt.Errorf("error convert private subnet %v from CIDR to mask, error %v", gCfg.PvtSubnet, err.Error())
		logrus.Errorf(err.Error())
		return err
	}
	inst.HostPvtNW = net
	logrus.Infof("Using host private subnet: %v", gCfg.PvtSubnet)
	return nil
}
440406
func initGlobal() error {
	// disable stats update.
	session.SetStatsLease(0)
	var err error
	storeGlobal, domGlobal, err = newMockTikvWithBootstrap()
	if err == nil {
		return nil
	}

	if storeGlobal != nil {
		if err1 := storeGlobal.Close(); err1 != nil {
			logutil.Logger(context.Background()).Error("storeGlobal close error", zap.Error(err1))
		}
	}
	if domGlobal != nil {
		domGlobal.Close()
	}
	return err
}
83758
func (c Configuration) NewTracer(options ...Option) (opentracing.Tracer, io.Closer, error) {
	if c.ServiceName == "" {
		return nil, nil, errors.New("no service name provided")
	}

	if c.Disabled {
		return &opentracing.NoopTracer{}, &nullCloser{}, nil
	}
	opts := applyOptions(options...)
	tracerMetrics := jaeger.NewMetrics(opts.metrics, nil)
	if c.RPCMetrics {
		Observer(
			rpcmetrics.NewObserver(
				opts.metrics.Namespace(metrics.NSOptions{Name: "jaeger-rpc", Tags: map[string]string{"component": "jaeger"}}),
				rpcmetrics.DefaultNameNormalizer,
			),
		)(&opts) // adds to c.observers
	}
	if c.Sampler == nil {
		c.Sampler = &SamplerConfig{
			Type:  jaeger.SamplerTypeRemote,
			Param: defaultSamplingProbability,
		}
	}
	if c.Reporter == nil {
		c.Reporter = &ReporterConfig{}
	}

	sampler := opts.sampler
	if sampler == nil {
		s, err := c.Sampler.NewSampler(c.ServiceName, tracerMetrics)
		if err != nil {
			return nil, nil, err
		}
		sampler = s
	}

	reporter := opts.reporter
	if reporter == nil {
		r, err := c.Reporter.NewReporter(c.ServiceName, tracerMetrics, opts.logger)
		if err != nil {
			return nil, nil, err
		}
		reporter = r
	}

	tracerOptions := []jaeger.TracerOption{
		jaeger.TracerOptions.Metrics(tracerMetrics),
		jaeger.TracerOptions.Logger(opts.logger),
		jaeger.TracerOptions.CustomHeaderKeys(c.Headers),
		jaeger.TracerOptions.Gen128Bit(opts.gen128Bit),
		jaeger.TracerOptions.PoolSpans(opts.poolSpans),
		jaeger.TracerOptions.ZipkinSharedRPCSpan(opts.zipkinSharedRPCSpan),
		jaeger.TracerOptions.MaxTagValueLength(opts.maxTagValueLength),
	}

	for _, tag := range opts.tags {
		tracerOptions = append(tracerOptions, jaeger.TracerOptions.Tag(tag.Key, tag.Value))
	}

	for _, tag := range c.Tags {
		tracerOptions = append(tracerOptions, jaeger.TracerOptions.Tag(tag.Key, tag.Value))
	}

	for _, obs := range opts.observers {
		tracerOptions = append(tracerOptions, jaeger.TracerOptions.Observer(obs))
	}

	for _, cobs := range opts.contribObservers {
		tracerOptions = append(tracerOptions, jaeger.TracerOptions.ContribObserver(cobs))
	}

	for format, injector := range opts.injectors {
		tracerOptions = append(tracerOptions, jaeger.TracerOptions.Injector(format, injector))
	}

	for format, extractor := range opts.extractors {
		tracerOptions = append(tracerOptions, jaeger.TracerOptions.Extractor(format, extractor))
	}

	if c.BaggageRestrictions != nil {
		mgr := remote.NewRestrictionManager(
			c.ServiceName,
			remote.Options.Metrics(tracerMetrics),
			remote.Options.Logger(opts.logger),
			remote.Options.HostPort(c.BaggageRestrictions.HostPort),
			remote.Options.RefreshInterval(c.BaggageRestrictions.RefreshInterval),
			remote.Options.DenyBaggageOnInitializationFailure(
				c.BaggageRestrictions.DenyBaggageOnInitializationFailure,
			),
		)
		tracerOptions = append(tracerOptions, jaeger.TracerOptions.BaggageRestrictionManager(mgr))
	}

	if c.Throttler != nil {
		debugThrottler := throttler.NewThrottler(
			c.ServiceName,
			throttler.Options.Metrics(tracerMetrics),
			throttler.Options.Logger(opts.logger),
			throttler.Options.HostPort(c.Throttler.HostPort),
			throttler.Options.RefreshInterval(c.Throttler.RefreshInterval),
			throttler.Options.SynchronousInitialization(
				c.Throttler.SynchronousInitialization,
			),
		)

		tracerOptions = append(tracerOptions, jaeger.TracerOptions.DebugThrottler(debugThrottler))
	}

	tracer, closer := jaeger.NewTracer(
		c.ServiceName,
		sampler,
		reporter,
		tracerOptions...,
	)

	return tracer, closer, nil
}
931903
func GetOperGlobal(obj *GlobalInspect) error {
	// Check if we handle this object
	if objCallbackHandler.GlobalCb == nil {
		log.Errorf("No callback registered for global object")
		return errors.New("Invalid object type")
	}

	// Perform callback
	err := objCallbackHandler.GlobalCb.GlobalGetOper(obj)
	if err != nil {
		log.Errorf("GlobalDelete retruned error for: %+v. Err: %v", obj, err)
		return err
	}

	return nil
}
460070
func GetTracer(enabled bool, addr string, tags map[string]string) (opentracing.Tracer, io.Closer, error) {
	// Sample configuration for testing. Use constant sampling to sample every trace
	// and enable LogSpan to log every span via configured Logger.
	cfg := jaegercfg.Configuration{
		Disabled: !enabled,
		Sampler: &jaegercfg.SamplerConfig{
			Type:  jaeger.SamplerTypeConst,
			Param: 1,
		},
		Reporter: &jaegercfg.ReporterConfig{
			LogSpans:           false,
			LocalAgentHostPort: addr,
		},
	}

	jLogger := jaegerlog.StdLogger

	options := []jaegercfg.Option{
		jaegercfg.Logger(jLogger),
	}
	for k, v := range tags {
		options = append(options, jaegercfg.Tag(k, v))
	}

	tracer, closer, err := cfg.New(
		"metrictank",
		options...,
	)
	if err != nil {
		return nil, nil, err
	}
	opentracing.InitGlobalTracer(tracer)
	return tracer, closer, nil
}
905242
func SetGlobalRouting(filename string) error {
	var err error
	globalRouter, err = router.NewFromConfig(filename)
	return err
}
111181
func GlobalInit() {
	setting.NewContext()
	log.Trace("Custom path: %s", setting.CustomPath)
	log.Trace("Log path: %s", setting.LogRootPath)
	models.LoadConfigs()
	NewServices()

	if setting.InstallLock {
		highlight.NewContext()
		markup.NewSanitizer()
		if err := models.NewEngine(); err != nil {
			log.Fatal(2, "Fail to initialize ORM engine: %v", err)
		}
		models.HasEngine = true

		models.LoadAuthSources()
		models.LoadRepoConfig()
		models.NewRepoContext()

		// Booting long running goroutines.
		cron.NewContext()
		models.InitSyncMirrors()
		models.InitDeliverHooks()
		models.InitTestPullRequests()
	}
	if models.EnableSQLite3 {
		log.Info("SQLite3 Supported")
	}
	if setting.SupportMiniWinService {
		log.Info("Builtin Windows Service Supported")
	}
	checkRunMode()

	if !setting.InstallLock {
		return
	}

	if setting.SSH.StartBuiltinServer {
		ssh.Listen(setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers)
		log.Info("SSH server started on %s:%v", setting.SSH.ListenHost, setting.SSH.ListenPort)
		log.Trace("SSH server cipher list: %v", setting.SSH.ServerCiphers)
	}

	if setting.SSH.RewriteAuthorizedKeysAtStart {
		if err := models.RewriteAuthorizedKeys(); err != nil {
			log.Warn("Failed to rewrite authorized_keys file: %v", err)
		}
	}
}