【问题标题】:Error to setup custom SLO period window (7d) in the Sloth Prometheus在 Sloth Prometheus 中设置自定义 SLO 周期窗口 (7d) 时出错
【发布时间】:2023-01-28 03:43:33
【问题描述】:

我正在尝试按照文档 https://sloth.dev/usage/slo-period-windows/ 将 SLO 周期窗口设置为 7d

图片:ghcr.io/slok/sloth:v0.11.0

在启用和不启用 customSloconfig 的情况下使用 helm (values.yaml) 时:

sloth:
  defaultSloPeriod: 7d  # The slo period used by sloth (e.g. 30d).
customSloConfig:
  enabled: true
  path: /windows
  data: {}

它出现错误: 未找到 AlertWindows.sloth.slok.dev“”

直接与清单::

apiVersion: sloth.slok.dev/v1
kind: AlertWindows
spec:
  sloPeriod: 7d
  page:
    quick:
      errorBudgetPercent: 8
      shortWindow: 5m
      longWindow: 1h
    slow:
      errorBudgetPercent: 12.5
      shortWindow: 30m
      longWindow: 6h
  ticket:
    quick:
      errorBudgetPercent: 20
      shortWindow: 2h
      longWindow: 1d
    slow:
      errorBudgetPercent: 42
      shortWindow: 6h
      longWindow: 3d
kubectl apply -f window.yaml

它出现错误:

错误:找不到名称的资源映射:“sloth-period-window”命名空间:“”来自“window.yaml”:版本“sloth.slok.dev/v1”中的种类“AlertWindows”没有匹配项 确保首先安装 CRD

我尝试为 AlertWindow (alertwindows.sloth.slok.dev) 创建 CRD,但还没有成功。任何人都有正确的 CRD,如果这是解决它的最佳方法或其他帮助,请问?

预计 pod 与日志一起工作:

INFO[0001] Hot-reload triggered from http webhook        version=v0.11.0 window=7d

【问题讨论】:

    标签: prometheus kubernetes-custom-resources


    【解决方案1】:

    已经解决了,如果有人需要的话。

    使用掌舵: 在 values.yaml 中如下设置这些变量

    labelSelector: slo-window=7d
    defaultSloPeriod: 7d
    

    customSloConfig:
      enabled: true
      path: /windows
      data: 
        apiVersion: sloth.slok.dev/v1
        kind: AlertWindows
        spec:
          sloPeriod: 7d
          page:
            quick:
              errorBudgetPercent: 1
              shortWindow: 2m
              longWindow: 30m
            slow:
              errorBudgetPercent: 2
              shortWindow: 15m
              longWindow: 3h
          ticket:
            quick:
              errorBudgetPercent: 5
              shortWindow: 1h
              longWindow: 12h
            slow:
              errorBudgetPercent: 5
              shortWindow: 3h
              longWindow: 36h
    

    我创建了 CRD,使用它:

    ---
    apiVersion: apiextensions.k8s.io/v1
    kind: CustomResourceDefinition
    metadata:
      annotations:
        controller-gen.kubebuilder.io/version: (devel)
      creationTimestamp: null
      name: alertwindows.sloth.slok.dev
    spec:
      group: sloth.slok.dev
      names:
        categories:
        - saw
        kind: AlertWindows
        listKind: AlertWindowsList
        plural: alertwindows
        shortNames:
        - saw
        singular: alertwindow
      scope: Namespaced
      versions:
      - additionalPrinterColumns:
        - jsonPath: .spec.sloPeriod
          name: SLOPERIOD
          type: string
        - jsonPath: .metadata.creationTimestamp
          name: AGE
          type: date
        name: v1
        schema:
          openAPIV3Schema:
            description: AlertWindows....
            properties:
              apiVersion:
                description: 'APIVersion defines the versioned schema of this representation
                  of an object. Servers should convert recognized schemas to the latest
                  internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
                type: string
              kind:
                description: 'Kind is a string value representing the REST resource this
                  object represents. Servers may infer this from the endpoint the client
                  submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
                type: string
              metadata:
                type: object
              spec:
                description: spec for Alert Windows.
                type: object
                properties:
                  labels:
                    additionalProperties:
                      type: string
                    description: Labels are....
                    type: object
                  sloPeriod: 
                    description: period.
                    type: string
                  page:
                    description: xxx
                    type: object
                    properties:  
                      quick:
                        description: xxx
                        type: object
                        properties:
                          errorBudgetPercent:
                            type: integer
                          shortWindow:
                            type: string
                          longWindow:
                            type: string 
                      slow:
                        description: xxx
                        type: object
                        properties:
                          errorBudgetPercent:
                            type: number
                          shortWindow:
                            type: string
                          longWindow:
                            type: string                              
                  ticket:
                    description: xxx
                    type: object
                    properties:  
                      quick:
                        description: xxx
                        type: object
                        properties:
                          errorBudgetPercent:
                            type: integer
                          shortWindow:
                            type: string
                          longWindow:
                            type: string 
                      slow:
                        description: xxx
                        type: object
                        properties:
                          errorBudgetPercent:
                            type: integer
                          shortWindow:
                            type: string
                          longWindow:
                            type: string     
              status:
                properties:
                  lastPromOpRulesSuccessfulGenerated:
                    description: LastPromOpRulesGeneration tells the last atemp made for
                      a successful SLO rules generate.
                    format: date-time
                    type: string
                  observedGeneration:
                    description: ObservedGeneration tells the generation was acted on,
                      normally this is required to stop an infinite loop when the status
                      is updated because it sends a watch updated event to the watchers
                      of the K8s object.
                    format: int64
                    type: integer
                  processedSLOs:
                    description: ProcessedSLOs tells how many SLOs haven been processed
                      for Prometheus operator.
                    type: integer
                  promOpRulesGenerated:
                    description: PromOpRulesGenerated tells if the rules for prometheus
                      operator CRD have been generated.
                    type: boolean
                  promOpRulesGeneratedSLOs:
                    description: PromOpRulesGeneratedSLOs tells how many SLOs have been
                      processed and generated for Prometheus operator successfully.
                    type: integer
                required:
                type: object
            type: object
        served: true
        storage: true
        subresources:
          status: {}
    

    在 PrometheusServiceLevel 文件 (SLO) 中,有必要添加此标签:

      labels:
        slo-window: 7d 
    

    希望它能帮助别人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-15
      相关资源
      最近更新 更多