sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/plugins/optional/grafana/v1alpha/scaffolds/internal/templates/custom.go (about)

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package templates
    18  
    19  import (
    20  	"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
    21  )
    22  
    23  var _ machinery.Template = &CustomMetricsConfigManifest{}
    24  
    25  // Kustomization scaffolds a file that defines the kustomization scheme for the prometheus folder
    26  type CustomMetricsConfigManifest struct {
    27  	machinery.TemplateMixin
    28  	ConfigPath string
    29  }
    30  
    31  // SetTemplateDefaults implements file.Template
    32  func (f *CustomMetricsConfigManifest) SetTemplateDefaults() error {
    33  	f.Path = f.ConfigPath
    34  
    35  	f.TemplateBody = customMetricsConfigTemplate
    36  
    37  	f.IfExistsAction = machinery.SkipFile
    38  
    39  	return nil
    40  }
    41  
    42  // nolint: lll
    43  const customMetricsConfigTemplate = `---
    44  customMetrics:
    45  #  - metric: # Raw custom metric (required)
    46  #    type:   # Metric type: counter/gauge/histogram (required)
    47  #    expr:   # Prom_ql for the metric (optional)
    48  #    unit:   # Unit of measurement, examples: s,none,bytes,percent,etc. (optional)
    49  #
    50  #
    51  # Example:
    52  # ---
    53  # customMetrics:
    54  #   - metric: foo_bar
    55  #     unit: none
    56  #     type: histogram
    57  #   	expr: histogram_quantile(0.90, sum by(instance, le) (rate(foo_bar{job=\"$job\", namespace=\"$namespace\"}[5m])))
    58  `