Skip to content

Commit

Permalink
removed cli telemetry.
Browse files Browse the repository at this point in the history
  • Loading branch information
hugosantos committed Jul 24, 2023
1 parent 381ae4b commit bab4fde
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 615 deletions.
12 changes: 5 additions & 7 deletions internal/cli/cmd/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,8 @@ type tenant struct {
}

func completeLogin(ctx context.Context, id, kind string) (tenant, error) {
ephemeralCliId := fnapi.TelemetryOn(ctx).GetClientID()

if kind == "tenant" {
res, err := fnapi.CompleteTenantLogin(ctx, id, ephemeralCliId)
res, err := fnapi.CompleteTenantLogin(ctx, id)
if err != nil {
return tenant{}, err
}
Expand All @@ -97,7 +95,7 @@ func completeLogin(ctx context.Context, id, kind string) (tenant, error) {
}

// TODO remove old login path
userAuth, err := getUserAuth(ctx, id, kind, ephemeralCliId)
userAuth, err := getUserAuth(ctx, id, kind)
if err != nil {
return tenant{}, err
}
Expand All @@ -119,13 +117,13 @@ func completeLogin(ctx context.Context, id, kind string) (tenant, error) {
return tenant{token: tt.TenantToken}, nil
}

func getUserAuth(ctx context.Context, id, kind, ephemeralCliId string) (*auth.UserAuth, error) {
func getUserAuth(ctx context.Context, id, kind string) (*auth.UserAuth, error) {
switch kind {
case "tenant":
return nil, fnerrors.InternalError("tenant login cannot produce user auth")

case "clerk":
t, err := fnapi.CompleteClerkLogin(ctx, id, ephemeralCliId)
t, err := fnapi.CompleteClerkLogin(ctx, id)
if err != nil {
return nil, err
}
Expand All @@ -141,6 +139,6 @@ func getUserAuth(ctx context.Context, id, kind, ephemeralCliId string) (*auth.Us
}, nil

default:
return fnapi.CompleteLogin(ctx, id, ephemeralCliId)
return fnapi.CompleteLogin(ctx, id)
}
}
29 changes: 1 addition & 28 deletions internal/cli/fncobra/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"namespacelabs.dev/foundation/internal/console/colors"
"namespacelabs.dev/foundation/internal/console/consolesink"
"namespacelabs.dev/foundation/internal/console/termios"
"namespacelabs.dev/foundation/internal/environment"
"namespacelabs.dev/foundation/internal/fnapi"
"namespacelabs.dev/foundation/internal/fnerrors"
"namespacelabs.dev/foundation/internal/fnerrors/format"
Expand Down Expand Up @@ -118,19 +117,6 @@ func doMain(opts MainOpts) (colors.Style, error) {
DeferCheckVersion(ctx, opts.Name)
}

tel := fnapi.TelemetryOn(ctx)

// XXX move id management out of telemetry, it's used for other purposes too.
if tel.IsFirstRun() && !environment.IsRunningInCI() {
// First NS run - print a welcome message.
welcome.PrintWelcome(ctx, true /* firstRun */, opts.Name)
}

// Now that "useTelemetry" flag is parsed, we can conditionally enable telemetry.
if useTelemetry && tel != nil {
tel.Enable()
}

if viper.GetBool("enable_pprof") {
go ListenPProf(console.Debug(cmd.Context()))
}
Expand All @@ -140,9 +126,6 @@ func doMain(opts MainOpts) (colors.Style, error) {
// Setting up container registry logging, which is unfortunately global.
crlogs.Warn = log.New(console.TypedOutput(cmd.Context(), "cr-warn", idtypes.CatOutputTool), "", log.LstdFlags|log.Lmicroseconds)

// Telemetry.
tel.RecordInvocation(ctx, cmd, args)

out := logrus.New()
out.SetOutput(console.NamedDebug(ctx, "containerd"))
// Because we can have concurrent builds producing the same output; the
Expand Down Expand Up @@ -208,16 +191,6 @@ func doMain(opts MainOpts) (colors.Style, error) {
cleanupTracer()
}

if err != nil && !errors.Is(err, context.Canceled) {
if tel := fnapi.TelemetryOn(rootCtx); tel != nil {
// Record errors only after the user sees them to hide potential latency implications.
// We pass the original ctx without sink since logs have already been flushed.
tel.RecordError(rootCtx, err)
}

return style, err
}

return style, err
}

Expand Down Expand Up @@ -406,5 +379,5 @@ func setupContext(ctx context.Context, inhibitReport bool, rendered consolesink.
flushLogs = func() {}
}

return fnapi.WithTelemetry(ctx), style, flushLogs
return ctx, style, flushLogs
}
4 changes: 0 additions & 4 deletions internal/fnapi/fnapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ func DecodeJSONResponse(resp any) func(io.Reader) error {
}

func AddNamespaceHeaders(ctx context.Context, headers *http.Header) {
if tel := TelemetryOn(ctx); tel != nil && tel.IsTelemetryEnabled() {
headers.Add("NS-Client-ID", tel.GetClientID())
}

headers.Add("NS-Internal-Version", fmt.Sprintf("%d", versions.Builtin().APIVersion))

if AdminMode {
Expand Down
18 changes: 7 additions & 11 deletions internal/fnapi/signin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ type StartLoginResponse struct {
}

type CompleteLoginRequest struct {
LoginId string `json:"login_id"`
EphemeralCliId string `json:"ephemeral_cli_id"`
LoginId string `json:"login_id"`
}

// Returns the URL which the user should open.
Expand All @@ -48,10 +47,9 @@ func StartLogin(ctx context.Context, kind, tenantId string) (*StartLoginResponse
return &resp, nil
}

func CompleteLogin(ctx context.Context, id, ephemeralCliId string) (*auth.UserAuth, error) {
func CompleteLogin(ctx context.Context, id string) (*auth.UserAuth, error) {
req := CompleteLoginRequest{
LoginId: id,
EphemeralCliId: ephemeralCliId,
LoginId: id,
}

method := "nsl.signin.SigninService/CompleteLogin"
Expand All @@ -73,10 +71,9 @@ type CompleteClerkLoginResponse struct {
Ticket string `json:"ticket,omitempty"`
}

func CompleteClerkLogin(ctx context.Context, id, ephemeralCliId string) (*CompleteClerkLoginResponse, error) {
func CompleteClerkLogin(ctx context.Context, id string) (*CompleteClerkLoginResponse, error) {
req := CompleteLoginRequest{
LoginId: id,
EphemeralCliId: ephemeralCliId,
LoginId: id,
}

method := "nsl.signin.SigninService/CompleteClerkLogin"
Expand All @@ -99,10 +96,9 @@ type CompleteTenantLoginResponse struct {
TenantName string `json:"tenant_name,omitempty"`
}

func CompleteTenantLogin(ctx context.Context, id, ephemeralCliId string) (*CompleteTenantLoginResponse, error) {
func CompleteTenantLogin(ctx context.Context, id string) (*CompleteTenantLoginResponse, error) {
req := CompleteLoginRequest{
LoginId: id,
EphemeralCliId: ephemeralCliId,
LoginId: id,
}

method := "nsl.signin.SigninService/CompleteTenantLogin"
Expand Down
Loading

0 comments on commit bab4fde

Please sign in to comment.