Skip to content

Commit 77298ed

Browse files
committed
docs: fix and refactor README
1 parent 4da9d52 commit 77298ed

1 file changed

Lines changed: 81 additions & 76 deletions

File tree

README.md

Lines changed: 81 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,48 @@
33
[![Code Coverage](https://codecov.io/gh/RedHatInsights/patchman-engine/branch/master/graph/badge.svg)](https://codecov.io/gh/RedHatInsights/patchman-engine)
44

55
# patchman-engine
6-
System Patch Manager is one of the applications for [console.redhat.com](https://console.redhat.com). This application allows users to display and manage available patches for their registered systems. This code repo stores sources for the backend part of the application which provides the REST API to the frontend.
6+
System Patch Manager is one of the applications for [console.redhat.com](https://console.redhat.com). This application allows users to display and manage available patches for their registered systems. This code repo stores sources for the backend part of the application, which provides the REST API for the frontend.
77

8-
## Table of content
8+
## Table of contents
99
- [Architecture](docs/md/architecture.md)
1010
- [Database](docs/md/database.md)
1111
- [Development environment](#development-environment)
12-
- [Local running](#local-running)
13-
- [Local app requests](#local-app-requests)
14-
- [Tests running](#tests-running)
15-
- [OpenAPI docs](#openapi-docs)
12+
- [Running locally](#running-locally)
13+
- [Local app requests](#local-app-requests)
14+
- [Testing and debugging](#testing-and-debugging)
15+
- [OpenAPI docs](#openapi-docs)
1616
- [Control by private API](#control-by-private-api)
1717
- [VMaaS](#vmaas)
1818
- [Monitoring](#monitoring)
19-
- [Profiling] (#profiling)
19+
- [Profiling](#profiling)
2020

2121
## Development environment
22+
Ensure that you have Go and Podman installed.
2223

2324
### Running locally
24-
Uses `podman-compose` to deploy the individual project components and supporting containers, which simulate the CMSfR platform and database:
25+
Use `podman-compose` to deploy the individual project components and supporting containers that simulate the CMSfR platform and database:
2526
~~~bash
2627
podman-compose up --build # Build images if needed and start containers
2728
podman-compose down # Stop and remove containers
2829
~~~
2930

30-
Use `--profile monitoring` to run local `prometheus` and `grafana`, for example
31+
#### Run with monitoring
32+
Use `--profile monitoring` to run local `prometheus` and `grafana`, for example:
3133
~~~bash
3234
podman-compose --profile monitoring up
3335
~~~
34-
Grafana is accessible at `http://localhost:3000`, Prometheus at `http://localhost:9090`
36+
Grafana is available at <http://localhost:3000> and Prometheus at <http://localhost:9090>.
3537

38+
#### Run a component in the host OS
39+
Run a single component in the host OS while running the rest in podman-compose:
40+
~~~bash
41+
podman-compose stop evaluator_upload # stop a single component using podman-compose
42+
export $(xargs < conf/local.env)
43+
./scripts/entrypoint.sh evaluator # (or listener, or manager) run the component in the host OS
44+
~~~
3645

3746
### Local app requests
38-
When podman compose is running, you can test the app using dev shell scripts:
47+
When podman-compose is running, use dev shell scripts to test the app:
3948
~~~bash
4049
cd dev/scripts
4150
./systems_list.sh # show systems
@@ -44,94 +53,89 @@ cd dev/scripts
4453
./platform_upload.sh # simulate archive upload to trigger listener and evaluator_upload
4554
~~~
4655

47-
### Running in host OS
48-
Run single component in host OS, rest in podman-compose:
49-
~~~bash
50-
podman-compose stop evaluator_upload # stop single component running using podman-compose
51-
export $(xargs < conf/local.env)
52-
./scripts/entrypoint.sh evaluator # (or listener, or manager) run component in host OS
53-
~~~
56+
### Testing and debugging
57+
A large part of the application functionality is covered with tests; this requires running a test database and mocked services. All of this is encapsulated in the test configuration, which is run using podman-compose. It also includes static code analysis, database migration tests, and a Dockerfile check. It is used to check pull requests too.
5458

55-
### Running tests
56-
We cover a large part of the application functionality with tests; this requires also running a test database and mocked services. This is all encapsulated into the configuration runable using podman-compose command. It also includes static code analysis, database migration tests and dockerfiles checking. It's also used when checking pull requests for the repo.
59+
Use this command to run the whole test suite:
5760
~~~bash
5861
podman-compose -f docker-compose.test.yml up --build --abort-on-container-exit
5962
~~~
6063

61-
### Run single test or set of tests in containers
62-
- Open `./scripts/go_test.sh` file
63-
- Comment line that runs all tests
64-
- Uncomment and modify the last line to run one or a set of tests
65-
- Run the same command as for running all tests (from above)
64+
#### Run one or more tests instead
65+
1. Open `./scripts/go_test.sh` file.
66+
2. Comment out the line that runs all tests.
67+
3. Uncomment and modify the last line to specify one or a set of tests.
68+
4. Run the same command as for the whole suite (from above).
6669

67-
### Run single test locally
68-
After running all test suite, testing platform components are still running (kafka, platform, db). This is especially useful when fixing some test or adding a new one. You need to have golang installed.
70+
#### Run a single test locally
71+
After running the entire test suite (without `--abort-on-container-exit` flag), testing platform components (`kafka`, `platform`, `db`) are still up. This is especially useful when fixing a test or adding a new one.
6972
~~~bash
7073
podman-compose -f docker-compose.test.yml up --build --no-start # build images
7174
podman-compose -f docker-compose.test.yml run test ./scripts/go_test.sh './evaluator -run TestEvaluate' # run "TestEvaluate" test from "evaluator" component
7275
~~~
7376

74-
### Run tests in VS Code
75-
76-
Prerequisite is to have [Go Extension](https://marketplace.visualstudio.com/items?itemName=golang.Go)
77+
#### Run tests in VS Code
78+
A prerequisite is to have the [Go Extension](https://marketplace.visualstudio.com/items?itemName=golang.Go)
7779
installed.
7880

79-
To set it up copy the example settings from `.vscode/settings.example.json`:
80-
```
81+
To set things up, copy the example settings from `.vscode/settings.example.json`:
82+
~~~bash
8183
cp .vscode/settings.example.json .vscode/settings.json
82-
```
83-
84-
### Access to dev/test database
84+
~~~
8585

86-
When a podman compose (either dev or test one) is running, then the database can
87-
be access directly by executing
88-
```
86+
#### Access to the dev/test database
87+
While podman-compose (either dev or test) is running, execute the following to access the database directly:
88+
~~~bash
8989
podman exec -it db psql -d patchman -U admin
90-
```
90+
~~~
9191

92-
or locally using `psql` with:
93-
```
92+
or locally using `psql.sh`, as follows:
93+
~~~bash
9494
export $(cat conf/local.env conf/database_admin.env | xargs ) 2>/dev/null; ./dev/scripts/psql.sh
95-
```
95+
~~~
96+
97+
#### Kafka control
98+
Control and inspect the Kafka instance using:
99+
~~~bash
100+
podman-compose exec kafka bash # enter kafka component and run inside:
101+
/usr/bin/kafka-topics --list --bootstrap-server=kafka:9092 # show created topics
102+
103+
# list all messages sent to a topic
104+
/usr/bin/kafka-console-consumer --bootstrap-server=kafka:9092 --topic platform.inventory.events --from-beginning
105+
106+
# send debugging message to a topic
107+
echo '{"id":"00000000-0000-0000-0000-000000000002"}' | /usr/bin/kafka-console-producer --broker-list kafka:9092 --topic patchman.evaluator.upload
108+
~~~
96109

97110
### OpenAPI docs
98-
Our REST API is documented using OpenAPI v3. On a local instance it can be accessed on <http://localhost:8080/openapi/index.html>.
111+
The REST API is documented using OpenAPI v3. On a local instance, it can be accessed at <http://localhost:8080/openapi/index.html>.
99112

100-
To update/regenerate OpenAPI sources run:
113+
For the first time, ensure that you have `swaggo/swag` binary installed:
114+
~~~bash
115+
go get -u github.com/swaggo/swag/cmd/swag
116+
~~~
117+
118+
Run this command to update/regenerate OpenAPI source files:
101119
~~~bash
102-
go get -u github.com/swaggo/swag/cmd/swag # download binary to generate, do it first time only
103120
./scripts/generate_docs.sh
104121
~~~
105122

106123
## Control by private API
107-
There is a private API accessible only from inside of `vmaas_sync` container. It allows running component routines manually. In local environment it can be tested like this:
124+
There is a private API accessible only from the `vmaas_sync` container, which allows triggering component routines manually. In a local environment, test it like this:
108125
~~~bash
109-
podman exec -it patchman-engine_vmaas_sync_1 ./sync.sh # trigger advisories syncing event.
110-
podman exec -it patchman-engine_vmaas_sync_1 ./re-calc.sh # trigger systems recalculation event.
126+
podman exec -it patchman-engine_vmaas_sync_1 ./sync.sh # trigger advisories syncing event.
127+
podman exec -it patchman-engine_vmaas_sync_1 ./re-calc.sh # trigger systems recalculation event.
111128
podman exec -it patchman-engine_vmaas_sync_1 ./caches-check.sh # trigger account caches checking.
112129
~~~
113130

114131
## VMaaS
115-
This project uses [VMaaS](https://github.com/RedHatInsights/vmaas) for retrieving information about advisories, and resolving which advisories can be applied to which systems. For local development this repo contains VMaaS service mock as a part of platform mock allowing independent running of the service using podman-compose.
132+
This project uses [VMaaS](https://github.com/RedHatInsights/vmaas) for retrieving information about advisories and resolving which advisories can be applied to which systems. For local development, the platform mock contains a VMaaS service mock.
116133

117134
## Monitoring
118135
Each application component (except for the database) exposes metrics for [Prometheus](https://prometheus.io/)
119136
on `/metrics` endpoint (see [docker-compose.yml](docker-compose.yml) for ports). Runtime logs can be sent to Amazon
120137
CloudWatch if configuration environment variables are set (see [awscloudwatch.go](base/utils/awscloudwatch.go)).
121138

122-
## Kafka control
123-
Your can control and inspect def Kafka instance using:
124-
~~~bash
125-
docker-compose exec kafka bash # enter kafka component and run inside:
126-
/usr/bin/kafka-topics --list --bootstrap-server=kafka:9092 # show created topics
127-
128-
# list all messages send to a topic
129-
/usr/bin/kafka-console-consumer --bootstrap-server=kafka:9092 --topic platform.inventory.events --from-beginning
130-
131-
# send debugging message to a topic
132-
echo '{"id":"00000000-0000-0000-0000-000000000002"}' | /usr/bin/kafka-console-producer --broker-list kafka:9092 --topic patchman.evaluator.upload
133-
~~~
134-
135139
## Run SonarQube code analysis
136140
~~~bash
137141
export SONAR_HOST_URL=https://sonar-server
@@ -141,23 +145,24 @@ podman-compose -f dev/sonar/docker-compose.yml up --build
141145
~~~
142146

143147
## Update Grafana config map
144-
Copy Grafana board json config to the temporary file, e.g. `grafana.json` and run:
148+
Copy Grafana board JSON config to a temporary file (e.g. `grafana.json`) and run:
145149
~~~bash
146150
./scripts/grafana-json-to-yaml.sh grafana.json > ./dashboards/app-sre/grafana-dashboard-insights-patchman-engine-general.configmap.yaml
147151
~~~
148152

149153
## Profiling
150-
App can be profiled using [/net/http/pprof](https://pkg.go.dev/net/http/pprof). Profiler is exposed on app's private port.
154+
The app can be profiled using [/net/http/pprof](https://pkg.go.dev/net/http/pprof). Profiler is exposed on app's private port.
155+
151156
### Local development
152-
- set `ENABLE_PROFILE=true` in the `cont/common.env`
153-
- `docker-compose up --build`
154-
- `go tool pprof http://localhost:{port}/debug/pprof/{heap|profile|block|mutex}`
155-
available ports:
156-
- 9000 - manager
157-
- 9002 - listener
158-
- 9003 - evaluator-upload
159-
- 9004 - evaluator-recalc
160-
### Admin API
161-
- set `ENABLE_PROFILE_{container_name}=true` in the ClowdApp
162-
- download the profile file using internal api `/api/patch/admin/pprof/{manager|listener|evaluator_upload|evaluator_recalc}/{heap|profile|block|mutex|trace}`
163-
- `go tool pprof <saved.file>`
157+
1. Set `ENABLE_PROFILE=true` in the `conf/common.env`.
158+
2. Run `podman-compose up --build`.
159+
3. Run `go tool pprof http://localhost:{port}/debug/pprof/{heap|profile|block|mutex}` with:
160+
- `9000` - manager,
161+
- `9002` - listener,
162+
- `9003` - evaluator-upload, or
163+
- `9004` - evaluator-recalc.
164+
165+
### Using Admin API
166+
1. Set `ENABLE_PROFILE_{container_name}=true` in the ClowdApp.
167+
2. Download the profile file using internal API `/api/patch/admin/pprof/{manager|listener|evaluator_upload|evaluator_recalc}/{heap|profile|block|mutex|trace}`.
168+
3. Run `go tool pprof <saved.file>`.

0 commit comments

Comments
 (0)