问题描述

完整的错误是这样的:

Defaulted container "loki" out of: loki, chmod-data (init)
Unable to parse config: /etc/loki/loki.yaml: yaml: unmarshal errors:
  line 1: field auth_enabled not found in type main.Config
  line 2: field ingester not found in type main.Config
  line 12: field limits_config not found in type main.Config
  line 16: field schema_config not found in type main.Config
  line 27: field storage_config not found in type main.Config
  line 35: field chunk_store_config not found in type main.Config
  line 37: field table_manager not found in type main.Config
  line 40: field compactor not found in type main.Config

最后查出的原因是:镜像用错了。把loki的镜像用成了promtail的镜像。

有的大聪明可能要说了“镜像用错了就换镜像就行了,还不简单”,“以后仔细点就行了,还不简单”,“这么简单的问题还写博客”。

最难的不是解决问题,而是定位问题,尤其是这种不太容易被怀疑的地方出了问题。

定位过程

首先从网上搜索,发现没有人回答这个问题。你经历过的问题99%都有人经历过了,loki有大把的文档,这种问题却没有人问,一般来说就是自己犯了低级错误。

然后,就去看源码

把Unable to parse config 放到代码里去搜索

只有两个文件里有这个报错信息,因此只能是go文件里的报错。

而这个go文件却属于promtail,这时我就开始怀疑是镜像用错了。

再观察报错,它说

  line 1: field auth_enabled not found in type main.Config
  line 2: field ingester not found in type main.Config
  line 12: field limits_config not found in type main.Config

也就是说,Config结构体里没有发现auth_enabled、 ingester这些属性

观察 main中Config结构体,没有这些属性,完全可以肯定镜像那个用错了

最后去检查镜像,果然在tag的时候把镜像名字tag错了。

希望能对大家有所启发。

更多推荐