Skip to content

Commit

Permalink
Merge 0bca28f into 8c9bcde
Browse files Browse the repository at this point in the history
  • Loading branch information
feloy authored Jul 19, 2023
2 parents 8c9bcde + 0bca28f commit 5a0dbfe
Show file tree
Hide file tree
Showing 35 changed files with 3,685 additions and 146 deletions.
29 changes: 29 additions & 0 deletions ododevapispec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,24 @@ paths:
example:
message: "Error getting the Devfile content"

/telemetry:
get:
description: Get the specific information for sending telemetry data
responses:
'200':
description: 'Specific information for sending telemetry data'
content:
application/json:
schema:
$ref: '#/components/schemas/TelemetryResponse'
'500':
description: Error getting the telemetry data
content:
application/json:
schema:
$ref: '#/components/schemas/GeneralError'
example:
message: "Error getting the telemetry data"

/devstate/devfile:
put:
Expand Down Expand Up @@ -1231,6 +1249,17 @@ components:
properties:
content:
type: string
TelemetryResponse:
type: object
required:
- enabled
properties:
enabled:
type: boolean
apikey:
type: string
userid:
type: string
DevstateDevfilePutRequest:
type: object
required:
Expand Down
1 change: 1 addition & 0 deletions pkg/apiserver-gen/.openapi-generator/FILES

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/apiserver-gen/go/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions pkg/apiserver-gen/go/api_default.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions pkg/apiserver-gen/go/model__telemetry_get_200_response.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions pkg/apiserver-gen/go/model_telemetry_response.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions pkg/apiserver-impl/api_default_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
odocontext "github.com/redhat-developer/odo/pkg/odo/context"
"github.com/redhat-developer/odo/pkg/podman"
"github.com/redhat-developer/odo/pkg/preference"
"github.com/redhat-developer/odo/pkg/segment"
scontext "github.com/redhat-developer/odo/pkg/segment/context"
"github.com/redhat-developer/odo/pkg/state"
"k8s.io/klog"
)
Expand Down Expand Up @@ -175,3 +177,27 @@ func (s *DefaultApiService) validateDevfile(ctx context.Context, dir string) err
}
return validate.ValidateDevfileData(devObj.Data)
}

func (s *DefaultApiService) TelemetryGet(ctx context.Context) (openapi.ImplResponse, error) {
var (
enabled = scontext.GetTelemetryStatus(ctx)
apikey string
userid string
)
if enabled {
apikey = segment.GetApikey()
var err error
userid, err = segment.GetUserIdentity(segment.GetTelemetryFilePath())
if err != nil {
return openapi.Response(http.StatusInternalServerError, openapi.GeneralError{
Message: fmt.Sprintf("error getting telemetry data: %s", err),
}), nil
}
}

return openapi.Response(http.StatusOK, openapi.TelemetryResponse{
Enabled: enabled,
Apikey: apikey,
Userid: userid,
}), nil
}
3 changes: 3 additions & 0 deletions pkg/apiserver-impl/ui/3rdpartylicenses.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pkg/apiserver-impl/ui/index.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pkg/apiserver-impl/ui/main.2ab96df0533a01ab.js

This file was deleted.

1 change: 1 addition & 0 deletions pkg/apiserver-impl/ui/main.859950834bdefd36.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions pkg/odo/genericclioptions/runnable.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ func GenericRun(o Runnable, testClientset clientset.Clientset, cmd *cobra.Comman
klog.V(4).Infof("WARNING: debug telemetry, if enabled, will be logged in %s", debugTelemetry)
}

isTelemetryEnabled := segment.IsTelemetryEnabled(userConfig, envcontext.GetEnvConfig(ctx))
scontext.SetTelemetryStatus(ctx, isTelemetryEnabled)

// We can dereference as there is a default value defined for this config field
err = scontext.SetCaller(ctx, envConfig.TelemetryCaller)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/segment/integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func getTelemetryForDevfileRegistry(ctx context.Context) (registryLibrary.Teleme
tag, _ := locale.Detect()
td.Locale = tag.String()

user, err := getUserIdentity(GetTelemetryFilePath())
user, err := GetUserIdentity(GetTelemetryFilePath())
if err != nil {
// default to the generic user ID if the anonymous ID cannot be found
td.User = td.Client
Expand Down
10 changes: 7 additions & 3 deletions pkg/segment/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ type Client struct {
TelemetryFilePath string
}

func GetApikey() string {
return writeKey
}

// NewClient returns a Client created with the default args
func NewClient() (*Client, error) {
return newCustomClient(
Expand Down Expand Up @@ -131,7 +135,7 @@ func (c *Client) Upload(ctx context.Context, data TelemetryData) error {
}

// obtain the user ID
userId, uerr := getUserIdentity(c.TelemetryFilePath)
userId, uerr := GetUserIdentity(c.TelemetryFilePath)
if uerr != nil {
return uerr
}
Expand Down Expand Up @@ -193,8 +197,8 @@ func GetTelemetryFilePath() string {
return filepath.Join(homeDir, ".redhat", "anonymousId")
}

// getUserIdentity returns the anonymous ID if it exists, else creates a new one and sends the data to Segment
func getUserIdentity(telemetryFilePath string) (string, error) {
// GetUserIdentity returns the anonymous ID if it exists, else creates a new one and sends the data to Segment
func GetUserIdentity(telemetryFilePath string) (string, error) {
var id []byte

// Get-or-Create the '$HOME/.redhat' directory
Expand Down
Loading

0 comments on commit 5a0dbfe

Please sign in to comment.