Commit Graph

26 Commits

Author SHA1 Message Date
Filip Petkovski 7a78897d0b
Improve reliability of Kubernetes SD tests (#10761)
The tests for Kubernetes SD rely on comparing target groups by first
serializing them to JSON. However, the target group MarshalJSON function
only serializes the __address__ label, which makes eliminates all other
labels from the comparison.

This commit implements a separate marshaling function intended for use in
Kubernetes SD tests. The function serializes all target labels, making
comparisons much more reliable. The commit also fixes all tests that
started to fail due to the newly introduced change.

Signed-off-by: Filip Petkovski <filip.petkovsky@gmail.com>
2022-06-07 16:19:40 +01:00
Matthieu MOREL f43749e82f
refactor (discovery): move from github.com/pkg/errors to 'errors' and 'fmt' (#10807)
Signed-off-by: Matthieu MOREL <mmorel-35@users.noreply.github.com>

Co-authored-by: Matthieu MOREL <mmorel-35@users.noreply.github.com>
2022-06-03 13:47:14 +02:00
fpetkovski fa798d3042
Allow attaching node metadata
Signed-off-by: fpetkovski <filip.petkovsky@gmail.com>
2022-03-10 08:40:52 +01:00
fpetkovski de87515b24 Implement target discovery in own k8s namespace
This commit adds support for discovering targets from the same
Kubernetes namespace as the Prometheus pod itself. Own-namespace
discovery can be indicated by using "." as the namespace.

Fixes #9782

Signed-off-by: fpetkovski <filip.petkovsky@gmail.com>
2021-12-14 13:41:38 +01:00
Mateusz Gozdek ea924746b3
discovery/kubernetes: improve test logic for waiting for discoverers (#9584)
When running tests in parallel, 10 milliseconds may not be enough for
all discoverers to register, which will make test flaky.

This commit changes the waiting logic to wait for number of discoverers
to stop increasing during given time frame, which should be large enough
for single discoverer to register in test environment.

A following run passes with this commit:

go test -failfast -race -count 100 -v ./discovery/kubernetes/

Signed-off-by: Mateusz Gozdek <mgozdekof@gmail.com>
2021-11-02 22:17:32 +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
Takashi Kusumi 6634a570cf Kubernetes SD: Support networking.k8s.io/v1 Ingress
Signed-off-by: Takashi Kusumi <tkusumi@zlab.co.jp>
2021-08-16 08:35:42 +09:00
Levi Harrison b5f6f8fb36 Switched to go-kit/log
Signed-off-by: Levi Harrison <git@leviharrison.dev>
2021-06-11 12:28:36 -04:00
kongxs 632678a461
Fix spelling mistake (#8879)
* Fix spelling mistake

Signed-off-by: kjinan <2008kongxiangsheng@163.com>

* Update discovery/kubernetes/endpoints.go

Co-authored-by: Julien Pivotto <roidelapluie@gmail.com>
Signed-off-by: kjinan <2008kongxiangsheng@163.com>

Co-authored-by: Julien Pivotto <roidelapluie@gmail.com>
2021-06-01 00:49:29 +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
Andy Bursavich 4e6a94a27d
Invert service discovery dependencies (#7701)
This also fixes a bug in query_log_file, which now is relative to the config file like all other paths.

Signed-off-by: Andy Bursavich <abursavich@gmail.com>
2020-08-20 13:48:26 +01:00
Frederic Branczyk 06e2c2f804
Merge pull request #6838 from brancz/endpointslice
discovery/kubernetes: EndpointSlice discovery
2020-08-12 16:42:49 +02:00
Julien Pivotto e76c436e9c
Goleak in discoveries, scrape, rules (#7662)
* Add go leak tests for discoveries with goroutines

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

* Add go leak tests in rules

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

* Add go leak tests in scrape tests

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2020-07-27 09:38:08 +01:00
Frederic Branczyk f6c5a75661 discovery/kubernetes: Add Kubernetes EndpointSlice discovery
Signed-off-by: Frederic Branczyk <fbranczyk@gmail.com>
Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
2020-06-14 21:55:27 +02:00
Frederic Branczyk 7b1c0d6b66
discovery/kubernetes: Fix incorrect premature break of reading results
Previously `max` results stopped reading from results in tests
prematurely, as it stopped when `max` number of items were received from
the channel instead of `max` number of unique target groups received.
This caused flaky tests where the same target group was received
multiple times, as Kubernetes informers may emit the same event multiple
times.

Before this patch, running this test repeatedly failed eventually. After
this patch I have run the test many thousand times without failure.

```bash
go test -run TestEndpointsDiscoveryNamespaces -count 1000 -test.v
```

Signed-off-by: Frederic Branczyk <fbranczyk@gmail.com>
2020-06-11 16:08:28 +02:00
Tariq Ibrahim 0730d6eb74
remove deprecated methods from the MetricProvider interface
Signed-off-by: Tariq Ibrahim <tariq181290@gmail.com>
2020-04-06 09:23:58 -07:00
Frederic Branczyk d06f1034db discovery/kubernetes: Fix race in test setup
Signed-off-by: Frederic Branczyk <fbranczyk@gmail.com>
2020-02-25 10:33:41 +01:00
Simon Pasquier dafd1632a2 discovery/kubernetes: add present labels for labels/annotations (#5443)
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
2019-04-10 13:21:42 +01:00
Tariq Ibrahim bfcdba211f remove the prepended watch reactor from the fake k8s client (#5140)
Signed-off-by: tariqibrahim <tariq.ibrahim@microsoft.com>
2019-01-28 16:42:25 +01:00
JoeWrightss e8be31eed9 Fixs typo: 'possibliy' to 'possibly' (#4974)
Signed-off-by: JoeWrightss <zhoulin.xie@daocloud.io>
2018-12-18 11:52:40 +01:00
Camille Janicki b035ea0ea9 Change discovery subpackages to not use testify in tests (#4612)
* Change discovery subpackages to not use testify in tests

Signed-off-by: Camille Janicki <camille.janicki@gmail.com>

* Remove testify suite from vendor dir

Signed-off-by: Camille Janicki <camille.janicki@gmail.com>
2018-09-18 17:35:22 +02:00
Yecheng Fu 2be543e65a Simplify some code and comments.
Signed-off-by: Yecheng Fu <cofyc.jackson@gmail.com>
2018-04-25 19:29:34 +02:00
Yecheng Fu 3a253f796c Fix grammar in comments and add missing `expectedMaxItems` to let it
break fast.

Signed-off-by: Yecheng Fu <cofyc.jackson@gmail.com>
2018-04-25 19:29:03 +02:00
Yecheng Fu d73b0d3141 Move hasSynced interface and its implementations to *_test.go files.
Signed-off-by: Yecheng Fu <cofyc.jackson@gmail.com>
2018-04-25 19:28:49 +02:00
Yecheng Fu 8ceb8f2ae8 Refactor Kubernetes Discovery Part 2: Refactoring
- Do initial listing and syncing to scrape manager, then register event
  handlers may lost events happening in listing and syncing (if it
  lasted a long time). We should register event handlers at the very
  begining, before processing just wait until informers synced (sync in
  informer will list all objects and call OnUpdate event handler).
- Use a queue then we don't block event callbacks and an object will be
  processed only once if added multiple times before it being processed.
- Fix bug in `serviceUpdate` in endpoints.go, we should build endpoints
  when `exists && err == nil`. Add `^TestEndpointsDiscoveryWithService`
  tests to test this feature.

Testing:

- Use `k8s.io/client-go` testing framework and fake implementations which are
  more robust and reliable for testing.
- `Test\w+DiscoveryBeforeRun` are used to test objects created before
  discoverer runs
- `Test\w+DiscoveryAdd\w+` are used to test adding objects
- `Test\w+DiscoveryDelete\w+` are used to test deleting objects
- `Test\w+DiscoveryUpdate\w+` are used to test updating objects
- `TestEndpointsDiscoveryWithService\w+` are used to test endpoints
  events triggered by services
- `cache.DeletedFinalStateUnknown` related stuffs are removed, because
  we don't care deleted objects in store, we only need its name to send
  a specical `targetgroup.Group` to scrape manager

Signed-off-by: Yecheng Fu <cofyc.jackson@gmail.com>
2018-04-25 19:28:34 +02:00