Skip to content

Commit 0e8dec4

Browse files
Change datatypes for annotation2 and hopannotation2 (#1109)
* Rename annotation2 schema & parser * Rename hopannotation2 parser & schema
1 parent 163dadf commit 0e8dec4

20 files changed

+157
-154
lines changed

cmd/generate_schema_docs/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ func main() {
150150
flagx.ArgsFromEnv(flag.CommandLine)
151151

152152
generators := []schemaGenerator{
153-
&schema.AnnotationRow{},
154-
&schema.HopAnnotation1Row{},
153+
&schema.Annotation2Row{},
154+
&schema.HopAnnotation2Row{},
155155
&schema.NDT5ResultRowV2{},
156156
&schema.NDT7ResultRow{},
157157
&schema.TCPInfoRow{},

cmd/generate_schema_docs/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func Test_main(t *testing.T) {
3737
files := [4]string{
3838
"schema_ndt5resultrowv2.md",
3939
"schema_pcaprow.md",
40-
"schema_hopannotation1row.md",
40+
"schema_hopannotation2row.md",
4141
"schema_scamper1row.md",
4242
}
4343

cmd/update-schema/update.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ func CreateOrUpdateNDT7ResultRow(project string, dataset string, table string) e
8080
}
8181

8282
func CreateOrUpdateAnnotationRow(project string, dataset string, table string) error {
83-
row := schema.AnnotationRow{}
83+
row := schema.Annotation2Row{}
8484
schema, err := row.Schema()
85-
rtx.Must(err, "Annotation.Schema")
85+
rtx.Must(err, "Annotation2.Schema")
8686
return CreateOrUpdate(schema, project, dataset, table, "Date")
8787
}
8888

@@ -100,10 +100,10 @@ func CreateOrUpdatePCAPRow(project string, dataset string, table string) error {
100100
return CreateOrUpdate(schema, project, dataset, table, "Date")
101101
}
102102

103-
func CreateOrUpdateHopAnnotation1Row(project string, dataset string, table string) error {
104-
row := schema.HopAnnotation1Row{}
103+
func CreateOrUpdateHopAnnotation2Row(project string, dataset string, table string) error {
104+
row := schema.HopAnnotation2Row{}
105105
schema, err := row.Schema()
106-
rtx.Must(err, "HopAnnotation1Row.Schema")
106+
rtx.Must(err, "HopAnnotation2Row.Schema")
107107
return CreateOrUpdate(schema, project, dataset, table, "Date")
108108
}
109109

@@ -216,10 +216,10 @@ func updateStandardTables(project string) int {
216216
errCount++
217217
}
218218

219-
if err := CreateOrUpdateAnnotationRow(project, "tmp_ndt", "annotation"); err != nil {
219+
if err := CreateOrUpdateAnnotationRow(project, "tmp_ndt", "annotation2"); err != nil {
220220
errCount++
221221
}
222-
if err := CreateOrUpdateAnnotationRow(project, "raw_ndt", "annotation"); err != nil {
222+
if err := CreateOrUpdateAnnotationRow(project, "raw_ndt", "annotation2"); err != nil {
223223
errCount++
224224
}
225225

@@ -230,10 +230,10 @@ func updateStandardTables(project string) int {
230230
errCount++
231231
}
232232

233-
if err := CreateOrUpdateHopAnnotation1Row(project, "tmp_ndt", "hopannotation1"); err != nil {
233+
if err := CreateOrUpdateHopAnnotation2Row(project, "tmp_ndt", "hopannotation2"); err != nil {
234234
errCount++
235235
}
236-
if err := CreateOrUpdateHopAnnotation1Row(project, "raw_ndt", "hopannotation1"); err != nil {
236+
if err := CreateOrUpdateHopAnnotation2Row(project, "raw_ndt", "hopannotation2"); err != nil {
237237
errCount++
238238
}
239239

@@ -361,11 +361,11 @@ func main() {
361361
errCount++
362362
}
363363

364-
case "annotation":
365-
if err := CreateOrUpdateAnnotationRow(*project, "tmp_ndt", "annotation"); err != nil {
364+
case "annotation2":
365+
if err := CreateOrUpdateAnnotationRow(*project, "tmp_ndt", "annotation2"); err != nil {
366366
errCount++
367367
}
368-
if err := CreateOrUpdateAnnotationRow(*project, "raw_ndt", "annotation"); err != nil {
368+
if err := CreateOrUpdateAnnotationRow(*project, "raw_ndt", "annotation2"); err != nil {
369369
errCount++
370370
}
371371

@@ -385,11 +385,11 @@ func main() {
385385
errCount++
386386
}
387387

388-
case "hopannotation1":
389-
if err := CreateOrUpdateHopAnnotation1Row(*project, "tmp_ndt", "hopannotation1"); err != nil {
388+
case "hopannotation2":
389+
if err := CreateOrUpdateHopAnnotation2Row(*project, "tmp_ndt", "hopannotation2"); err != nil {
390390
errCount++
391391
}
392-
if err := CreateOrUpdateHopAnnotation1Row(*project, "raw_ndt", "hopannotation1"); err != nil {
392+
if err := CreateOrUpdateHopAnnotation2Row(*project, "raw_ndt", "hopannotation2"); err != nil {
393393
errCount++
394394
}
395395

etl/globals.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ func (dt DataType) BQBufferSize() int {
251251
// These constants enumerate the different data types.
252252
// TODO - use camelcase.
253253
const (
254-
ANNOTATION = DataType("annotation")
255-
HOPANNOTATION1 = DataType("hopannotation1")
254+
ANNOTATION2 = DataType("annotation2")
255+
HOPANNOTATION2 = DataType("hopannotation2")
256256
NDT = DataType("ndt")
257257
NDT5 = DataType("ndt5")
258258
NDT7 = DataType("ndt7")
@@ -270,8 +270,8 @@ var (
270270
// DirToDataType maps from gs:// subdirectory to data type.
271271
// TODO - this should be loaded from a config.
272272
dirToDataType = map[string]DataType{
273-
"annotation": ANNOTATION,
274-
"hopannotation1": HOPANNOTATION1,
273+
"annotation2": ANNOTATION2,
274+
"hopannotation2": HOPANNOTATION2,
275275
"ndt": NDT,
276276
"ndt5": NDT5,
277277
"ndt7": NDT7,
@@ -287,8 +287,8 @@ var (
287287
// DataTypeToTable maps from data type to BigQuery table name.
288288
// TODO - this should be loaded from a config.
289289
dataTypeToTable = map[DataType]string{
290-
ANNOTATION: "annotation",
291-
HOPANNOTATION1: "hopannotation1",
290+
ANNOTATION2: "annotation2",
291+
HOPANNOTATION2: "hopannotation2",
292292
NDT: "ndt",
293293
SS: "sidestream",
294294
PCAP: "pcap",
@@ -307,8 +307,8 @@ var (
307307
// as everything is written to gcs files, and the gcs library does it’s own buffering.
308308
// TODO - this should be loaded from a config
309309
dataTypeToBQBufferSize = map[DataType]int{
310-
ANNOTATION: 400, // around 1k each.
311-
HOPANNOTATION1: 200,
310+
ANNOTATION2: 400, // around 1k each.
311+
HOPANNOTATION2: 200,
312312
NDT: 10,
313313
NDT_OMIT_DELTAS: 50,
314314
TCPINFO: 5,

etl/globals_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,13 @@ func TestValidateTestPath(t *testing.T) {
138138
},
139139
},
140140
{
141-
name: "thirdparty-annotation",
142-
path: `gs://archive-mlab-sandbox/ndt/annotation/2019/08/14/20211107T143735.458956Z-annotation-third-party-ndt.tgz`,
143-
wantType: etl.ANNOTATION,
141+
name: "thirdparty-annotation2",
142+
path: `gs://archive-mlab-sandbox/ndt/annotation2/2019/08/14/20211107T143735.458956Z-annotation2-third-party-ndt.tgz`,
143+
wantType: etl.ANNOTATION2,
144144
want: etl.DataPath{
145-
`gs://archive-mlab-sandbox/ndt/annotation/2019/08/14/20211107T143735.458956Z-annotation-third-party-ndt.tgz`,
146-
`ndt/annotation/2019/08/14/20211107T143735.458956Z-annotation-third-party-ndt.tgz`,
147-
`archive-mlab-sandbox`, "ndt", "annotation", "2019/08/14", "20211107", "143735.458956", "annotation", "third", "party", "ndt", "", "", ".tgz",
145+
`gs://archive-mlab-sandbox/ndt/annotation2/2019/08/14/20211107T143735.458956Z-annotation2-third-party-ndt.tgz`,
146+
`ndt/annotation2/2019/08/14/20211107T143735.458956Z-annotation2-third-party-ndt.tgz`,
147+
`archive-mlab-sandbox`, "ndt", "annotation2", "2019/08/14", "20211107", "143735.458956", "annotation2", "third", "party", "ndt", "", "", ".tgz",
148148
},
149149
},
150150
}
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ import (
1717
)
1818

1919
//=====================================================================================
20-
// Annotation Parser
20+
// Annotation2 Parser
2121
//=====================================================================================
2222

23-
// AnnotationParser parses the annotation datatype from the uuid-annotator.
24-
type AnnotationParser struct {
23+
// Annotation2Parser parses the annotation datatype from the uuid-annotator.
24+
type Annotation2Parser struct {
2525
*row.Base
2626
table string
2727
suffix string
2828
}
2929

30-
// NewAnnotationParser creates a new parser for annotation data.
31-
func NewAnnotationParser(sink row.Sink, label, suffix string) etl.Parser {
32-
bufSize := etl.ANNOTATION.BQBufferSize()
33-
return &AnnotationParser{
30+
// NewAnnotation2Parser creates a new parser for annotation data.
31+
func NewAnnotation2Parser(sink row.Sink, label, suffix string) etl.Parser {
32+
bufSize := etl.ANNOTATION2.BQBufferSize()
33+
return &Annotation2Parser{
3434
Base: row.NewBase(label, sink, bufSize),
3535
table: label,
3636
suffix: suffix,
@@ -40,7 +40,7 @@ func NewAnnotationParser(sink row.Sink, label, suffix string) etl.Parser {
4040
// TaskError returns non-nil if the task had enough failures to justify
4141
// recording the entire task as in error. For now, this is any failure
4242
// rate exceeding 10%.
43-
func (ap *AnnotationParser) TaskError() error {
43+
func (ap *Annotation2Parser) TaskError() error {
4444
stats := ap.GetStats()
4545
if stats.Total() < 10*stats.Failed {
4646
log.Printf("Warning: high row commit errors (more than 10%%): %d failed of %d accepted\n",
@@ -51,20 +51,20 @@ func (ap *AnnotationParser) TaskError() error {
5151
}
5252

5353
// IsParsable returns the canonical test type and whether to parse data.
54-
func (ap *AnnotationParser) IsParsable(testName string, data []byte) (string, bool) {
54+
func (ap *Annotation2Parser) IsParsable(testName string, data []byte) (string, bool) {
5555
// Files look like: "<UUID>.json"
5656
if strings.HasSuffix(testName, "json") {
57-
return "annotation", true
57+
return "annotation2", true
5858
}
5959
return "unknown", false
6060
}
6161

62-
// ParseAndInsert decodes the data.Annotation JSON and inserts it into BQ.
63-
func (ap *AnnotationParser) ParseAndInsert(meta map[string]bigquery.Value, testName string, test []byte) error {
64-
metrics.WorkerState.WithLabelValues(ap.TableName(), "annotation").Inc()
65-
defer metrics.WorkerState.WithLabelValues(ap.TableName(), "annotation").Dec()
62+
// ParseAndInsert decodes the data.Annotation2 JSON and inserts it into BQ.
63+
func (ap *Annotation2Parser) ParseAndInsert(meta map[string]bigquery.Value, testName string, test []byte) error {
64+
metrics.WorkerState.WithLabelValues(ap.TableName(), "annotation2").Inc()
65+
defer metrics.WorkerState.WithLabelValues(ap.TableName(), "annotation2").Dec()
6666

67-
row := schema.AnnotationRow{
67+
row := schema.Annotation2Row{
6868
Parser: schema.ParseInfo{
6969
Version: Version(),
7070
Time: time.Now(),
@@ -79,7 +79,7 @@ func (ap *AnnotationParser) ParseAndInsert(meta map[string]bigquery.Value, testN
7979
err := json.Unmarshal(test, &raw)
8080
if err != nil {
8181
log.Println(err)
82-
metrics.TestTotal.WithLabelValues(ap.TableName(), "annotation", "decode-location-error").Inc()
82+
metrics.TestTotal.WithLabelValues(ap.TableName(), "annotation2", "decode-location-error").Inc()
8383
return err
8484
}
8585

@@ -116,41 +116,41 @@ func (ap *AnnotationParser) ParseAndInsert(meta map[string]bigquery.Value, testN
116116
}
117117

118118
// Count successful inserts.
119-
metrics.TestTotal.WithLabelValues(ap.TableName(), "annotation", "ok").Inc()
119+
metrics.TestTotal.WithLabelValues(ap.TableName(), "annotation2", "ok").Inc()
120120
return nil
121121
}
122122

123123
// NB: These functions are also required to complete the etl.Parser interface.
124124
// For Annotation, we just forward the calls to the Inserter.
125125

126-
func (ap *AnnotationParser) Flush() error {
126+
func (ap *Annotation2Parser) Flush() error {
127127
return ap.Base.Flush()
128128
}
129129

130-
func (ap *AnnotationParser) TableName() string {
130+
func (ap *Annotation2Parser) TableName() string {
131131
return ap.table
132132
}
133133

134-
func (ap *AnnotationParser) FullTableName() string {
134+
func (ap *Annotation2Parser) FullTableName() string {
135135
return ap.table + ap.suffix
136136
}
137137

138138
// RowsInBuffer returns the count of rows currently in the buffer.
139-
func (ap *AnnotationParser) RowsInBuffer() int {
139+
func (ap *Annotation2Parser) RowsInBuffer() int {
140140
return ap.GetStats().Pending
141141
}
142142

143143
// Committed returns the count of rows successfully committed to BQ.
144-
func (ap *AnnotationParser) Committed() int {
144+
func (ap *Annotation2Parser) Committed() int {
145145
return ap.GetStats().Committed
146146
}
147147

148148
// Accepted returns the count of all rows received through InsertRow(s)
149-
func (ap *AnnotationParser) Accepted() int {
149+
func (ap *Annotation2Parser) Accepted() int {
150150
return ap.GetStats().Total()
151151
}
152152

153153
// Failed returns the count of all rows that could not be committed.
154-
func (ap *AnnotationParser) Failed() int {
154+
func (ap *Annotation2Parser) Failed() int {
155155
return ap.GetStats().Failed
156156
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/m-lab/go/rtx"
1414
)
1515

16-
func TestAnnotationParser_ParseAndInsert(t *testing.T) {
16+
func TestAnnotation2Parser_ParseAndInsert(t *testing.T) {
1717
tests := []struct {
1818
name string
1919
file string
@@ -36,9 +36,9 @@ func TestAnnotationParser_ParseAndInsert(t *testing.T) {
3636
for _, tt := range tests {
3737
t.Run(tt.name, func(t *testing.T) {
3838
ins := newInMemorySink()
39-
n := parser.NewAnnotationParser(ins, "test", "_suffix")
39+
n := parser.NewAnnotation2Parser(ins, "test", "_suffix")
4040

41-
data, err := ioutil.ReadFile("testdata/Annotation/" + tt.file)
41+
data, err := ioutil.ReadFile("testdata/Annotation2/" + tt.file)
4242
rtx.Must(err, "failed to read test file")
4343

4444
if _, ok := n.IsParsable(tt.file, data); !ok {
@@ -51,12 +51,12 @@ func TestAnnotationParser_ParseAndInsert(t *testing.T) {
5151
}
5252

5353
if err := n.ParseAndInsert(meta, tt.file, data); (err != nil) != tt.wantErr {
54-
t.Errorf("AnnotationParser.ParseAndInsert() error = %v, wantErr %v", err, tt.wantErr)
54+
t.Errorf("Annotation2Parser.ParseAndInsert() error = %v, wantErr %v", err, tt.wantErr)
5555
}
5656

5757
if n.Accepted() == 1 {
5858
n.Flush()
59-
row := ins.data[0].(*schema.AnnotationRow)
59+
row := ins.data[0].(*schema.Annotation2Row)
6060

6161
expPI := schema.ParseInfo{
6262
Version: "https://github.com/m-lab/etl/tree/foobar",
@@ -68,14 +68,14 @@ func TestAnnotationParser_ParseAndInsert(t *testing.T) {
6868
}
6969

7070
if diff := deep.Equal(row.Parser, expPI); diff != nil {
71-
t.Errorf("AnnotationParser.ParseAndInsert() different summary: %s", strings.Join(diff, "\n"))
71+
t.Errorf("Annotation2Parser.ParseAndInsert() different summary: %s", strings.Join(diff, "\n"))
7272
}
7373

7474
if row.Client.Geo != nil && row.Client.Geo.Region != "" {
75-
t.Errorf("AnnotationParser.ParseAndInsert() did not clear Client.Geo.Region: %q", row.Client.Geo.Region)
75+
t.Errorf("Annotation2Parser.ParseAndInsert() did not clear Client.Geo.Region: %q", row.Client.Geo.Region)
7676
}
7777
if row.Server.Geo != nil && row.Server.Geo.Region != "" {
78-
t.Errorf("AnnotationParser.ParseAndInsert() did not clear Server.Geo.Region: %q", row.Server.Geo.Region)
78+
t.Errorf("Annotation2Parser.ParseAndInsert() did not clear Server.Geo.Region: %q", row.Server.Geo.Region)
7979
}
8080
}
8181
})

0 commit comments

Comments
 (0)