Skip to content

Commit 12b4193

Browse files
committed
Log metrics
1 parent ed96103 commit 12b4193

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

pkg/store/sources.go

+16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/jmoiron/sqlx"
16+
log "github.com/sirupsen/logrus"
1617
)
1718

1819
// Source represents a source
@@ -119,6 +120,7 @@ func (db *psqlxStore) ProcessSourceExecution(s Source, sourceFindings []SourceFi
119120
if screated == nil {
120121
return Source{}, errors.New("unexpected nil pointer after source creation")
121122
}
123+
tInit := time.Now()
122124

123125
// Before updating the findings we have to lock the tx to prevent race
124126
// conditions from other possible concurrent sources being processed.
@@ -133,6 +135,7 @@ func (db *psqlxStore) ProcessSourceExecution(s Source, sourceFindings []SourceFi
133135
return Source{}, err
134136
}
135137

138+
tRelatedFamilies := time.Now()
136139
for _, sf := range sourceFindings {
137140
err = createSourceIssue(ctx, tx, sf.IssueID, screated.ID)
138141
if err != nil {
@@ -162,6 +165,7 @@ func (db *psqlxStore) ProcessSourceExecution(s Source, sourceFindings []SourceFi
162165
}
163166
}
164167

168+
tFindings := time.Now()
165169
findingStates, err := findingsStates(ctx, tx, db.logger, screated.SourceFamily)
166170
if err != nil {
167171
tx.Rollback()
@@ -174,6 +178,18 @@ func (db *psqlxStore) ProcessSourceExecution(s Source, sourceFindings []SourceFi
174178
return Source{}, err
175179
}
176180

181+
db.logger.WithFields(log.Fields{
182+
"msRelatedFamilies": tRelatedFamilies.Sub(tInit).Milliseconds(),
183+
"msFindings": tFindings.Sub(tRelatedFamilies).Milliseconds(),
184+
"msFindingStates": time.Since(tFindings).Milliseconds(),
185+
"msTotal": time.Since(tInit).Milliseconds(),
186+
"numFindingStates": len(findingStates),
187+
"numSourceFindings": len(sourceFindings),
188+
"target": s.Target,
189+
"check": s.Instance,
190+
"component": s.Component,
191+
}).Info("ProcessSourceExecution")
192+
177193
return *screated, tx.Commit()
178194
}
179195

0 commit comments

Comments
 (0)