Jaeger采样率初始化

2019-12-04  本文已影响0人  huiwq1990

一、采样率配置属性

可以通过环境变量对采样率配置
JAEGER_SAMPLER_TYPE 配置采集器的类型
JAEGER_SAMPLER_PARAM 采样率(对于概率采集器来说)
JAEGER_SAMPLER_MANAGER_HOST_PORT 管理端地址
JAEGER_SAMPLER_MAX_OPERATIONS operation的最大数量
JAEGER_SAMPLER_REFRESH_INTERVAL 刷新时间间隔
常量定义在文件:jaeger-client-go\config\config_env.go

二、代码分析

2.1 配置初始化

FromEnv(jaeger-client-go/config/config_env.go)从环境变量初始化jaeger的配置。

    if c.Sampler == nil {
        c.Sampler = &SamplerConfig{}
    }

    if s, err := c.Sampler.samplerConfigFromEnv(); err == nil {
        c.Sampler = s
    } else {
        return nil, errors.Wrap(err, "cannot obtain sampler config from env")
    }

1)如果simplerconfig配置为空,新建一个空的
2)调用samplerConfigFromEnv,获取JAEGER_SAMPLER_TYPE、JAEGER_SAMPLER_PARAM 的值。

2.2 采集器初始化

采集器可以通过配置生成,也可以通过代码初始化。如果用代码cfg.NewTracer(jaegercfg.Sampler(jaeger.NewConstSampler(true)),)初始化,环境变量配置不会生效。

    opts := applyOptions(options...)

    if c.Sampler == nil {
        c.Sampler = &SamplerConfig{
            Type:  jaeger.SamplerTypeRemote,
            Param: defaultSamplingProbability,
        }
    }
        // 没有显示指定采集器,利用配置新建
    sampler := opts.sampler
    if sampler == nil {
        s, err := c.Sampler.NewSampler(c.ServiceName, tracerMetrics)
        if err != nil {
            return nil, nil, err
        }
        sampler = s
    }

2.3 创建采集器

  if samplerType == jaeger.SamplerTypeRemote || sc.Type == "" {
      sc2 := *sc
      sc2.Type = jaeger.SamplerTypeProbabilistic
      glog.Info("trace create simpler remote")
             // 调用自身创建概率采集器
      initSampler, err := sc2.NewSampler(serviceName, nil)
      if err != nil {
          return nil, err
      }
      options := []jaeger.SamplerOption{
          jaeger.SamplerOptions.Metrics(metrics),
          jaeger.SamplerOptions.InitialSampler(initSampler),
          jaeger.SamplerOptions.SamplingServerURL(sc.SamplingServerURL),
          jaeger.SamplerOptions.MaxOperations(sc.MaxOperations),
          jaeger.SamplerOptions.OperationNameLateBinding(sc.OperationNameLateBinding),
          jaeger.SamplerOptions.SamplingRefreshInterval(sc.SamplingRefreshInterval),
      }
      options = append(options, sc.Options...)
      return jaeger.NewRemotelyControlledSampler(serviceName, options...), nil
  }

重看remotesimpler的创建,如果没有指定类型,默认创建该类型的。remotesimpler是一个复合的采集器,它会内置一个概率采集器。因此,用户配置(如JAEGER_SAMPLER_PARAM )是配置的概率采集器。

三、Collector动态配置采样率

jaeger目前还不支持动态配置采样率。

1、监听文件变更实现

  1. SIGNUP or a POST method similar to the solution in prometheus.
  2. fsnotify https://github.com/fsnotify/fsnotify
  3. tableflip https://github.com/cloudflare/tableflip
  4. Viper's native re-reading config support (with help of fsnotify).

https://github.com/jaegertracing/jaeger/issues/1058

2、动态配置存储

https://github.com/jaegertracing/jaeger/issues/355

上一篇 下一篇

猜你喜欢

热点阅读