From 35991711775d3532a201496a884ec7a7bfa19eb4 Mon Sep 17 00:00:00 2001 From: Vishnu Jayadevan Date: Wed, 13 Sep 2023 09:33:06 +0530 Subject: [PATCH] refactor: move eventlog to its own package --- eventlog/analysis.go | 36 ++++++++++++++++++++++++++++++++++++ utils.go | 30 ------------------------------ 2 files changed, 36 insertions(+), 30 deletions(-) create mode 100644 eventlog/analysis.go diff --git a/eventlog/analysis.go b/eventlog/analysis.go new file mode 100644 index 0000000..792e216 --- /dev/null +++ b/eventlog/analysis.go @@ -0,0 +1,36 @@ +package eventlog + +import ( + "fmt" + "strconv" + "time" +) + +var analysisEventsLogFmt = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%d\n" + +type AnalysisLogger struct { + RunID string + RunSerial string + CheckSequence string + Repository string + Shortcode string + CommitSHA string + IsFullRun bool + IsIDERun bool +} + +func (a *AnalysisLogger) Log(runType, stage string) { + fmt.Printf(analysisEventsLogFmt, + runType, + a.RunID, + a.RunSerial, + a.CheckSequence, + a.Shortcode, + a.Repository, + a.CommitSHA, + strconv.FormatBool(a.IsFullRun), + strconv.FormatBool(a.IsIDERun), + stage, + time.Now().Unix(), + ) +} diff --git a/utils.go b/utils.go index 9a9a779..83035b1 100644 --- a/utils.go +++ b/utils.go @@ -16,8 +16,6 @@ import ( "github.com/getsentry/sentry-go" ) -var analysisEventsLogFmt = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%d\n" - // Returns bearer token that is used to authenticate while // interacting with the k8s REST API // Utilized by janus and atlas. @@ -185,31 +183,3 @@ func TriggerDeploymentRestart(auth bool, podName, patchData, baseURL, tokenPath } return nil } - -// AnalysisEventsLog represents the struct that contains the fields -// that need to be logged for tracking analysis pipeline's performance. -type AnalysisEventsLog struct { - RunID string - RunSerial string - CheckSequence string - Repository string - Shortcode string - CommitSHA string - IsFullRun string -} - -// logAnalysisEventTimestamp logs the timestamp at various analysis stages. -func (a *AnalysisEventsLog) LogAnalysisEventTimestamp(runType, stage string) { - fmt.Printf(analysisEventsLogFmt, - runType, - a.RunID, - a.RunSerial, - a.CheckSequence, - a.Shortcode, - a.Repository, - a.CommitSHA, - a.IsFullRun, - stage, - time.Now().Unix(), - ) -}