Copyright 2020, 2021, 2022 Red Hat, Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
|
package storage_test
import (
"database/sql"
"fmt"
"testing"
"time"
"github.com/RedHatInsights/insights-operator-utils/tests/helpers"
"github.com/RedHatInsights/insights-results-aggregator-data/testdata"
"github.com/RedHatInsights/insights-results-aggregator/types"
"github.com/google/uuid"
"github.com/rs/zerolog"
"github.com/RedHatInsights/insights-results-aggregator/storage"
ira_helpers "github.com/RedHatInsights/insights-results-aggregator/tests/helpers"
)
var Report20Rules = types . ClusterReport ( `
{
"system": {
"metadata": {},
"hostname": null
},
"reports": [
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "` + testdata . ErrorKey1 + `",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "` + testdata . ErrorKey2 + `",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "ek3",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek4",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "ek5",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek6",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "ek7",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek8",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "ek9",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek10",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "ek11",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek12",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "ek13",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek14",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "ek15",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek16",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "ek17",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek18",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "ek19",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek20",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek200",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "ek21",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek22",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "ek23",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek24",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "ek25",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek26",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "ek27",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek28",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule1ID ) + `",
"key": "ek29",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule1ExtraData ) + `
},
{
"component": "` + string ( testdata . Rule2ID ) + `",
"key": "ek30",
"user_vote": 0,
"disabled": false,
"details": ` + helpers . ToJSONString ( testdata . Rule2ExtraData ) + `
}
],
"fingerprints": [],
"skips": [],
"info": []
}
` )
var exists = struct { } { }
type set struct {
content map [ string ] struct { }
}
|
Postgres queries are very verbose at DEBUG log level, so it's better
to silence them this way to make benchmark results easier to find.
|
zerolog . SetGlobalLevel ( zerolog . WarnLevel )
mockStorage , closer := ira_helpers . MustGetPostgresStorage ( b , false )
conn := storage . GetConnection ( mockStorage . ( * storage . OCPRecommendationsDBStorage ) )
_ , err := conn . Exec ( "DROP TABLE IF EXISTS recommendation;" )
helpers . FailOnError ( b , err )
_ , err = conn . Exec ( "DROP TABLE IF EXISTS report;" )
helpers . FailOnError ( b , err )
_ , err = conn . Exec ( "DROP TABLE IF EXISTS rule_hit;" )
helpers . FailOnError ( b , err )
_ , err = conn . Exec ( "CREATE TABLE recommendation (org_id INTEGER NOT NULL, cluster_id VARCHAR NOT NULL, rule_fqdn VARCHAR NOT NULL, error_key VARCHAR NOT NULL, PRIMARY KEY(cluster_id, rule_fqdn, error_key));" )
helpers . FailOnError ( b , err )
_ , err = conn . Exec ( "CREATE TABLE report (org_id INTEGER NOT NULL, cluster VARCHAR NOT NULL UNIQUE, report VARCHAR NOT NULL, reported_at TIMESTAMP, last_checked_at TIMESTAMP, kafka_offset BIGINT NOT NULL DEFAULT 0, PRIMARY KEY(org_id, cluster));" )
helpers . FailOnError ( b , err )
_ , err = conn . Exec ( "CREATE TABLE rule_hit (org_id INTEGER NOT NULL, cluster_id VARCHAR NOT NULL, rule_fqdn VARCHAR NOT NULL, error_key VARCHAR NOT NULL, template_data VARCHAR NOT NULL, PRIMARY KEY(cluster_id, org_id, rule_fqdn, error_key));" )
helpers . FailOnError ( b , err )
return mockStorage , conn , closer
}
func mustCleanupAfterRecommendationsBenchmark ( b * testing . B , conn * sql . DB , closer func ( ) ) {
_ , err := conn . Exec ( "DROP TABLE recommendation;" )
helpers . FailOnError ( b , err )
closer ( )
}
func mustCleanupAfterReportAndRecommendationsBenchmark ( b * testing . B , conn * sql . DB , closer func ( ) ) {
_ , err := conn . Exec ( "DROP TABLE recommendation;" )
helpers . FailOnError ( b , err )
_ , err = conn . Exec ( "DROP TABLE report;" )
helpers . FailOnError ( b , err )
_ , err = conn . Exec ( "DROP TABLE rule_hit;" )
helpers . FailOnError ( b , err )
closer ( )
}
|