【Monitoring】Grafana Tempo介绍以及在Kubernates中安装

2,225 阅读3分钟

1. Tempo介绍

官方文档:grafana.com/docs/tempo/…

Grafana Tempo是一个分布式的后端tracing系统。可以作为数据源,在Grafana中进行展示。

下图列出了一个分布式tracing系统的必要的几个步骤:Instrumentation, Pipeline, Backend和Visualization。

Tempo在其中扮演的角色是提供trace相关的存储功能。

image.png

具体来说:

1.1 Instrumentation

在程序中加上trace相关的信息(如traceId, spanId等等)。
一般来说我们会自动通过SDK来做自动生成traceId,流行的SDK有:

1.2. Pipeline (Grafana Agent)

当我们的项目已经加上了tracking相关的信息后,下一步是试图将这些trace相关的信息发送到一个后端保存起来,并可以图形化查看。

Tracing pipeline主要做的是将application的trace相关的信息存到后台。这一步也不是必须需要的,因为很多情况下我们也可以直接将app中的数据发送到Tompo中。

在Kubernetes中,Grafana Agent可以做到相对透明的将app中的trace信息发送到一个backend中存储起来。了解更多关于Grafana Agent,可以查看:文章

当然还有其长的Tracing pipeline,如:

  • OpenTelemetry Collector,可以阅读这篇文章,详细的介绍了opentelemetry-collector与tempo的结合使用。简单来说,就是安装好opentelemetry-collector后,在配置的exporter的endpoint中配上tempo的地址(即上图中2->3的过程)。app对接opentelemetry-collector,app对接opentelemetry的agent,那么则自动配置为localhost:4317,也可通过-D进行reset。
  • Jaeger Agent

1.3 Backend (Tempo)

  • 官网示例:examples
  • Deployment相关: deployment
  • 关于Tempo的安装,在下一章

1.4 Visualization (Grafana)

在Grafana中配置Tempo数据源,然后通过Exploer进行查看。下文有演示。

2. 通过helm在Kubernetes中安装Tempo

参考:grafana.com/docs/tempo/… Github:github.com/grafana/tem…

首先是helm repo添加:

helm repo add grafana https://grafana.github.io/helm-charts
helm repo update

查找chart:
我们安装Grafana Tempo Single Binary Mode版本即可:

helm search repo grafana

image.png

开始安装,装在namespace=monitoring下:

helm upgrade --install tempo grafana/tempo -n monitoring

image.png

可以看到Tempo相关的pod以及service都已经安装了:

kubectl get all -n monitoring | grep tempo

image.png

3. 在Grafana中配置tempo数据源

关于Grafana的安装与使用,看文章:【k8s学习】Grafana Loki在Kubernetes中的安装(超详细)

登陆Grafana后,左侧Navigate - Configuration - Data sources - 【Add data source】: 在URL中输入http://tempo:3100 image.png

点击Save & Test: image.png

这时候在Grafana的Exporer中就会多了一个数据源,但因为我们目前没有trace的log,所以需要手动安装一个进行测试。

4. 安装一个项目进行手动测试tempo的trace

我们在#1中贴的图,整个trace id有4个步骤,因为本文主要讲Tempo,所以关于trace id的收集,以及存入Tempo,这些步骤,我在网上找了个现成的项目来mock traceId的生成以及存入Tempo。

首先将 github.com/grafana/tem… 的内容下载到本地,注,把文件中的namespace删除(文件中默认了default为namespace,而我们需要放在monitoring,否则通过tempo:14248会找不到tempo)。

删除了namespace后,然后安装:

kubectl create -f single-binary-extras.yaml -n monitoring

可以看到在namespace=monitoring下安装了: image.png 查看pod的log:

kubectl logs -f synthetic-load-generator-788bb979d6-jgtjz -n monitoring

打印的log sample:

22/07/25 16:51:49 INFO ScheduledTraceGenerator: Emitted traceId 688a5cdd6f83fa65 for service frontend route /product

22/07/25 16:51:49 INFO ScheduledTraceGenerator: Emitted traceId 76b21233e3825b35 for service frontend route /cart

在Grafana中查询traceId:

拿到traceId,去Grafana的Exploer中查询:

    1. 确保数据源选的是Tempo。
    1. 在TraceId中输入上述日志中的Id。
    1. 可以选过去多久的数据。
    1. 开始Run日志。

image.png