Skip to content

Commit b799d1e

Browse files
author
Gregory Russell
committed
Add delta field counter
1 parent 358924e commit b799d1e

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

metrics/metrics.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func init() {
3434
prometheus.MustRegister(BigQueryInsert)
3535
prometheus.MustRegister(RowSizeHistogram)
3636
prometheus.MustRegister(DeltaNumFieldsHistogram)
37+
prometheus.MustRegister(SnapshotDeltaFieldCount)
3738
prometheus.MustRegister(EntryFieldCountHistogram)
3839
prometheus.MustRegister(DurationHistogram)
3940
prometheus.MustRegister(InsertionHistogram)
@@ -277,6 +278,20 @@ var (
277278
[]string{"table"},
278279
)
279280

281+
// Count of fields occurring in snapshot deltas.
282+
//
283+
// Provides metrics:
284+
// etl_ndt_snapshot_delta_field_count_count
285+
// Example usage:
286+
// metrics.SnapshotDeltaFieldCount.WithLabelValues(field.Name).Inc()
287+
SnapshotDeltaFieldCount = prometheus.NewCounterVec(
288+
prometheus.CounterOpts{
289+
Name: "etl_ndt_snapshot_delta_field_count_count",
290+
Help: "Count of fields occurring in snapshot deltas.",
291+
},
292+
[]string{"field"},
293+
)
294+
280295
// A histogram of snapshot delta field counts. It is intended primarily for
281296
// NDT. Typical is about 13, but max might be up to 120 or so.
282297
//

parser/ndt.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ func (n *NDTParser) processTest(test *fileInfoAndData, testType string) {
348348
}
349349

350350
func (n *NDTParser) getDeltas(snaplog *web100.SnapLog, testType string) ([]schema.Web100ValueMap, int) {
351+
// TODO - using make here causes insert error not detected by unit tests.
351352
deltas := []schema.Web100ValueMap{}
352353
deltaFieldCount := 0
353354
if NDTOmitDeltas {

web100/web100.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"io"
1010
"net"
1111
"strings"
12+
13+
"github.com/m-lab/etl/metrics"
1214
)
1315

1416
// NOTES:
@@ -553,7 +555,7 @@ func (snap *Snapshot) SnapshotValues(snapValues Saver) error {
553555
return nil
554556
}
555557

556-
// SnapshotValues writes changed values into the provided Saver.
558+
// SnapshotDeltas writes changed values into the provided Saver.
557559
func (snap *Snapshot) SnapshotDeltas(other *Snapshot, snapValues Saver) error {
558560
if snap.raw == nil {
559561
return errors.New("Empty/Invalid Snaplog")
@@ -568,6 +570,9 @@ func (snap *Snapshot) SnapshotDeltas(other *Snapshot, snapValues Saver) error {
568570
a := other.raw[field.Offset : field.Offset+field.Size]
569571
b := snap.raw[field.Offset : field.Offset+field.Size]
570572
if bytes.Compare(a, b) != 0 {
573+
if field.Name != "Duration" {
574+
metrics.SnapshotDeltaFieldCount.WithLabelValues(field.Name).Inc()
575+
}
571576
field.Save(b, snapValues)
572577
}
573578
}

0 commit comments

Comments
 (0)