Skip to content

Commit

Permalink
error-handle-changes-added
Browse files Browse the repository at this point in the history
  • Loading branch information
an1l4 committed Dec 5, 2023
1 parent 6815d55 commit 318eadb
Showing 1 changed file with 30 additions and 60 deletions.
90 changes: 30 additions & 60 deletions client/pkg/clickhouse/db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,12 @@ func (c *DBClient) InsertContainerEventAzure(pushEvent model.AzureContainerPushE

tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}

stmt, err := tx.Prepare(string(InsertAzureContainerPushEvent))
if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}

defer stmt.Close()
Expand Down Expand Up @@ -187,14 +185,12 @@ func (c *DBClient) InsertContainerEventAzure(pushEvent model.AzureContainerPushE
func (c *DBClient) InsertContainerEventQuay(pushEvent model.QuayImagePushPayload) {
tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}

stmt, err := tx.Prepare(string(InsertQuayContainerPushEvent))
if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}

defer stmt.Close()
Expand Down Expand Up @@ -240,14 +236,12 @@ func (c *DBClient) InsertContainerEventQuay(pushEvent model.QuayImagePushPayload
func (c *DBClient) InsertContainerEventJfrog(pushEvent model.JfrogContainerPushEventPayload) {
tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}

stmt, err := tx.Prepare(string(InsertJfrogContainerPushEvent))
if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}

defer stmt.Close()
Expand Down Expand Up @@ -293,13 +287,11 @@ func (c *DBClient) InsertContainerEventJfrog(pushEvent model.JfrogContainerPushE
func (c *DBClient) InsertRakeesMetrics(metrics model.RakeesMetrics) {
tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}
stmt, err := tx.Prepare(string(InsertRakees))
if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}

defer stmt.Close()
Expand All @@ -325,13 +317,11 @@ func (c *DBClient) InsertRakeesMetrics(metrics model.RakeesMetrics) {
func (c *DBClient) InsertKetallEvent(metrics model.Resource) {
tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}
stmt, err := tx.Prepare(string(InsertKetall))
if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}

defer stmt.Close()
Expand All @@ -356,13 +346,11 @@ func (c *DBClient) InsertKetallEvent(metrics model.Resource) {
func (c *DBClient) InsertOutdatedEvent(metrics model.CheckResultfinal) {
tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}
stmt, err := tx.Prepare(string(InsertOutdated))
if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}

defer stmt.Close()
Expand All @@ -389,13 +377,11 @@ func (c *DBClient) InsertOutdatedEvent(metrics model.CheckResultfinal) {
func (c *DBClient) InsertDeprecatedAPI(deprecatedAPI model.DeprecatedAPI) {
tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}
stmt, err := tx.Prepare(string(InsertDepricatedApi))
if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}

defer stmt.Close()
Expand Down Expand Up @@ -429,13 +415,11 @@ func (c *DBClient) InsertDeprecatedAPI(deprecatedAPI model.DeprecatedAPI) {
func (c *DBClient) InsertDeletedAPI(deletedAPI model.DeletedAPI) {
tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}
stmt, err := tx.Prepare(string(InsertDeletedApi))
if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}

defer stmt.Close()
Expand Down Expand Up @@ -470,13 +454,11 @@ func (c *DBClient) InsertDeletedAPI(deletedAPI model.DeletedAPI) {
func (c *DBClient) InsertKubvizEvent(metrics model.Metrics) {
tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}
stmt, err := tx.Prepare(string(InsertKubvizEvent))
if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}

defer stmt.Close()
Expand Down Expand Up @@ -539,13 +521,11 @@ func (c *DBClient) InsertContainerEvent(event string) {
func (c *DBClient) InsertKubeScoreMetrics(metrics model.KubeScoreRecommendations) {
tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}
stmt, err := tx.Prepare(InsertKubeScore)
if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}
defer stmt.Close()

Expand All @@ -571,13 +551,11 @@ func (c *DBClient) InsertTrivyMetrics(metrics model.Trivy) {
for _, vulnerability := range result.Vulnerabilities {
tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}
stmt, err := tx.Prepare(InsertTrivyVul)
if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}
if _, err := stmt.Exec(
metrics.ID,
Expand Down Expand Up @@ -608,13 +586,11 @@ func (c *DBClient) InsertTrivyMetrics(metrics model.Trivy) {
for _, misconfiguration := range result.Misconfigurations {
tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}
stmt, err := tx.Prepare(InsertTrivyMisconfig)
if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}

defer stmt.Close()
Expand Down Expand Up @@ -654,13 +630,11 @@ func (c *DBClient) InsertTrivyImageMetrics(metrics model.TrivyImage) {
for _, vulnerability := range result.Vulnerabilities {
tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}
stmt, err := tx.Prepare(InsertTrivyImage)
if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}

if _, err := stmt.Exec(
Expand Down Expand Up @@ -700,13 +674,11 @@ func (c *DBClient) InsertTrivySbomMetrics(metrics model.Sbom) {
if result.CycloneDX != nil {
tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}
stmt, err := tx.Prepare(InsertTrivySbom)
if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}

if _, err := stmt.Exec(
Expand Down Expand Up @@ -834,14 +806,12 @@ func (c *DBClient) RetrieveKubvizEvent() ([]model.DbEvent, error) {
func (c *DBClient) InsertContainerEventDockerHub(build model.DockerHubBuild) {
tx, err := c.conn.Begin()
if err != nil {
log.Printf("error beginning transaction: %v", err)
return
log.Fatalf("error beginning transaction, clickhouse connection not available: %v", err)
}
stmt, err := tx.Prepare(string(InsertDockerHubBuild))

if err != nil {
log.Printf("error preparing statement: %v", err)
return
log.Fatalf("error preparing statement: %v", err)
}
defer stmt.Close()

Expand Down

0 comments on commit 318eadb

Please sign in to comment.