Skip to content

Commit 8f9209c

Browse files
authored
fix: missing Sessionable ID in exported metrics (#8737)
1 parent f7a4132 commit 8f9209c

File tree

3 files changed

+17
-33
lines changed

3 files changed

+17
-33
lines changed

pkg/skaffold/instrumentation/firelog/exporter.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"net/http"
2424
"os"
2525

26+
"github.com/google/uuid"
2627
"go.opentelemetry.io/otel/attribute"
2728
"go.opentelemetry.io/otel/exporters/stdout/stdoutmetric"
2829
"go.opentelemetry.io/otel/sdk/metric"
@@ -37,6 +38,9 @@ var (
3738
APIKey = ""
3839
POST = http.Post
3940
Marshal = json.Marshal
41+
42+
// TODO: Implement a persistent client installation ID
43+
GetClientInstallID = uuid.NewString
4044
)
4145

4246
type Exporter struct {
@@ -126,7 +130,7 @@ func sendDataPoint(name string, dp DataPoint) error {
126130
if err != nil {
127131
return err
128132
}
129-
data := buildMetricData(str, dp.eventTime(), dp.upTime())
133+
data := buildMetricData(str, dp.eventTime())
130134

131135
resp, err := POST(fmt.Sprintf(`https://firebaselogging-pa.googleapis.com/v1/firelog/legacy/log?key=%s`, APIKey), "application/json", data.newReader())
132136
if err != nil {
@@ -140,25 +144,22 @@ func sendDataPoint(name string, dp DataPoint) error {
140144
return err
141145
}
142146

143-
func buildMetricData(proto string, startTimeMS int64, upTimeMS int64) MetricData {
147+
func buildMetricData(proto string, startTimeMS int64) MetricData {
144148
return MetricData{
145149
ClientInfo: ClientInfo{ClientType: "DESKTOP"},
146150
LogSource: "CONCORD",
147151
LogEvent: LogEvent{
148152
EventTimeMS: startTimeMS,
149-
EventUptimeMS: upTimeMS,
150153
SourceExtensionJSONProto3Str: proto,
151154
},
152-
RequestTimeMS: startTimeMS,
153-
RequestUptimeMS: upTimeMS,
155+
RequestTimeMS: startTimeMS,
154156
}
155157
}
156158

157159
func buildProtoStr(name string, kvs EventMetadata) (string, error) {
158160
proto3 := SourceExtensionJSONProto3{
159-
ProjectID: "skaffold",
160161
ConsoleType: "SKAFFOLD",
161-
ClientInstallID: "",
162+
ClientInstallID: GetClientInstallID(),
162163
EventName: name,
163164
EventMetadata: kvs,
164165
}

pkg/skaffold/instrumentation/firelog/exporter_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,16 @@ func TestBuildMetricData(t *testing.T) {
140140
LogSource: "CONCORD",
141141
LogEvent: LogEvent{
142142
EventTimeMS: 100,
143-
EventUptimeMS: 200,
144143
SourceExtensionJSONProto3Str: "{foo:a}",
145144
},
146-
RequestTimeMS: 100,
147-
RequestUptimeMS: 200,
145+
RequestTimeMS: 100,
148146
},
149147
},
150148
}
151149

152150
for _, test := range tests {
153151
testutil.Run(t, test.name, func(t *testutil.T) {
154-
actual := buildMetricData(test.proto, test.startTimeMS, test.upTimeMS)
152+
actual := buildMetricData(test.proto, test.startTimeMS)
155153
t.CheckDeepEqual(test.expected, actual)
156154
})
157155
}
@@ -170,7 +168,7 @@ func TestBuildProtoStr(t *testing.T) {
170168
name: "no kvs",
171169
eventName: "no kvs",
172170
kvs: EventMetadata{},
173-
expected: `{"project_id":"skaffold","console_type":"SKAFFOLD","client_install_id":"","event_name":"no kvs","event_metadata":[]}`,
171+
expected: `{"console_type":"SKAFFOLD","client_install_id":"00000000-0000-0000-0000-000000000000","event_name":"no kvs","event_metadata":[]}`,
174172
wantErr: false,
175173
},
176174
{
@@ -180,7 +178,7 @@ func TestBuildProtoStr(t *testing.T) {
180178
{"key1", "value1"},
181179
{"key2", "value2"},
182180
},
183-
expected: `{"project_id":"skaffold","console_type":"SKAFFOLD","client_install_id":"","event_name":"with kvs","event_metadata":[{"key":"key1","value":"value1"},{"key":"key2","value":"value2"}]}`,
181+
expected: `{"console_type":"SKAFFOLD","client_install_id":"00000000-0000-0000-0000-000000000000","event_name":"with kvs","event_metadata":[{"key":"key1","value":"value1"},{"key":"key2","value":"value2"}]}`,
184182
wantErr: false,
185183
},
186184
{
@@ -199,6 +197,7 @@ func TestBuildProtoStr(t *testing.T) {
199197

200198
for _, test := range tests {
201199
testutil.Run(t, test.name, func(t *testutil.T) {
200+
t.Override(&GetClientInstallID, func() string { return "00000000-0000-0000-0000-000000000000" })
202201
if test.marshalFunc != nil {
203202
t.Override(&Marshal, test.marshalFunc)
204203
}

pkg/skaffold/instrumentation/firelog/types.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ type ClientInfo struct {
3030
}
3131

3232
type MetricData struct {
33-
ClientInfo ClientInfo `json:"client_info"`
34-
LogSource string `json:"log_source"`
35-
LogEvent LogEvent `json:"log_event"`
36-
RequestTimeMS int64 `json:"request_time_ms"`
37-
RequestUptimeMS int64 `json:"request_uptime_ms"`
33+
ClientInfo ClientInfo `json:"client_info"`
34+
LogSource string `json:"log_source"`
35+
LogEvent LogEvent `json:"log_event"`
36+
RequestTimeMS int64 `json:"request_time_ms"`
3837
}
3938

4039
type LogEvent struct {
4140
EventTimeMS int64 `json:"event_time_ms"`
42-
EventUptimeMS int64 `json:"event_uptime_ms"`
4341
SourceExtensionJSONProto3Str string `json:"source_extension_json_proto3"`
4442
}
4543

@@ -51,7 +49,6 @@ type KeyValue struct {
5149
type EventMetadata []KeyValue
5250

5351
type SourceExtensionJSONProto3 struct {
54-
ProjectID string `json:"project_id"`
5552
ConsoleType string `json:"console_type"`
5653
ClientInstallID string `json:"client_install_id"`
5754
EventName string `json:"event_name"`
@@ -76,7 +73,6 @@ type DataPoint interface {
7673
value() string
7774
attributes() attribute.Set
7875
eventTime() int64
79-
upTime() int64
8076
}
8177

8278
type DataPointInt64 metricdata.DataPoint[int64]
@@ -89,10 +85,6 @@ func (d DataPointInt64) eventTime() int64 {
8985
return d.StartTime.UnixMilli()
9086
}
9187

92-
func (d DataPointInt64) upTime() int64 {
93-
return d.Time.UnixMilli()
94-
}
95-
9688
type DataPointFloat64 metricdata.DataPoint[float64]
9789

9890
func (d DataPointFloat64) attributes() attribute.Set {
@@ -103,10 +95,6 @@ func (d DataPointFloat64) eventTime() int64 {
10395
return d.StartTime.UnixMilli()
10496
}
10597

106-
func (d DataPointFloat64) upTime() int64 {
107-
return d.Time.UnixMilli()
108-
}
109-
11098
type DataPointHistogram metricdata.HistogramDataPoint
11199

112100
func (d DataPointHistogram) attributes() attribute.Set {
@@ -117,10 +105,6 @@ func (d DataPointHistogram) eventTime() int64 {
117105
return d.StartTime.UnixMilli()
118106
}
119107

120-
func (d DataPointHistogram) upTime() int64 {
121-
return d.Time.UnixMilli()
122-
}
123-
124108
func (d DataPointInt64) value() string {
125109
return fmt.Sprintf("%d", d.Value)
126110
}

0 commit comments

Comments
 (0)