Skip to content

Commit 11d2447

Browse files
authored
Merge pull request #98 from kim-tsao/suppress-devconsole-telemetry
Suppress devconsole events
2 parents 1800790 + 2a9718a commit 11d2447

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

index/server/pkg/server/endpoint.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ func serveDevfile(c *gin.Context) {
106106
return
107107
}
108108

109-
// Track event for telemetry. Ignore events from the registry-viewer since those are tracked on the client side
110-
if enableTelemetry && !util.IsRegistryViewerEvent(c) {
109+
// Track event for telemetry. Ignore events from the registry-viewer and DevConsole since those are tracked on the client side
110+
if enableTelemetry && !util.IsWebClient(c) {
111111

112112
user := util.GetUser(c)
113113
client := util.GetClient(c)
@@ -239,8 +239,8 @@ func buildIndexAPIResponse(c *gin.Context) {
239239
c.File(responseIndexPath)
240240
}
241241

242-
// Track event for telemetry. Ignore events from the registry-viewer since those are tracked on the client side
243-
if enableTelemetry && !util.IsRegistryViewerEvent(c) {
242+
// Track event for telemetry. Ignore events from the registry-viewer and DevConsole since those are tracked on the client side
243+
if enableTelemetry && !util.IsWebClient(c) {
244244
user := util.GetUser(c)
245245
client := util.GetClient(c)
246246
err := util.TrackEvent(analytics.Track{

index/server/pkg/server/index.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ func ociServerProxy(c *gin.Context) {
172172
resource = parts[3]
173173
}
174174

175-
//Ignore events from the registry-viewer since those are tracked on the client side
176-
if resource == "blobs" && !util.IsRegistryViewerEvent(c) {
175+
//Ignore events from the registry-viewer and DevConsole since those are tracked on the client side
176+
if resource == "blobs" && !util.IsWebClient(c) {
177177
user := util.GetUser(c)
178178
client := util.GetClient(c)
179179

index/server/pkg/util/telemetry.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const (
1212
telemetryKey = "6HBMiy5UxBtsbxXx7O4n0t0u4dt8IAR3"
1313
defaultUser = "devfile-registry"
1414
viewerId = "registry-viewer"
15+
consoleId = "openshift-console"
1516
)
1617

1718
//TrackEvent tracks event for telemetry
@@ -95,10 +96,10 @@ func getRegion(c *gin.Context) string {
9596

9697
}
9798

98-
//IsRegistryViewerEvent determines if the event is coming from the registry viewer client
99-
func IsRegistryViewerEvent(c *gin.Context) bool {
99+
//IsWebClient determines if the event is coming from the registry viewer or DevConsole client.
100+
func IsWebClient(c *gin.Context) bool {
100101
client := GetClient(c)
101-
if client == viewerId {
102+
if client == viewerId || client == consoleId {
102103
return true
103104
}
104105

index/server/pkg/util/telemetry_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,18 @@ func TestIsRegistryViewerEvent(t *testing.T) {
243243
context: &gin.Context{
244244
Request: &http.Request{
245245
Header: http.Header{
246-
"Client": {"registry-viewer"},
246+
"Client": {viewerId},
247+
},
248+
},
249+
},
250+
want: true,
251+
},
252+
{
253+
name: "Test openshift-console event",
254+
context: &gin.Context{
255+
Request: &http.Request{
256+
Header: http.Header{
257+
"Client": {consoleId},
247258
},
248259
},
249260
},
@@ -265,7 +276,7 @@ func TestIsRegistryViewerEvent(t *testing.T) {
265276
context: &gin.Context{
266277
Request: &http.Request{
267278
Header: http.Header{
268-
"User": {"registry-viewer"},
279+
"User": {viewerId},
269280
},
270281
},
271282
},
@@ -286,7 +297,7 @@ func TestIsRegistryViewerEvent(t *testing.T) {
286297

287298
for _, test := range tests {
288299
t.Run(test.name, func(t *testing.T) {
289-
got := IsRegistryViewerEvent(test.context)
300+
got := IsWebClient(test.context)
290301
if got != test.want {
291302
t.Errorf("Got: %v, Expected: %v", got, test.want)
292303
}

0 commit comments

Comments
 (0)