Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ tasks:
- build:tsunamiscaffold
env:
WAVETERM_ENVFILE: "{{.ROOT_DIR}}/.env"
WCLOUD_PING_ENDPOINT: "https://ping-dev.waveterm.dev/central"
WCLOUD_ENDPOINT: "https://api-dev.waveterm.dev/central"
WCLOUD_WS_ENDPOINT: "wss://wsapi-dev.waveterm.dev"
WAVETERM_NOCONFIRMQUIT: "1"
Expand All @@ -41,7 +40,6 @@ tasks:
- build:backend
env:
WAVETERM_ENVFILE: "{{.ROOT_DIR}}/.env"
WCLOUD_PING_ENDPOINT: "https://ping-dev.waveterm.dev/central"
WCLOUD_ENDPOINT: "https://api-dev.waveterm.dev/central"
WCLOUD_WS_ENDPOINT: "wss://wsapi-dev.waveterm.dev"

Expand All @@ -53,7 +51,6 @@ tasks:
- build:backend:quickdev
env:
WAVETERM_ENVFILE: "{{.ROOT_DIR}}/.env"
WCLOUD_PING_ENDPOINT: "https://ping-dev.waveterm.dev/central"
WCLOUD_ENDPOINT: "https://api-dev.waveterm.dev/central"
WCLOUD_WS_ENDPOINT: "wss://wsapi-dev.waveterm.dev/"
WAVETERM_NOCONFIRMQUIT: "1"
Expand All @@ -80,7 +77,6 @@ tasks:
- build:backend:quickdev:windows
env:
WAVETERM_ENVFILE: "{{.ROOT_DIR}}/.env"
WCLOUD_PING_ENDPOINT: "https://ping-dev.waveterm.dev/central"
WCLOUD_ENDPOINT: "https://api-dev.waveterm.dev/central"
WCLOUD_WS_ENDPOINT: "wss://wsapi-dev.waveterm.dev/"

Expand All @@ -92,7 +88,6 @@ tasks:
- build:backend:quickdev:linux
env:
WAVETERM_ENVFILE: "{{.ROOT_DIR}}/.env"
WCLOUD_PING_ENDPOINT: "https://ping-dev.waveterm.dev/central"
WCLOUD_ENDPOINT: "https://api-dev.waveterm.dev/central"
WCLOUD_WS_ENDPOINT: "wss://wsapi-dev.waveterm.dev/"
WAVETERM_NOCONFIRMQUIT: "1"
Expand Down
14 changes: 12 additions & 2 deletions pkg/wcloud/wcloud.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2025, Command Line Inc.
// Copyright 2026, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

package wcloud
Expand All @@ -25,7 +25,7 @@ import (

const WCloudEndpoint = "https://api.waveterm.dev/central"
const WCloudEndpointVarName = "WCLOUD_ENDPOINT"
const WCloudPingEndpoint = "https://ping.waveterm.dev/central"
const WCloudPingEndpoint = "https://cfapi.waveterm.dev/api"
const WCloudPingEndpointVarName = "WCLOUD_PING_ENDPOINT"

var WCloudEndpoint_VarCache string
Expand All @@ -38,6 +38,7 @@ const MaxUpdatesToDeDup = 1000
const MaxUpdateWriterErrors = 3
const WCloudDefaultTimeout = 5 * time.Second
const WCloudWebShareUpdateTimeout = 15 * time.Second
const SendEvents = false

// setting to 1M to be safe (max is 6M for API-GW + Lambda, but there is base64 encoding and upload time)
// we allow one extra update past this estimated size
Expand Down Expand Up @@ -180,6 +181,9 @@ func sendTEventsBatch(clientId string) (bool, int, error) {
}

func sendTEvents(clientId string) (int, error) {
if !SendEvents {
return 0, nil
}
numIters := 0
totalEvents := 0
for {
Expand Down Expand Up @@ -219,6 +223,9 @@ func SendAllTelemetry(clientId string) error {
}

func sendTelemetry(clientId string) error {
if !SendEvents {
return nil
}
ctx, cancelFn := context.WithTimeout(context.Background(), WCloudDefaultTimeout)
defer cancelFn()
activity, err := telemetry.GetNonUploadedActivity(ctx)
Expand Down Expand Up @@ -255,6 +262,9 @@ func sendTelemetry(clientId string) error {
}

func SendNoTelemetryUpdate(ctx context.Context, clientId string, noTelemetryVal bool) error {
if !SendEvents {
return nil
}
req, err := makeAnonPostReq(ctx, NoTelemetryUrl, NoTelemetryInputType{ClientId: clientId, Value: noTelemetryVal})
if err != nil {
return err
Expand Down
76 changes: 76 additions & 0 deletions pkg/wcloud/wcloud_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2026, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

package wcloud

import (
"context"
"encoding/json"
"io"
"net/http"
"strings"
"testing"
)

type roundTripFunc func(*http.Request) (*http.Response, error)

func (fn roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {
return fn(req)
}

func TestEventSending(t *testing.T) {
originalClient := http.DefaultClient
originalPingEndpoint := WCloudPingEndpoint_VarCache
t.Cleanup(func() {
http.DefaultClient = originalClient
WCloudPingEndpoint_VarCache = originalPingEndpoint
})
WCloudPingEndpoint_VarCache = "https://ping.example.test/central"
var requests []*http.Request
var inputs []PingInputType
http.DefaultClient = &http.Client{Transport: roundTripFunc(func(req *http.Request) (*http.Response, error) {
requests = append(requests, req)
if req.Method != http.MethodPost || req.URL.Path != "/api"+PingUrl {
t.Fatalf("unexpected request: %s %s", req.Method, req.URL.Path)
}
var input PingInputType
if err := json.NewDecoder(req.Body).Decode(&input); err != nil {
t.Fatal(err)
}
inputs = append(inputs, input)
return &http.Response{StatusCode: http.StatusOK, Body: io.NopCloser(strings.NewReader(""))}, nil
})}

ctx := context.Background()
if count, err := sendTEvents("test-client"); err != nil || count != 0 {
t.Fatalf("event batch returned (%d, %v), want (0, nil)", count, err)
}
if err := sendTelemetry("test-client"); err != nil {
t.Fatal(err)
}
for _, disabled := range []bool{false, true} {
if err := SendNoTelemetryUpdate(ctx, "test-client", disabled); err != nil {
t.Fatal(err)
}
}
if len(requests) != 0 {
t.Fatalf("got %d requests with uploads disabled, want 0", len(requests))
}

for _, enabled := range []bool{false, true} {
if err := SendDiagnosticPing(ctx, "test-client", enabled); err != nil {
t.Fatal(err)
}
}
if len(inputs) != 2 {
t.Fatalf("got %d pings, want 2", len(inputs))
}
for i, input := range inputs {
if input.ClientId != "test-client" || input.UsageTelemetry != (i == 1) {
t.Errorf("ping %d did not preserve its input", i)
}
if input.Arch == "" || input.Version == "" || input.LocalDate == "" {
t.Errorf("ping %d is missing app details", i)
}
}
}