@@ -27,6 +27,10 @@ import (
27
27
var (
28
28
// Metrics on a stream are tagged with the stream ID.
29
29
keyStream = tag .MustNewKey ("streamID" )
30
+
31
+ // We allow users to annotate streams with a data origin for monitoring purposes.
32
+ // See the WithDataOrigin writer option for providing this.
33
+ keyDataOrigin = tag .MustNewKey ("dataOrigin" )
30
34
)
31
35
32
36
const statsPrefix = "cloud.google.com/go/bigquery/storage/managedwriter/"
36
40
// It is EXPERIMENTAL and subject to change or removal without notice.
37
41
AppendRequests = stats .Int64 (statsPrefix + "append_requests" , "Number of append requests sent" , stats .UnitDimensionless )
38
42
43
+ // AppendBytes is a measure of the bytes sent as append requests.
44
+ // It is EXPERIMENTAL and subject to change or removal without notice.
45
+ AppendBytes = stats .Int64 (statsPrefix + "append_bytes" , "Number of bytes sent as append requests" , stats .UnitBytes )
46
+
39
47
// AppendResponses is a measure of the number of append responses received.
40
48
// It is EXPERIMENTAL and subject to change or removal without notice.
41
49
AppendResponses = stats .Int64 (statsPrefix + "append_responses" , "Number of append responses sent" , stats .UnitDimensionless )
58
66
// It is EXPERIMENTAL and subject to change or removal without notice.
59
67
AppendRequestsView * view.View
60
68
69
+ // AppendBytesView is a cumulative sum of AppendBytes.
70
+ // It is EXPERIMENTAL and subject to change or removal without notice.
71
+ AppendBytesView * view.View
72
+
61
73
// AppendResponsesView is a cumulative sum of AppendResponses.
62
74
// It is EXPERIMENTAL and subject to change or removal without notice.
63
75
AppendResponsesView * view.View
@@ -76,31 +88,43 @@ var (
76
88
)
77
89
78
90
func init () {
79
- AppendRequestsView = createCountView (stats .Measure (AppendRequests ), keyStream )
80
- AppendResponsesView = createCountView (stats .Measure (AppendResponses ), keyStream )
81
- FlushRequestsView = createCountView (stats .Measure (FlushRequests ), keyStream )
82
- AppendClientOpenView = createCountView (stats .Measure (AppendClientOpenCount ), keyStream )
83
- AppendClientOpenRetryView = createCountView (stats .Measure (AppendClientOpenRetryCount ), keyStream )
91
+ AppendRequestsView = createSumView (stats .Measure (AppendRequests ), keyStream , keyDataOrigin )
92
+ AppendBytesView = createSumView (stats .Measure (AppendBytes ), keyStream , keyDataOrigin )
93
+ AppendResponsesView = createSumView (stats .Measure (AppendResponses ), keyStream , keyDataOrigin )
94
+ FlushRequestsView = createSumView (stats .Measure (FlushRequests ), keyStream , keyDataOrigin )
95
+ AppendClientOpenView = createSumView (stats .Measure (AppendClientOpenCount ), keyStream , keyDataOrigin )
96
+ AppendClientOpenRetryView = createSumView (stats .Measure (AppendClientOpenRetryCount ), keyStream , keyDataOrigin )
84
97
}
85
98
86
- func createCountView (m stats.Measure , keys ... tag.Key ) * view.View {
99
+ func createView (m stats.Measure , agg * view. Aggregation , keys ... tag.Key ) * view.View {
87
100
return & view.View {
88
101
Name : m .Name (),
89
102
Description : m .Description (),
90
103
TagKeys : keys ,
91
104
Measure : m ,
92
- Aggregation : view . Sum () ,
105
+ Aggregation : agg ,
93
106
}
94
107
}
95
108
96
- var logOnce sync.Once
109
+ func createSumView (m stats.Measure , keys ... tag.Key ) * view.View {
110
+ return createView (m , view .Sum (), keys ... )
111
+ }
112
+
113
+ var logTagStreamOnce sync.Once
114
+ var logTagOriginOnce sync.Once
97
115
98
- // keyContextWithStreamID returns a new context modified with the streamID tag .
99
- func keyContextWithStreamID (ctx context.Context , streamID string ) context.Context {
116
+ // keyContextWithStreamID returns a new context modified with the instrumentation tags .
117
+ func keyContextWithTags (ctx context.Context , streamID , dataOrigin string ) context.Context {
100
118
ctx , err := tag .New (ctx , tag .Upsert (keyStream , streamID ))
101
119
if err != nil {
102
- logOnce .Do (func () {
103
- log .Printf ("managedwriter: error creating tag map for 'stream' key: %v" , err )
120
+ logTagStreamOnce .Do (func () {
121
+ log .Printf ("managedwriter: error creating tag map for 'streamID' key: %v" , err )
122
+ })
123
+ }
124
+ ctx , err = tag .New (ctx , tag .Upsert (keyDataOrigin , dataOrigin ))
125
+ if err != nil {
126
+ logTagOriginOnce .Do (func () {
127
+ log .Printf ("managedwriter: error creating tag map for 'dataOrigin' key: %v" , err )
104
128
})
105
129
}
106
130
return ctx
0 commit comments