Skip to content

Commit 933c2e4

Browse files
committed
added datetime to kubescore
1 parent 5171b21 commit 933c2e4

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

client/pkg/clickhouse/db_client.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,11 +438,15 @@ func (c *DBClient) InsertKubeScoreMetrics(metrics model.KubeScoreRecommendations
438438
stmt, _ = tx.Prepare(InsertKubeScore)
439439
)
440440
defer stmt.Close()
441+
442+
currentTime := time.Now().UTC()
443+
441444
if _, err := stmt.Exec(
442445
metrics.ID,
443446
metrics.Namespace,
444447
metrics.ClusterName,
445448
metrics.Recommendations,
449+
currentTime,
446450
); err != nil {
447451
log.Fatal(err)
448452
}

client/pkg/clickhouse/statements.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,15 @@ CREATE TABLE IF NOT EXISTS outdated_images (
9797
`
9898

9999
const kubescoreTable DBStatement = `
100-
CREATE TABLE IF NOT EXISTS kubescore (
101-
id UUID,
102-
namespace String,
103-
cluster_name String,
104-
recommendations String
105-
) engine=File(TabSeparated)
106-
`
100+
CREATE TABLE IF NOT EXISTS kubescore (
101+
id UUID,
102+
namespace String,
103+
cluster_name String,
104+
recommendations String,
105+
EventTime DateTime('UTC')
106+
) engine=File(TabSeparated)
107+
`
108+
107109
const trivyTableVul DBStatement = `
108110
CREATE TABLE IF NOT EXISTS trivy_vul (
109111
id UUID,
@@ -236,7 +238,7 @@ const InsertDeletedApi DBStatement = "INSERT INTO DeletedAPIs (ClusterName, Obje
236238
const InsertKubvizEvent DBStatement = "INSERT INTO events (ClusterName, Id, EventTime, OpType, Name, Namespace, Kind, Message, Reason, Host, Event, FirstTime, LastTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
237239
const clickhouseExperimental DBStatement = `SET allow_experimental_object_type=1;`
238240
const containerGithubTable DBStatement = `CREATE table IF NOT EXISTS container_github(event JSON) ENGINE = MergeTree ORDER BY tuple();`
239-
const InsertKubeScore string = "INSERT INTO kubescore (id, namespace, cluster_name, recommendations) VALUES (?, ?, ?, ?)"
241+
const InsertKubeScore string = "INSERT INTO kubescore (id, namespace, cluster_name, recommendations, EventTime) VALUES (?, ?, ?, ?, ?)"
240242
const InsertTrivyVul string = "INSERT INTO trivy_vul (id, cluster_name, namespace, kind, name, vul_id, vul_vendor_ids, vul_pkg_id, vul_pkg_name, vul_pkg_path, vul_installed_version, vul_fixed_version, vul_title, vul_severity, vul_published_date, vul_last_modified_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?. ?)"
241243
const InsertTrivyImage string = "INSERT INTO trivyimage (id, cluster_name, artifact_name, vul_id, vul_pkg_id, vul_pkg_name, vul_installed_version, vul_fixed_version, vul_title, vul_severity, vul_published_date, vul_last_modified_date) VALUES ( ?, ?,?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
242244
const InsertTrivyMisconfig string = "INSERT INTO trivy_misconfig (id, cluster_name, namespace, kind, name, misconfig_id, misconfig_avdid, misconfig_type, misconfig_title, misconfig_desc, misconfig_msg, misconfig_query, misconfig_resolution, misconfig_severity, misconfig_status, EventTime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

0 commit comments

Comments
 (0)