-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Makefile target to run against local Prometheus
Adds several Makefile targets, but mainly: - `make test-daemon` - `make clean-pod` Which can be used by developers to build&run host-metering locally within couple seconds againts a Prometheus server that is spawned in a podman container/pod. The run can be cleaned-up via. ``` make clean make clean-pod ``` `README.md` is updated to reflect this + several basic stuff that were missing. Signed-off-by: Petr Vobornik <[email protected]>
- Loading branch information
Showing
7 changed files
with
199 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,84 @@ | ||
# Host Metering | ||
|
||
Host metering client. | ||
|
||
## Usage | ||
|
||
``` | ||
$ host-metering daemon | ||
``` | ||
|
||
Or if run from RPMs as a service: | ||
|
||
``` | ||
# yum install host-metering | ||
# systemctl enable host-metering | ||
# systemctl start host-metering | ||
``` | ||
|
||
See output/log: | ||
|
||
``` | ||
# journalctl -feu host-metering | ||
``` | ||
|
||
## RPM repository | ||
|
||
RPM builds of `main` branch are available at COPR: https://copr.fedorainfracloud.org/coprs/pvoborni/host-metering/ | ||
|
||
## Build | ||
|
||
``` | ||
$ go build | ||
``` | ||
|
||
rpms via mock: | ||
|
||
``` | ||
$ make mock # EPEL 7 | ||
$ make mock-8 # CentOS Stream 8 | ||
$ make mock-9 # CentOS Stream 9 | ||
``` | ||
|
||
rpms directly via `rpmbuild` | ||
|
||
``` | ||
$ make rpm | ||
``` | ||
|
||
## Testing | ||
|
||
### Unit tests | ||
|
||
To run go unit test: | ||
``` | ||
$ make test | ||
``` | ||
|
||
### Local run / development | ||
|
||
``` | ||
$ make test-daemon | ||
``` | ||
|
||
It will run `host-metering` with: | ||
* mocked `subscriptin-manager` | ||
* test configuration file that is lowering intervals and using the following: | ||
* test certificate | ||
* custom path for metrics WAL | ||
* Prometheus server started in a podman container | ||
|
||
Query Prometheus, e.g., via command: | ||
|
||
``` | ||
$ curl 'http://localhost:9090/api/v1/query?query=system_cpu_logical_count' | jq | ||
``` | ||
|
||
Or visit the Prometheus Web UI at http://localhost:9090/graph?g0.expr=system_cpu_logical_count&g0.tab=0&g0.range_input=1m | ||
|
||
### Clean-up | ||
|
||
``` | ||
$ make clean # clean build&test files | ||
$ make clean-pod # destroy podman pod | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
# Execute this script in the directory with test-cert.cnf | ||
# Purpose: Create a self-signed certificate for testing | ||
|
||
openssl genrsa -out test-cert.key | ||
|
||
# To create a CSR for submitting to CA | ||
# openssl req -new -key test-cert.key -out test-cert.csr -config test-cert.cnf | ||
|
||
# Create a self-signed certificate | ||
openssl req -x509 -new -key test-cert.key -out test-cert.crt -config test-cert.cnf | ||
|
||
# Show the certificate | ||
openssl x509 -in test-cert.crt -text -noout |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Test host-metering configuration file which writes to a local prometheus | ||
# and uses a test certificate and key. | ||
|
||
# E.g. could be used as: | ||
# ./host-metering -config hack/host-metering.conf daemon | ||
|
||
[host-metering] | ||
write_url=http://localhost:9090/api/v1/write | ||
write_interval_sec=5 | ||
host_cert_path=./hack/test-cert.crt | ||
host_cert_key_path=./hack/test-cert.key | ||
collect_interval_sec=0 | ||
label_refresh_interval_sec=10 | ||
write_retry_attempts=4 | ||
write_retry_interval_sec=2 | ||
metrics_wal_path=./hack/cpumetrics | ||
log_level=DEBUG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[req] | ||
prompt = no | ||
req_extensions = req_ext | ||
distinguished_name = dn | ||
|
||
[ dn ] | ||
C=US | ||
ST=North Carolina | ||
L=Raleigh | ||
O=Milton | ||
OU=Information Technology | ||
emailAddress[email protected] | ||
CN = test-host.host-metering.test | ||
|
||
[ req_ext ] | ||
subjectAltName = DNS:test-host.host-metering.test |