Skip to content

Commit 5325642

Browse files
author
Serhii Zakharov
committed
implemented fetching rules from a remote server for conditional gathering
1 parent b94b61c commit 5325642

File tree

13 files changed

+413
-279
lines changed

13 files changed

+413
-279
lines changed

README.md

+47-36
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Insights Operator
22

3-
This cluster operator gathers anonymized system configuration and reports it to Red Hat Insights. It is a part of the
4-
standard OpenShift distribution. The data collected allows for debugging in the event of cluster failures or
3+
This cluster operator gathers anonymized system configuration and reports it to Red Hat Insights. It is a part of the
4+
standard OpenShift distribution. The data collected allows for debugging in the event of cluster failures or
55
unanticipated errors.
66

77
# Table of Contents
@@ -12,26 +12,27 @@ unanticipated errors.
1212
- [Testing](#testing)
1313
- [Documentation](#documentation)
1414
- [Getting metrics from Prometheus](#getting-metrics-from-prometheus)
15-
- [Generate the certificate and key](#generate-the-certificate-and-key)
16-
- [Prometheus metrics provided by Insights Operator](#prometheus-metrics-provided-by-insights-operator)
17-
- [Running IO locally](#running-io-locally)
18-
- [Running IO on K8s](#running-io-on-k8s)
19-
- [Getting the data directly from Prometheus](#getting-the-data-directly-from-prometheus)
20-
- [Debugging Prometheus metrics without valid CA](#debugging-prometheus-metrics-without-valid-ca)
15+
- [Generate the certificate and key](#generate-the-certificate-and-key)
16+
- [Prometheus metrics provided by Insights Operator](#prometheus-metrics-provided-by-insights-operator)
17+
- [Running IO locally](#running-io-locally)
18+
- [Running IO on K8s](#running-io-on-k8s)
19+
- [Getting the data directly from Prometheus](#getting-the-data-directly-from-prometheus)
20+
- [Debugging Prometheus metrics without valid CA](#debugging-prometheus-metrics-without-valid-ca)
2121
- [Debugging](#debugging)
22-
- [Using the profiler](#using-the-profiler)
23-
- [Starting IO with the profiler](#starting-io-with-the-profiler)
24-
- [Collect profiling data](#collect-profiling-data)
25-
- [Analyzing profiling data](#analyzing-profiling-data)
22+
- [Using the profiler](#using-the-profiler)
23+
- [Starting IO with the profiler](#starting-io-with-the-profiler)
24+
- [Collect profiling data](#collect-profiling-data)
25+
- [Analyzing profiling data](#analyzing-profiling-data)
2626
- [Changelog](#changelog)
27-
- [Updating the changelog](#updating-the-changelog)
27+
- [Updating the changelog](#updating-the-changelog)
2828
- [Reported data](#reported-data)
29-
- [Insights Operator Archive](#insights-operator-archive)
30-
- [Sample IO archive](#sample-io-archive)
31-
- [Generating a sample archive](#generating-a-sample-archive)
32-
- [Formatting archive json files](#formatting-archive-json-files)
33-
- [Obfuscating an archive](#obfuscating-an-archive)
34-
- [Updating the sample archive](#updating-the-sample-archive)
29+
- [Insights Operator Archive](#insights-operator-archive)
30+
- [Sample IO archive](#sample-io-archive)
31+
- [Generating a sample archive](#generating-a-sample-archive)
32+
- [Formatting archive json files](#formatting-archive-json-files)
33+
- [Obfuscating an archive](#obfuscating-an-archive)
34+
- [Updating the sample archive](#updating-the-sample-archive)
35+
- [Conditional Gathering](#conditional-gathering)
3536
- [Contributing](#contributing)
3637
- [Support](#support)
3738
- [License](#license)
@@ -60,7 +61,7 @@ Unit tests can be started by the following command:
6061
make test
6162
```
6263

63-
It is also possible to specify CLI options for Go test. For example, if you need to disable test results caching,
64+
It is also possible to specify CLI options for Go test. For example, if you need to disable test results caching,
6465
use the following command:
6566

6667
```shell script
@@ -72,8 +73,8 @@ VERBOSE=-count=1 make test
7273
# Documentation
7374

7475

75-
The document [docs/gathered-data](docs/gathered-data.md) contains the list of collected data and the API that is used
76-
to collect it. This documentation is generated by the command bellow, by collecting the comment tags located above
76+
The document [docs/gathered-data](docs/gathered-data.md) contains the list of collected data and the API that is used
77+
to collect it. This documentation is generated by the command bellow, by collecting the comment tags located above
7778
each Gather method.
7879

7980
To start generating the document run:
@@ -86,12 +87,12 @@ make docs
8687

8788
## Generate the certificate and key
8889

89-
Certificate and key are required to access Prometheus metrics (instead 404 Forbidden is returned). It is possible
90-
to generate these two files from Kubernetes config file. Certificate is stored in `users/admin/client-cerfificate-data`
91-
and key in `users/admin/client-key-data`. Please note that these values are encoded by using Base64 encoding,
90+
Certificate and key are required to access Prometheus metrics (instead 404 Forbidden is returned). It is possible
91+
to generate these two files from Kubernetes config file. Certificate is stored in `users/admin/client-cerfificate-data`
92+
and key in `users/admin/client-key-data`. Please note that these values are encoded by using Base64 encoding,
9293
so it is needed to decode them, for example by `base64 -d`.
9394

94-
There's a tool named `gen_cert_key.py` that can be used to automatically generate both files. It is stored in `tools`
95+
There's a tool named `gen_cert_key.py` that can be used to automatically generate both files. It is stored in `tools`
9596
subdirectory.
9697

9798
```shell script
@@ -100,10 +101,10 @@ gen_cert_file.py kubeconfig.yaml
100101

101102
## Prometheus metrics provided by Insights Operator
102103

103-
It is possible to read Prometheus metrics provided by Insights Operator. Example of metrics exposed by
104+
It is possible to read Prometheus metrics provided by Insights Operator. Example of metrics exposed by
104105
Insights Operator can be found at [metrics.txt](docs/metrics.txt)
105106

106-
Depending on how or where the IO is running you may have different ways to retrieve the metrics.
107+
Depending on how or where the IO is running you may have different ways to retrieve the metrics.
107108
Here is a list of some options, so you can find the one that fits you:
108109

109110
### Running IO locally
@@ -185,7 +186,7 @@ go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
185186
go tool pprof http://localhost:6060/debug/pprof/heap
186187
```
187188

188-
These commands will create a compressed file that can be visualized using a variety of tools, one of them is
189+
These commands will create a compressed file that can be visualized using a variety of tools, one of them is
189190
the `pprof` tool.
190191

191192
### Analyzing profiling data
@@ -213,7 +214,7 @@ It uses both the local git and GitHub`s API to update the file so:
213214

214215
It can be used 2 ways:
215216

216-
1. Providing no command line arguments the script will update the current `CHANGELOG.md` with the latest changes
217+
1. Providing no command line arguments the script will update the current `CHANGELOG.md` with the latest changes
217218
2. according to the local git state.
218219

219220
> 🚨 IMPORTANT: It will only work with changelogs created with this script
@@ -222,7 +223,7 @@ It can be used 2 ways:
222223
go run cmd/changelog/main.go
223224
```
224225

225-
2. Providing 2 command line arguments, `AFTER` and `UNTIL` dates the script will generate a new `CHANGELOG.md` within
226+
2. Providing 2 command line arguments, `AFTER` and `UNTIL` dates the script will generate a new `CHANGELOG.md` within
226227
the provided time frame.
227228

228229
```shell script
@@ -235,17 +236,17 @@ go run cmd/changelog/main.go 2021-01-10 2021-01-20
235236
* ClusterOperator objects
236237
* All non-secret global config (hostnames and URLs anonymized)
237238

238-
The list of all collected data with description, location in produced archive and link to Api and some examples is
239+
The list of all collected data with description, location in produced archive and link to Api and some examples is
239240
at [docs/gathered-data.md](docs/gathered-data.md)
240241

241-
The resulting data is packed in `.tar.gz` archive with folder structure indicated in the document. Example of such
242+
The resulting data is packed in `.tar.gz` archive with folder structure indicated in the document. Example of such
242243
archive is at [docs/insights-archive-sample](docs/insights-archive-sample).
243244

244245
## Insights Operator Archive
245246

246247
### Sample IO archive
247248

248-
There is a sample IO archive maintained in this repo to use as a quick reference. (can be found
249+
There is a sample IO archive maintained in this repo to use as a quick reference. (can be found
249250
at [docs/insights-archive-sample](https://github.com/openshift/insights-operator/tree/master/docs/insights-archive-sample))
250251

251252
To keep it up-to-date it is **required** to update this manually when developing a new data enhancement.
@@ -311,8 +312,18 @@ the `managedFields` field when it was removed from the IO archive to save space:
311312
./scripts/update_sample_archive.sh <Path of directory with the NEW extracted IO archive> '"managedFields":'
312313
```
313314

314-
The path of the sample archive directory should be constant relative to
315-
the path of the script and therefore does not have to be specified explicitly.
315+
The path of the sample archive directory should be constant relative to the path of the script and therefore does not
316+
have to be specified explicitly.
317+
318+
# Conditional Gathering
319+
320+
Conditional Gatherer fetches its config from remote URL which is set in the config, the default one for local
321+
development is set to `http://localhost:8000/`. You can start a mock server following the next steps:
322+
323+
- `git clone https://github.com/RedHatInsights/insights-operator-gathering-conditions.git`
324+
- `cd insights-operator-gathering-conditions/`
325+
- `./build.sh`
326+
- `python3 -m http.server --directory build/`
316327

317328
# Contributing
318329

config/local.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ leaderElection:
55
interval: "5m"
66
storagePath: /tmp/insights-operator
77
endpoint: http://[::1]:8081
8+
conditionalGathererEndpoint: http://localhost:8000/
89
impersonate: system:serviceaccount:openshift-insights:gather
910
gather:
1011
- ALL

config/pod.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ leaderElection:
55
interval: "2h"
66
storagePath: /var/lib/insights-operator
77
endpoint: https://cloud.redhat.com/api/ingress/v1/upload
8+
conditionalGathererEndpoint: http://localhost:8000/
89
impersonate: system:serviceaccount:openshift-insights:gather
910
pull_report:
1011
endpoint: https://cloud.redhat.com/api/insights-results-aggregator/v1/clusters/%s/report

pkg/config/config.go

+27-14
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import (
1111

1212
// Serialized defines the standard config for this operator.
1313
type Serialized struct {
14-
Report bool `json:"report"`
15-
StoragePath string `json:"storagePath"`
16-
Interval string `json:"interval"`
17-
Endpoint string `json:"endpoint"`
18-
PullReport struct {
14+
Report bool `json:"report"`
15+
StoragePath string `json:"storagePath"`
16+
Interval string `json:"interval"`
17+
Endpoint string `json:"endpoint"`
18+
ConditionalGathererEndpoint string `json:"conditionalGathererEndpoint"`
19+
PullReport struct {
1920
Endpoint string `json:"endpoint"`
2021
Delay string `json:"delay"`
2122
Timeout string `json:"timeout"`
@@ -33,15 +34,16 @@ type Serialized struct {
3334

3435
// Controller defines the standard config for this operator.
3536
type Controller struct {
36-
Report bool
37-
StoragePath string
38-
Interval time.Duration
39-
Endpoint string
40-
ReportEndpoint string
41-
ReportPullingDelay time.Duration
42-
ReportMinRetryTime time.Duration
43-
ReportPullingTimeout time.Duration
44-
Impersonate string
37+
Report bool
38+
StoragePath string
39+
Interval time.Duration
40+
Endpoint string
41+
ConditionalGathererEndpoint string `json:"conditionalGathererEndpoint"`
42+
ReportEndpoint string
43+
ReportPullingDelay time.Duration
44+
ReportMinRetryTime time.Duration
45+
ReportPullingTimeout time.Duration
46+
Impersonate string
4547
// list of gathering functions to enable
4648
// if there's a string "ALL", we enable everything
4749
// otherwise, each string should consist of 2 parts:
@@ -84,6 +86,7 @@ type Converter func(s *Serialized, cfg *Controller) (*Controller, error)
8486
func (c *Controller) ToString() string {
8587
return fmt.Sprintf("enabled=%t "+
8688
"endpoint=%s "+
89+
"conditional_gatherer_endpoint=%s "+
8790
"interval=%s "+
8891
"username=%t "+
8992
"token=%t "+
@@ -93,6 +96,7 @@ func (c *Controller) ToString() string {
9396
"pollingTimeout=%s",
9497
c.Report,
9598
c.Endpoint,
99+
c.ConditionalGathererEndpoint,
96100
c.Interval,
97101
len(c.Username) > 0,
98102
len(c.Token) > 0,
@@ -106,6 +110,7 @@ func (c *Controller) MergeWith(cfg *Controller) {
106110
c.mergeCredentials(cfg)
107111
c.mergeInterval(cfg)
108112
c.mergeEndpoint(cfg)
113+
c.mergeConditionalGathererEndpoint(cfg)
109114
c.mergeReport(cfg)
110115
c.mergeOCM(cfg)
111116
c.mergeHTTP(cfg)
@@ -122,6 +127,12 @@ func (c *Controller) mergeEndpoint(cfg *Controller) {
122127
}
123128
}
124129

130+
func (c *Controller) mergeConditionalGathererEndpoint(cfg *Controller) {
131+
if len(cfg.ConditionalGathererEndpoint) > 0 {
132+
c.ConditionalGathererEndpoint = cfg.ConditionalGathererEndpoint
133+
}
134+
}
135+
125136
func (c *Controller) mergeReport(cfg *Controller) {
126137
if len(cfg.ReportEndpoint) > 0 {
127138
c.ReportEndpoint = cfg.ReportEndpoint
@@ -168,6 +179,7 @@ func ToController(s *Serialized, cfg *Controller) (*Controller, error) { // noli
168179
cfg.Report = s.Report
169180
cfg.StoragePath = s.StoragePath
170181
cfg.Endpoint = s.Endpoint
182+
cfg.ConditionalGathererEndpoint = s.ConditionalGathererEndpoint
171183
cfg.Impersonate = s.Impersonate
172184
cfg.Gather = s.Gather
173185
cfg.EnableGlobalObfuscation = s.EnableGlobalObfuscation
@@ -254,6 +266,7 @@ func ToDisconnectedController(s *Serialized, cfg *Controller) (*Controller, erro
254266
cfg.Impersonate = s.Impersonate
255267
cfg.Gather = s.Gather
256268
cfg.EnableGlobalObfuscation = s.EnableGlobalObfuscation
269+
cfg.ConditionalGathererEndpoint = s.ConditionalGathererEndpoint
257270

258271
if len(s.Interval) > 0 {
259272
d, err := time.ParseDuration(s.Interval)

pkg/config/configobserver/config.go

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func LoadConfigFromSecret(secret *v1.Secret) (config.Controller, error) {
2626

2727
cfg.loadCredentials(secret.Data)
2828
cfg.loadEndpoint(secret.Data)
29+
cfg.loadConditionalGathererEndpoint(secret.Data)
2930
cfg.loadHTTP(secret.Data)
3031
cfg.loadReport(secret.Data)
3132
cfg.loadOCM(secret.Data)
@@ -64,6 +65,12 @@ func (c *Config) loadEndpoint(data map[string][]byte) {
6465
}
6566
}
6667

68+
func (c *Config) loadConditionalGathererEndpoint(data map[string][]byte) {
69+
if endpoint, ok := data["conditionalGathererEndpoint"]; ok {
70+
c.ConditionalGathererEndpoint = string(endpoint)
71+
}
72+
}
73+
6774
func (c *Config) loadHTTP(data map[string][]byte) {
6875
if httpProxy, ok := data["httpProxy"]; ok {
6976
c.HTTPConfig.HTTPProxy = string(httpProxy)

pkg/gather/gather.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func CreateAllGatherers(
6161
anonymizer, controller.Interval,
6262
)
6363
workloadsGatherer := workloads.New(gatherProtoKubeConfig)
64-
conditionalGatherer := conditional.New(gatherProtoKubeConfig, metricsGatherKubeConfig, gatherKubeConfig)
64+
conditionalGatherer := conditional.New(gatherProtoKubeConfig, metricsGatherKubeConfig, gatherKubeConfig, controller)
6565

6666
return []gatherers.Interface{clusterConfigGatherer, workloadsGatherer, conditionalGatherer}
6767
}
@@ -100,7 +100,7 @@ func CollectAndRecordGatherer(
100100
gathererName, result.FunctionName, err,
101101
)
102102

103-
errs = append(errs, fmt.Errorf(errStr))
103+
errs = append(errs, fmt.Errorf("%v", errStr))
104104
}
105105
recordedRecs := 0
106106
for _, r := range result.Records {

pkg/gatherers/common/constants.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package common
22

3+
import "time"
4+
35
const (
46
// ImageConfigQPS is the maximum qps for image client
57
ImageConfigQPS = 10
68
// ImageConfigBurst is the maximum burst for image client
7-
ImageConfigBurst = 10
9+
ImageConfigBurst = 10
10+
ConditionalGathererHTTPRequestTimeout = time.Minute
811
)

0 commit comments

Comments
 (0)