Skip to content

Commit

Permalink
Add telemetry for the download-starter-project endpoint to registry…
Browse files Browse the repository at this point in the history
… server (#157)

* starter project telemetry event tracking source added to registry server.

* copyright years in headers changed to year ranges for endpoint.go and index.go

Signed-off-by: Michael Valdron <mvaldron@redhat.com>
  • Loading branch information
michael-valdron authored Jan 19, 2023
1 parent 7a809c0 commit 05c05d3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
22 changes: 21 additions & 1 deletion index/server/pkg/server/endpoint.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2022 Red Hat, Inc.
// Copyright 2022-2023 Red Hat, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -305,6 +305,26 @@ func serveDevfileStarterProjectWithVersion(c *gin.Context) {
return
}

// Track event for telemetry. Ignore events from the registry-viewer and DevConsole since those are tracked on the client side. Ignore indirect calls from clients.
if enableTelemetry && !util.IsWebClient(c) && !util.IsIndirectCall(c) {

user := util.GetUser(c)
client := util.GetClient(c)

err := util.TrackEvent(analytics.Track{
Event: eventTrackMap["spdownload"],
UserId: user,
Context: util.SetContext(c),
Properties: analytics.NewProperties().
Set("devfile", devfileName).
Set("starterProject", starterProjectName).
Set("client", client),
})
if err != nil {
log.Println(err)
}
}

c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s.zip\"", starterProjectName))
c.Data(http.StatusAccepted, starterProjectMediaType, downloadBytes)
}
Expand Down
9 changes: 5 additions & 4 deletions index/server/pkg/server/index.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2022 Red Hat, Inc.
// Copyright 2022-2023 Red Hat, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -41,9 +41,10 @@ import (
)

var eventTrackMap = map[string]string{
"list": "list devfile",
"view": "view devfile",
"download": "download devfile",
"list": "list devfile",
"view": "view devfile",
"download": "download devfile",
"spdownload": "Starter Project Downloaded",
}

var mediaTypeMapping = map[string]string{
Expand Down

0 comments on commit 05c05d3

Please sign in to comment.