Skip to content

Commit

Permalink
reduce telemetry events (#149)
Browse files Browse the repository at this point in the history
Signed-off-by: Kim Tsao <ktsao@redhat.com>

Signed-off-by: Kim Tsao <ktsao@redhat.com>
  • Loading branch information
kim-tsao authored Nov 7, 2022
1 parent 47b3ffa commit f16affc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 11 deletions.
3 changes: 2 additions & 1 deletion build-tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ tar_files_and_cleanup() {
-a -not -name "." \
-a -not -name "logo.svg" \
-a -not -name "logo.png" \
-a -not -name "*.zip" \) -maxdepth 1)
-a -not -name "*.zip" \
-a -not -name "OWNERS" \) -maxdepth 1)

# There are files that need to be pulled into a tar archive
if [[ ! -z $tarFiles ]]; then
Expand Down
3 changes: 2 additions & 1 deletion index/generator/library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const (
devfileHidden = ".devfile.yaml"
extraDevfileEntries = "extraDevfileEntries.yaml"
stackYaml = "stack.yaml"
ownersFile = "OWNERS"
)

// MissingArchError is an error if the architecture list is empty
Expand Down Expand Up @@ -397,7 +398,7 @@ func parseStackDevfile(devfileDirPath string, stackName string, force bool, vers
for _, stackFile := range stackFiles {
// The registry build should have already packaged any folders and miscellaneous files into an archive.tar file
// But, add this check as a safeguard, as OCI doesn't support unarchived folders being pushed up.
if !stackFile.IsDir() {
if !stackFile.IsDir() && stackFile.Name() != ownersFile {
versionComponent.Resources = append(versionComponent.Resources, stackFile.Name())
}
}
Expand Down
2 changes: 1 addition & 1 deletion index/server/pkg/server/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ func buildIndexAPIResponse(c *gin.Context, wantV1Index bool) {
c.Data(http.StatusOK, http.DetectContentType(bytes), bytes)

// Track event for telemetry. Ignore events from the registry-viewer and DevConsole since those are tracked on the client side
if enableTelemetry && !util.IsWebClient(c) {
if enableTelemetry && !util.IsWebClient(c) && !util.IsIndirectCall(c) {
user := util.GetUser(c)
client := util.GetClient(c)
err := util.TrackEvent(analytics.Track{
Expand Down
17 changes: 14 additions & 3 deletions index/server/pkg/util/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import (
)

const (
defaultUser = "devfile-registry"
viewerId = "registry-viewer"
consoleId = "openshift-console"
defaultUser = "devfile-registry"
viewerId = "registry-viewer"
consoleId = "openshift-console"
registryLibrary = "registry-library"
)

var telemetryKey = GetOptionalEnv("TELEMETRY_KEY", "").(string)
Expand Down Expand Up @@ -122,3 +123,13 @@ func IsWebClient(c *gin.Context) bool {

return false
}

//IsIndirectCall determines if a request is made from an internal client
func IsIndirectCall(c *gin.Context) bool {
client := GetClient(c)
if client == registryLibrary {
return true
}

return false
}
16 changes: 11 additions & 5 deletions registry-library/library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ const (
DevfilePNGLogoMediaType = "image/png"
DevfileArchiveMediaType = "application/x-tar"

OwnersFile = "OWNERS"

httpRequestResponseTimeout = 30 * time.Second // httpRequestTimeout configures timeout of all HTTP requests
OwnersFile = "OWNERS"
registryLibrary = "registry-library" //constant to indicate that function is called by the library
httpRequestResponseTimeout = 30 * time.Second // httpRequestTimeout configures timeout of all HTTP requests
)

var (
Expand Down Expand Up @@ -457,7 +457,10 @@ func DownloadStarterProjectAsBytes(registryURL string, stack string, starterProj
// IsStarterProjectExists checks if starter project exists for a given stack
func IsStarterProjectExists(registryURL string, stack string, starterProject string, options RegistryOptions) (bool, error) {
// Get stack index
stackIndex, err := GetStackIndex(registryURL, stack, options)
// Avoid collecting telemetry here since it's an indirect call to GetStackIndex
modifiedOptions := options
modifiedOptions.Telemetry = TelemetryData{Client: registryLibrary}
stackIndex, err := GetStackIndex(registryURL, stack, modifiedOptions)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -497,7 +500,10 @@ func GetStackLink(registryURL string, stack string, options RegistryOptions) (st
var stackLink string

// Get stack index
stackIndex, err := GetStackIndex(registryURL, stack, options)
// Avoid collecting telemetry here since it's an indirect call to GetStackIndex
modifiedOptions := options
modifiedOptions.Telemetry = TelemetryData{Client: registryLibrary}
stackIndex, err := GetStackIndex(registryURL, stack, modifiedOptions)
if err != nil {
return "", err
}
Expand Down

0 comments on commit f16affc

Please sign in to comment.