telemetry fix, log no-telemetry (#802)

This commit is contained in:
Mike Sawka 2024-09-23 13:33:39 -07:00 committed by GitHub
parent de08cc8340
commit 62cc9d8a6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 50 additions and 5 deletions

View File

@ -42,8 +42,8 @@ import (
var WaveVersion = "0.0.0"
var BuildTime = "0"
const InitialTelemetryWait = 30 * time.Second
const TelemetryTick = 10 * time.Minute
const InitialTelemetryWait = 10 * time.Second
const TelemetryTick = 2 * time.Minute
const TelemetryInterval = 4 * time.Hour
const ReadySignalPidVarName = "WAVETERM_READY_SIGNAL_PID"

View File

@ -12,8 +12,6 @@ import { FlexiModal } from "./modal";
import { QuickTips } from "@/app/element/quicktips";
import { atoms } from "@/app/store/global";
import { modalsModel } from "@/app/store/modalmodel";
import { RpcApi } from "@/app/store/wshclientapi";
import { WindowRpcClient } from "@/app/store/wshrpcutil";
import { atom, PrimitiveAtom, useAtom, useAtomValue, useSetAtom } from "jotai";
import "./tos.less";
@ -34,7 +32,7 @@ const ModalPage1 = () => {
};
const setTelemetry = (value: boolean) => {
RpcApi.SetConfigCommand(WindowRpcClient, { "telemetry:enabled": value })
services.ClientService.TelemetryUpdate(value)
.then(() => {
setTelemetryEnabled(value);
})

View File

@ -47,6 +47,9 @@ class ClientServiceType {
MakeWindow(): Promise<WaveWindow> {
return WOS.callBackendService("client", "MakeWindow", Array.from(arguments))
}
TelemetryUpdate(arg2: boolean): Promise<void> {
return WOS.callBackendService("client", "TelemetryUpdate", Array.from(arguments))
}
}
export const ClientService = new ClientServiceType();

View File

@ -6,11 +6,14 @@ package clientservice
import (
"context"
"fmt"
"log"
"time"
"github.com/wavetermdev/waveterm/pkg/remote/conncontroller"
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
"github.com/wavetermdev/waveterm/pkg/waveobj"
"github.com/wavetermdev/waveterm/pkg/wcloud"
"github.com/wavetermdev/waveterm/pkg/wconfig"
"github.com/wavetermdev/waveterm/pkg/wcore"
"github.com/wavetermdev/waveterm/pkg/wlayout"
"github.com/wavetermdev/waveterm/pkg/wshrpc"
@ -106,3 +109,26 @@ func (cs *ClientService) AgreeTos(ctx context.Context) (waveobj.UpdatesRtnType,
wlayout.BootstrapStarterLayout(ctx)
return waveobj.ContextGetUpdatesRtn(ctx), nil
}
func (cs *ClientService) TelemetryUpdate(ctx context.Context, telemetryEnabled bool) error {
meta := waveobj.MetaMapType{
wconfig.ConfigKey_TelemetryEnabled: telemetryEnabled,
}
err := wconfig.SetBaseConfigValue(meta)
if err != nil {
return fmt.Errorf("error setting telemetry value: %w", err)
}
clientData, err := wstore.DBGetSingleton[*waveobj.Client](ctx)
if err != nil {
return fmt.Errorf("error getting client data: %w", err)
}
if clientData == nil {
return fmt.Errorf("client data is nil")
}
telemetryErr := wcloud.SendNoTelemetryUpdate(ctx, clientData.OID, !telemetryEnabled)
if telemetryErr != nil {
// don't return error here, just log
log.Printf("[error] sending telemetry update: %v\n", telemetryErr)
}
return nil
}

View File

@ -11,6 +11,7 @@ import (
"github.com/google/uuid"
"github.com/wavetermdev/waveterm/pkg/blockcontroller"
"github.com/wavetermdev/waveterm/pkg/telemetry"
"github.com/wavetermdev/waveterm/pkg/waveobj"
"github.com/wavetermdev/waveterm/pkg/wps"
"github.com/wavetermdev/waveterm/pkg/wstore"
@ -172,9 +173,26 @@ func CreateClient(ctx context.Context) (*waveobj.Client, error) {
}
func CreateBlock(ctx context.Context, tabId string, blockDef *waveobj.BlockDef, rtOpts *waveobj.RuntimeOpts) (*waveobj.Block, error) {
if blockDef == nil {
return nil, fmt.Errorf("blockDef is nil")
}
if blockDef.Meta == nil || blockDef.Meta.GetString(waveobj.MetaKey_View, "") == "" {
return nil, fmt.Errorf("no view provided for new block")
}
blockData, err := wstore.CreateBlock(ctx, tabId, blockDef, rtOpts)
if err != nil {
return nil, fmt.Errorf("error creating block: %w", err)
}
go func() {
blockView := blockDef.Meta.GetString(waveobj.MetaKey_View, "")
if blockView == "" {
return
}
tctx, cancelFn := context.WithTimeout(context.Background(), 2*time.Second)
defer cancelFn()
telemetry.UpdateActivity(tctx, telemetry.ActivityUpdate{
Renderers: map[string]int{blockView: 1},
})
}()
return blockData, nil
}