Skip to content

Commit 33973ec

Browse files
committed
RHINENG-16453: gather table sizes from all used schemas, not only public
1 parent 29c09c3 commit 33973ec

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,14 @@ We cover a large part of the application functionality with tests; this requires
5858
podman-compose -f docker-compose.test.yml up --build --abort-on-container-exit
5959
~~~
6060

61-
### Run single test
62-
After running all test suit, 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.
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)
66+
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.
6369
~~~bash
6470
podman-compose -f docker-compose.test.yml up --build --no-start # build images
6571
podman-compose -f docker-compose.test.yml start db platform kafka # start containers

scripts/go_test.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ TEST_DIRS=${1:-./...}
99
# Run go test and colorize output (PASS - green, FAIL - red).
1010
# Set "-p 1" to run test sequentially to avoid parallel changes in testing database.
1111
gotestsum --format=standard-verbose -- -v -p 1 -coverprofile=coverage.txt -covermode=atomic $TEST_DIRS
12+
13+
# To run one test uncomment and modify last string and comment the one above:
14+
# go test -count=1 -v ./tasks/vmaas_sync -run TestTableSizes

tasks/vmaas_sync/metrics_db.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ func updateMetricsWithState(items []keyValue, metrics *prometheus.GaugeVec) {
5151

5252
func getTableSizes() []keyValue {
5353
var tableSizes []keyValue
54-
err := tasks.CancelableDB().Raw(`select tablename as key, pg_total_relation_size(quote_ident(tablename)) as value
55-
from (select * from pg_catalog.pg_tables where schemaname = 'public') t;`).
54+
err := tasks.CancelableDB().Raw(`select concat(schemaname, '.', tablename) as key,
55+
pg_total_relation_size(schemaname || '.' || tablename) as value
56+
from (select * from pg_catalog.pg_tables where schemaname in ('public', 'inventory', 'repack')) t;`).
5657
Find(&tableSizes).Error
5758
if err != nil {
5859
utils.LogError("err", err.Error(), "unable to get database table sizes")

tasks/vmaas_sync/metrics_db_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ func TestTableSizes(t *testing.T) {
1717
for _, item := range tableSizes {
1818
uniqueTables[item.Key] = true
1919
}
20-
assert.Equal(t, 213, len(tableSizes))
21-
assert.Equal(t, 213, len(uniqueTables))
22-
assert.True(t, uniqueTables["system_platform"]) // check whether table names were loaded
23-
assert.True(t, uniqueTables["package"])
24-
assert.True(t, uniqueTables["repo"])
20+
assert.Equal(t, 214, len(tableSizes))
21+
assert.Equal(t, 214, len(uniqueTables))
22+
assert.True(t, uniqueTables["public.system_platform"]) // check whether table names were loaded
23+
assert.True(t, uniqueTables["public.package"])
24+
assert.True(t, uniqueTables["public.repo"])
25+
assert.True(t, uniqueTables["inventory.hosts_v1_0"])
2526
}
2627

2728
func TestDatabaseSize(t *testing.T) {

0 commit comments

Comments
 (0)