Grafana Alert Templating - grafana

I am struggling to include values into my alerting template
(Using Grafana 9.03 with classic condition alerting)
Query
Alert Evaluation
I tried to use {{ $values.B0 }} which works but only displaying the value. I want to use the Tag "Limit" for example "ImportStatNSC4903"
I did some more tries with:
{{ $values.B0.Limit }}
{{ $values.B0.labels }}
{{ $labels }}
Any ideas what I am doing wrong?
I am struggling to include values into my alerting template. I want a summery that tells me clearly why this alert was triggered
For example:
Limit ImportStatNSC4903 is outside the defined Boundaries

Related

Are Helm variables case insensitive? (The templates seem to be.)

I am trying to debug one of my Helm charts and I noticed that the app.kubernetes.io/version label is created using the following code (in _helpers.tpl):
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
But the actual variable is called appVersion. Similar inconsistencies exist with version and name. The use of them is using PascalCase, but the definition is using camelCase. I tried to google it, but can't find any info on it.
Are Helm variables really case insensitive? Or is there some kind of conversion going on behind the scenes.
The fields in the built-in objects are generally capitalized. That documentation also includes an example using {{ .Chart.Name }}-{{ .Chart.Version }}. Even though .Chart contains the contents of the chart.yaml file, its fields follow this convention.
Field access is case-sensitive and if you reference .Chart.appVersion you should get an error.
At an implementation level, the Go template . operator can either navigate a Go object tree or a Go map. The top-level object is a mix of maps and objects. .Values is an unstructured map; a release can include any values it wants in essentially any YAML layout. .Release turns out to be a map too, but with fixed known keys.
.Chart is a chart.Metadata object (not the parsed YAML directly but an object form of it). Its fields are visible to the template engine. Go's rule is that structure fields that begin with capital letters are visible, and that capitalization carries through back to the template engine.

Template file in yaml

Values.yaml
cpulimit: 200m
memlimit: 512M
configmap.yaml
mem_pool_size = {{ ((.Values.memlimit)) mul 0.8 }} --> not working
mem_pool_size = {{ .Values.memlimit mul 0.8 }} --> not working
mem_pool_size = {{ .Values.memlimit * 0.8 }} --> not working
mem_pool_size = {{ .Values.memlimit }} * 0.8 --> not working
mem_pool_size = {{ .Values.memlimit }} mul 0.8 --> not working
Tried many ways but i dint got the exact solution.if user provides value of memlimit as 512M i should assign only 80 % ram so the value will be 410M. I am finding a way whether arithmetic operations are supported in helm templates. Is there any example for this.
In helm templates this is done via pipelines. Some of them are defined via Go template language and some others are part of Sprig template library.
I did not find a complete list which are valid and working in Helm, but I did not find a Sprig one not working as explained in the Sprig documentation.
So first the syntax for pipelines has to be:
{{ .Values.memlimit | mul 2 }}
However the Math Functions only work on int64. But 512M is not an int. So you can let the user specify the limits as bytes or chain more pipes to first remove the "M" and then do the calculation:
{{ .Values.memlimit | replace "M" "" |mul 2 }}M
Since Memory can be specified with different units you maybe need some regexp:
{{ .Values.memlimit |regexFind "[1-9]+" |mul 2 }}{{ .Values.memlimit | regexFind "[a-zA-Z]+" }}
But like stated all Sprig Math Functions only work on int64 so mul 0.8 will multiply by zero, mul 1,6 with only multiply with 1 and so on.
So probably you have to wait for the Sprig functions to also work with floats to achieve a percentage based calculation or you find some clever trick with the provided Math functions by Sprig and the int64 type.
Maybe something like explained in this answer:
C How to calculate a percentage(perthousands) without floating point precision

Symfony 2, double error

Why i have double error when i want to customize my form ?
Template:
<div>
{{ form_errors(edit_form.wiek) }}
{{ form_widget(edit_form.wiek) }}
</div>
HTML:
You probably see the error on the field level, but also on the form level. It can look like you have two errors especially if there's only one field in your form.
Dig into the customizing error output of the form cookbook for more details.
Edit
The doc gives a much better explanation :)
You can also customize the error output for just one specific field type. For example, certain errors that are more global to your form (i.e. not specific to just one field) are rendered separately, usually at the top of your form.

What's the substitution of Input::had() in Laravel 4?

I'm porting an existent L3 project into L4.
In my login view I've used {{ Form::checkbox('remember', 'remember', Input::had('remember')) }} to repopulate the status of remember me button.
However, in L4, Input::had is deprecated. So what's the substitution of Input::had()? Or there's another sexier way to repopulate status of a checkbox?
Use
{{ Form::checkbox('remember', 'remember', null !== Input::old('remember')) }}

Explicitly print CSRF token field instead of form_rest(form)?

How can I explicitly print CSRF field instead of using {{ form_rest(form) }}?
I need this because I'm going to hide/show some fields based on conditions, however {{ form_rest(form) }} is going to print all of the remaining fields (which is what I'd like to avoid).
It can be done this way:
{{ form_widget(form._token) }}
Also you might want to consider adding fields conditionally in your form type instead of making that kind of decisions in a template.