Commit b23b74a
authored
Adds resourceVersion support to k8sObject receiver (#46543)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
Implements optional resourceVersion checkpointing to prevent duplicate
events on collector restart.
Resource version persistence is developed as part of watch mechanism
which is being used by k8sObjects receiver and k8sEvents receiver. The
feature is not enabled for `pull` mode in any of the receivers.
Features:
- Opt-in via declaring storage extension for persistence
- Namespace-aware checkpointing: Creates per stream checkpoint when
separate namespaces are mentioned. Per namespace keys are maintained in
the storage. The format is
`latestResourceVersion/configmaps.kube-system` for per namespace watch
stream. In case namespaces are not specified, a global clusterwide watch
stream is created that creates a different checkpoint key with format:
`latestResourceVersion/pods, latestResourceVersion/nodes`
- Watch mode only (validated at config time)
- If persistence is enabled, then `resource_version` provided in the
config will be ignored. The persisted version will be used to kick-off
the watch stream.
- In case of stale persisted version, a List() API will be called to get
the latest resource version available which is the existing way of
handling stale resource version in k8s inventory.
Configuration:
```
receivers:
k8sobjects:
storage: file_storage
objects:
- name: pods
mode: watch
```
How it works:
1. At the start of each watch stream, `getResourceVersion()` is called
which checks if persistence is enabled then it retrieves the persisted
version.
- If persisted version is empty then it calls List() API to get the list
of available objects and picks the latest version and persists it.
- If persisted version is non-empty then it is supplied to kick-off the
watch stream.
- In case, the persisted version supplied to start watch stream in the
step above is stale then checkpoint is deleted. This prompts the List()
API call again to get the latest available resource version for the
given stream.
2. After processing each watch event, saves resourceVersion to storage.
3. In case persistence operation fails for any reason, the watch stream
continues.
#### Link to tracking issue
Fixes
#46017
<!--Describe what testing was performed and which tests were added.-->
#### Testing
- Unit tests
- Manually built the updated image using ` make docker-otelcontribcol`
and deployed in local. Tested various restarts and 410 handling
scenarios for global watch streams, per namespace watch streams.
<!--Describe the documentation added.-->
#### Documentation
- Updated schema yaml files for k8sobject and k8sevents receiver.
<!--Please delete paragraphs that you did not use before submitting.-->
Example - how the new config would look like?
```
extensions:
file_storage:
directory: /var/lib/otelcol/storage
timeout: 10s
receivers:
k8sobjects:
auth_type: serviceAccount
storage: file_storage
include_initial_state: true
objects:
- name: pods
mode: watch
namespaces: [default]
- name: events
mode: watch
namespaces: [default]
exporters:
nop:
service:
telemetry:
logs:
level: debug
extensions: [file_storage]
pipelines:
logs:
receivers: [k8sobjects]
exporters: [nop]
```
---------
Signed-off-by: Dhruv Shah <dhruv.shah@sumologic.com>1 parent 4aa4ab4 commit b23b74a
17 files changed
Lines changed: 1759 additions & 65 deletions
File tree
- .chloggen
- internal/k8sinventory
- watch
- receiver
- k8seventsreceiver
- k8sobjectsreceiver
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
| 8 | + | |
| 9 | + | |
7 | 10 | | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| 17 | + | |
14 | 18 | | |
15 | 19 | | |
16 | 20 | | |
| 21 | + | |
17 | 22 | | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
21 | 26 | | |
| 27 | + | |
| 28 | + | |
22 | 29 | | |
23 | 30 | | |
24 | 31 | | |
| |||
27 | 34 | | |
28 | 35 | | |
29 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
30 | 48 | | |
31 | 49 | | |
32 | 50 | | |
33 | 51 | | |
34 | 52 | | |
35 | | - | |
| 53 | + | |
36 | 54 | | |
37 | 55 | | |
38 | 56 | | |
39 | | - | |
| 57 | + | |
40 | 58 | | |
41 | 59 | | |
42 | 60 | | |
| |||
48 | 66 | | |
49 | 67 | | |
50 | 68 | | |
| 69 | + | |
| 70 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
0 commit comments