mirror of
https://github.com/prometheus/prometheus.git
synced 2026-05-28 04:02:21 -04:00
Add support for generating only Opts types
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
This commit is contained in:
parent
f7b009de9b
commit
ea2370e773
2 changed files with 26 additions and 0 deletions
|
|
@ -268,6 +268,20 @@ deny contains metric_violation(
|
|||
not is_number(val)
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# Rule: only_opts must be a boolean when present
|
||||
# =============================================================================
|
||||
deny contains metric_violation(
|
||||
sprintf("Metric '%s': annotations.prometheus.only_opts must be a boolean, got %v", [group.metric_name, type_name(group.annotations.prometheus.only_opts)]),
|
||||
group.id,
|
||||
group.metric_name
|
||||
) if {
|
||||
group := input.groups[_]
|
||||
group.type == "metric"
|
||||
group.annotations.prometheus.only_opts
|
||||
not is_boolean(group.annotations.prometheus.only_opts)
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# Helper Functions
|
||||
# =============================================================================
|
||||
|
|
|
|||
|
|
@ -102,6 +102,17 @@ func (a {{ name }}Attr) Value() string {
|
|||
{%- else -%}
|
||||
{%- set metric_inst = (metric.instrument | default("gauge")) | map_text("go_instrument_type") -%}
|
||||
{%- endif -%}
|
||||
{#- Check if only_opts is set - generate just an Opts function instead of full type -#}
|
||||
{%- if prom.only_opts %}
|
||||
|
||||
{{ h.metric_typedoc(metric, "") | comment | trim }}
|
||||
func {{ metric_name }}Opts() prometheus.{{ metric_inst }}Opts {
|
||||
return prometheus.{{ metric_inst }}Opts{
|
||||
Name: "{{ metric.metric_name }}",
|
||||
Help: "{{ metric.brief | default("") | trim }}",
|
||||
}
|
||||
}
|
||||
{%- else %}
|
||||
|
||||
{{ h.metric_typedoc(metric, "") | comment | trim }}
|
||||
type {{ metric_name }} struct {
|
||||
|
|
@ -242,6 +253,7 @@ func (m {{ metric_name }}) With(
|
|||
return m.{{ metric_inst }}Vec.With(labels)
|
||||
}
|
||||
{%- endif %}
|
||||
{%- endif %}{# end only_opts else block #}
|
||||
{%- if not loop.last %}
|
||||
|
||||
{% endif %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue