Skip to content

Commit

Permalink
telemetry updates (#151)
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 committed Nov 25, 2022
1 parent ba1df89 commit 16e3226
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions index/server/pkg/server/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func serveDevfileWithVersion(c *gin.Context) {
bytes, devfileIndex := fetchDevfile(c, name, version)

if len(bytes) != 0 {
// 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) {
// 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)
Expand Down
4 changes: 2 additions & 2 deletions index/server/pkg/server/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ func ociServerProxy(c *gin.Context) {
resource = parts[3]
}

//Ignore events from the registry-viewer and DevConsole since those are tracked on the client side
if resource == "blobs" && !util.IsWebClient(c) {
//Ignore events from the registry-viewer and DevConsole since those are tracked on the client side. Ignore indirect calls from clients.
if resource == "blobs" && !util.IsWebClient(c) && !util.IsIndirectCall(c) {
user := util.GetUser(c)
client := util.GetClient(c)

Expand Down
16 changes: 9 additions & 7 deletions index/server/pkg/util/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,20 @@
package util

import (
"log"
"net"

"github.com/gin-gonic/gin"
"golang.org/x/text/language"
"gopkg.in/segmentio/analytics-go.v3"
"log"
"net"
)

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

var telemetryKey = GetOptionalEnv("TELEMETRY_KEY", "").(string)
Expand Down Expand Up @@ -127,7 +129,7 @@ func IsWebClient(c *gin.Context) bool {
//IsIndirectCall determines if a request is made from an internal client
func IsIndirectCall(c *gin.Context) bool {
client := GetClient(c)
if client == registryLibrary {
if client == registryLibrary || client == devfileLibraryIndirect {
return true
}

Expand Down
11 changes: 7 additions & 4 deletions registry-library/library/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"archive/zip"
"encoding/json"
"fmt"
"github.com/hashicorp/go-multierror"
"io"
"io/ioutil"
"net/http"
Expand All @@ -32,6 +31,7 @@ import (
"text/tabwriter"
"time"

"github.com/hashicorp/go-multierror"
orasctx "oras.land/oras-go/pkg/context"

"github.com/containerd/containerd/remotes/docker"
Expand Down Expand Up @@ -215,12 +215,15 @@ func PrintRegistry(registryURLs string, devfileType string, options RegistryOpti
registryURLArray := strings.Split(registryURLs, ",")
var registryList []Registry

//ignore telemetry when printing the registry
modifiedOptions := options
modifiedOptions.Telemetry = TelemetryData{Client: registryLibrary}
if devfileType == string(indexSchema.StackDevfileType) {
registryList = GetMultipleRegistryIndices(registryURLArray, options, indexSchema.StackDevfileType)
registryList = GetMultipleRegistryIndices(registryURLArray, modifiedOptions, indexSchema.StackDevfileType)
} else if devfileType == string(indexSchema.SampleDevfileType) {
registryList = GetMultipleRegistryIndices(registryURLArray, options, indexSchema.SampleDevfileType)
registryList = GetMultipleRegistryIndices(registryURLArray, modifiedOptions, indexSchema.SampleDevfileType)
} else if devfileType == "all" {
registryList = GetMultipleRegistryIndices(registryURLArray, options, indexSchema.StackDevfileType, indexSchema.SampleDevfileType)
registryList = GetMultipleRegistryIndices(registryURLArray, modifiedOptions, indexSchema.StackDevfileType, indexSchema.SampleDevfileType)
}

w := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)
Expand Down

0 comments on commit 16e3226

Please sign in to comment.