Commit graph

55 commits

Author SHA1 Message Date
Sylvain Rabot c31a3e4c92
Build with Go 1.18 (#10501)
* Build with Go 1.18
* Update golangci-lint version

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2022-03-31 00:16:54 +02:00
Martina Ferrari 3e4bd4d913 Avoid literal integer overflows in 32 bit arches.
This commit ensures 64-bit integers are used in various tests that other wise
fail in 32-bit architectures.

It also adds support for int64 and uint64 types in the template.convertToFloat
function to support the test changes.

Closes: 10481
Signed-off-by: Martina Ferrari <tina@debian.org>
2022-03-29 22:51:20 +02:00
Julien Pivotto 9a2e93228e
Switch to grafana/regexp everywhere (#10268)
Let's have a consistent library for regexp.

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2022-02-13 00:58:27 +01:00
Levi Harrison 71a0f42331
template: Fix failing tests on non-amd64 architectures (#10196) 2022-01-24 18:15:38 -05:00
uesyn 13af2470bf
Add stripPort to template function (#10002)
* template: add `stripPort` to template functions

Signed-off-by: GitHub <suemura@zlab.co.jp>
2021-12-16 09:27:31 +00:00
David Leadbeater c0c5f3227b Update to return a float
Signed-off-by: David Leadbeater <dgl@dgl.cx>
2021-11-10 18:35:30 +01:00
David Leadbeater 89ebb3dcf2 Add parseDuration to template functions
This can be useful when generating rules, a query may use a duration,
and it may be useful to template that into a URL parameter. Therefore
this allows interfacing with systems that don't implement Prometheus
style duration parsing.

Signed-off-by: David Leadbeater <dgl@dgl.cx>
2021-11-10 18:35:30 +01:00
Jacques-Etienne Beaudet 9fae120f2a Support int and uint as datatype for template formatting
Fixes GH-9679

Signed-off-by: Jacques-Etienne Beaudet <jebeaudet@coveo.com>
2021-11-10 10:48:53 +01:00
beorn7 c954cd9d1d Move packages out of deprecated pkg directory
This creates a new `model` directory and moves all data-model related
packages over there:
  exemplar labels relabel rulefmt textparse timestamp value

All the others are more or less utilities and have been moved to `util`:
  gate logging modetimevfs pool runtime

Signed-off-by: beorn7 <beorn@grafana.com>
2021-11-09 08:03:10 +01:00
Mateusz Gozdek 1a6c2283a3 Format Go source files using 'gofumpt -w -s -extra'
Part of #9557

Signed-off-by: Mateusz Gozdek <mgozdekof@gmail.com>
2021-11-02 19:52:34 +01:00
George Robinson 049b4f4f13
Support customization of template options in TemplateExpander (#9290)
Signed-off-by: George Robinson <george.robinson@grafana.com>
2021-09-13 17:19:08 +05:30
George Robinson 9397402bd3 Fix template_test.go to check that error messages match the expected error message
Signed-off-by: George Robinson <george.robinson@grafana.com>
2021-09-02 15:52:07 +01:00
Levi Harrison 17ea8d006a
Added external URL access
Signed-off-by: Levi Harrison <git@leviharrison.dev>
2021-05-30 23:35:26 -04:00
Julien Pivotto ea6f6bba74
Enable parsing strings in humanize functions (#8682)
* Enable parsing strings in humanize functions

This is useful to humanize count_values or buckets labels.

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2021-04-14 00:30:15 +02:00
Julien Pivotto 6c56a1faaa
Testify: move to require (#8122)
* Testify: move to require

Moving testify to require to fail tests early in case of errors.

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>

* More moves

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2020-10-29 09:43:23 +00:00
Julien Pivotto 4e5b1722b3
Move away from testutil, refactor imports (#8087)
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2020-10-22 11:00:08 +02:00
Guangwen Feng 663016ee0c
Add unit test case to improve test coverage for template.go (#7537)
Signed-off-by: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
2020-07-09 09:43:32 +01:00
johncming 099b0d7c29 template: remove redundant parentheses. (#5904)
Signed-off-by: johncming <johncming@yahoo.com>
2019-08-16 09:41:01 +01:00
AllenZMC 00b556e9b5 fix mis-spelling in template.go
Signed-off-by: czm <zhongming.chang@daocloud.io>
2019-08-11 18:22:42 +08:00
Jens Erat 375aeb9158 Added humanizePercentage formatting to templates (#5670)
Lots of alerts are based on ratios (eg. disk usage), and humans are used
to values in percentage in textual descriptions.

Signed-off-by: Jens Erat <email@jenserat.de>
2019-06-15 08:59:57 +01:00
Simon Pasquier 45506841e6
*: enable all default linters (#5504)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-05-03 15:11:28 +02:00
Bjoern Rabenstein 38d518c0fe Rework #5009 after comments
Signed-off-by: Bjoern Rabenstein <bjoern@rabenste.in>
2019-04-17 01:40:10 +02:00
Sylvain Rabot 335a34486e Add external labels to template expansion
This affects the expansion of templates in alert labels and
annotations and console templates.

Signed-off-by: Sylvain Rabot <sylvain@abstraction.fr>
2019-04-17 01:40:10 +02:00
Tariq Ibrahim 8fdfa8abea refine error handling in prometheus (#5388)
i) Uses the more idiomatic Wrap and Wrapf methods for creating nested errors.
ii) Fixes some incorrect usages of fmt.Errorf where the error messages don't have any formatting directives.
iii) Does away with the use of fmt package for errors in favour of pkg/errors

Signed-off-by: tariqibrahim <tariq181290@gmail.com>
2019-03-26 00:01:12 +01:00
Mucahit Kurt 4a6c329d71 add alert template expanding failure metric (#4747)
Signed-off-by: Mucahit Kurt <mucahitkurt@gmail.com>
2018-11-06 14:39:06 +00:00
Ganesh Vernekar 05726c5ea2 Test template expansion while loading groups (#4537)
Signed-off-by: Ganesh Vernekar <cs15btech11018@iith.ac.in>
2018-09-13 13:55:58 +01:00
Elif T. Kuş daebf68ea2 Rewrote tests for relabel and template (#3754)
* relabel: use testutil for testing

* template: use testutil for testing
2018-03-29 16:02:28 +01:00
Dominik-K 67c13ba156 template: all text_template settings before parsing (bugfix "nil-pointer dereference") (#3854) 2018-02-17 07:57:25 +00:00
Fabian Reinartz 2d0e3746ac rules: remove dependency on promql.Engine 2017-11-24 07:57:54 +01:00
Julius Volz 099df0c5f0 Migrate "golang.org/x/net/context" -> "context" (#3333)
In some places, where ctxhttp or gRPC are concerned, we still need to use the
old contexts.
2017-10-24 21:21:42 -07:00
Fabian Reinartz 06c2b76cd4 Merge branch 'master' into uptsdb 2017-05-16 16:48:37 +02:00
Julius Volz ac203ef0ee Add externalURL template function (#2716)
This allows users to e.g. add links back to the generating Prometheus
right in their alert templates.
2017-05-13 15:47:04 +02:00
Fabian Reinartz 311e7b5069 storage/vendor: update to latest fabxc/tsdb 2017-02-20 11:11:44 +01:00
Fabian Reinartz 157e698958 web/api: fix min/max timestamps to valid range 2017-01-16 14:09:59 +01:00
Fabian Reinartz fecf9532b9 *: fix misc compile errors 2016-12-25 11:42:57 +01:00
Fabian Reinartz 5817cb5bde *: migrate from model.* to promql.* types 2016-12-25 00:37:46 +01:00
Fabian Reinartz 09666e2e2a promql: make scalar public 2016-12-24 10:44:04 +01:00
Julius Volz c187308366 storage: Contextify storage interfaces.
This is based on https://github.com/prometheus/prometheus/pull/1997.

This adds contexts to the relevant Storage methods and already passes
PromQL's new per-query context into the storage's query methods.
The immediate motivation supporting multi-tenancy in Frankenstein, but
this could also be used by Prometheus's normal local storage to support
cancellations and timeouts at some point.
2016-09-19 16:29:07 +02:00
Julius Volz ed5a0f0abe promql: Allow per-query contexts.
For Weaveworks' Frankenstein, we need to support multitenancy. In
Frankenstein, we initially solved this without modifying the promql
package at all: we constructed a new promql.Engine for every
query and injected a storage implementation into that engine which would
be primed to only collect data for a given user.

This is problematic to upstream, however. Prometheus assumes that there
is only one engine: the query concurrency gate is part of the engine,
and the engine contains one central cancellable context to shut down all
queries. Also, creating a new engine for every query seems like overkill.

Thus, we want to be able to pass per-query contexts into a single engine.

This change gets rid of the promql.Engine's built-in base context and
allows passing in a per-query context instead. Central cancellation of
all queries is still possible by deriving all passed-in contexts from
one central one, but this is now the responsibility of the caller. The
central query context is now created in main() and passed into the
relevant components (web handler / API, rule manager).

In a next step, the per-query context would have to be passed to the
storage implementation, so that the storage can implement multi-tenancy
or other features based on the contextual information.
2016-09-19 15:38:17 +02:00
beorn7 094a098ce6 Revert "Revert the /graph changes."
This reverts commit aa43d34a86.

This brings back the /graph changes so that @grandbora can continue to
work on the redirect for backwards compatibility. And other changes
can already take the new /graph parameters into account.
2016-09-03 21:05:23 +02:00
beorn7 aa43d34a86 Revert the /graph changes.
This revert will be reverted once v1.1 is released and has its own
release branch. Since we had already change on top of this, there was
no cleaner way of cutting those changes out.

This commit reverts the following commits:

Revert "Update backend helpers and templates to new url schema"
This reverts commit fc6cdd0611.

Revert "Refactor graph.js"
This reverts commit 445fac56e0.

Revert "Use query parameters in the url"
This reverts commit 3e18d86d8a.

Revert "Point to correct place for GraphLinkForExpression"
This reverts commit 3da825fc76.

Assets are also updated.
2016-09-02 13:59:09 +02:00
Dmitry Ulianov a8619111f3 Added toUpper and toLower formatting to templates 2016-08-15 14:00:22 +03:00
Bora Tunca fc6cdd0611 Update backend helpers and templates to new url schema 2016-08-08 09:52:14 +02:00
beorn7 4b574e8a61 Switch chunk encoding to type 2 where it was hardcoded type 1 before
The chunk encoding was hardcoded there because it mostly doesn't
matter what encoding is chosen in that test. Since type 1 is
battle-hardened enough, I'm switching to type 2 here so that we can
catch unexpected problems as a byproduct. My expectation is that the
chunk encoding doesn't matter anyway, as said, but then "unexpected
problems" contains the word "unexpected".
2016-03-20 23:32:20 +01:00
Brian Brazil 738af32057 template: Use zero-values for missing values.
Currently missing values will get the value <no value>
rather than the empty string. Using the empty string is
more consistent, and should be easier for users to deal with too.
2015-11-28 13:45:32 +00:00
Julius Volz af513468eb Fix some dead code, missing error checks, shadowings.
I applied
https://medium.com/@jgautheron/quality-pipeline-for-go-projects-497e34d6567
and was greeted with a deluge of warnings, most of which were not
applicable or really fixable realistically. These are some of the first
ones I decided to fix.
2015-09-14 12:21:34 +02:00
Julius Volz 995d3b831d Fix most golint warnings.
This is with `golint -min_confidence=0.5`.

I left several lint warnings untouched because they were either
incorrect or I felt it was better not to change them at the moment.
2015-08-26 12:44:46 +02:00
Fabian Reinartz d6b8da8d43 Switch promql types to common/model 2015-08-25 13:49:14 +02:00
Fabian Reinartz 306e8468a0 Switch from client_golang/model to common/model 2015-08-21 13:33:38 +02:00
Julius Volz bbc8b8490e Switch human-readable times to UTC.
This fixes https://github.com/prometheus/prometheus/issues/829
2015-06-23 21:26:05 +02:00