mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-29 05:56:38 +08:00
aa4faddade
Result: {"status":"keep","total_issues":8,"golint_canonicalheader":0,"golint_errname":0,"golint_errorlint":1,"golint_exhaustive":0,"golint_forcetypeassert":0,"golint_gosec":0,"golint_intrange":0,"golint_modernize":3,"golint_nilnil":3,"golint_perfsprint":0,"golint_prealloc":0,"golint_recvcheck":1,"golint_usestdlibvars":0,"golint_wastedassign":0,"golint_total":8,"golint_test_testifylint":0,"golint_test_thelper":0,"golint_test_usetesting":0,"golint_test_total":0,"golint_vetx_total":0,"eslint_problems":0,"eslint_errors":0,"eslint_warnings":0,"tsc_errors":0,"vitest_failed":0,"vitest_total":116,"measure_s":81}
99 lines
2.7 KiB
Go
99 lines
2.7 KiB
Go
// Copyright 2026 Arctel.net
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// Package main is a manual smoke tool for ClickHouse app write path.
|
|
// Usage (from repo root, with config.yaml and Docker CH up):
|
|
//
|
|
// go run ./scripts/live_ch_smoke
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/Rain-kl/Wavelet/internal/repository"
|
|
|
|
"github.com/Rain-kl/Wavelet/internal/apps/openflare/chwriter"
|
|
db "github.com/Rain-kl/Wavelet/internal/infra/persistence"
|
|
"github.com/Rain-kl/Wavelet/internal/model"
|
|
)
|
|
|
|
const (
|
|
flushWaitTimeout = 45 * time.Second
|
|
listLimit = 5
|
|
pollInterval = 2 * time.Second
|
|
)
|
|
|
|
func main() {
|
|
if err := run(); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func run() error {
|
|
if !db.ChConnReady() {
|
|
return errors.New("ChConn not ready — check config.yaml clickhouse.enabled")
|
|
}
|
|
ctx := context.Background()
|
|
chwriter.Init(ctx)
|
|
defer func() { _ = chwriter.Stop(ctx) }()
|
|
|
|
now := time.Now().UTC()
|
|
nodeID := "e2e-app-" + now.Format("150405")
|
|
if err := repository.InsertOpenFlareMetricSnapshot(ctx, &model.OpenFlareMetricSnapshot{
|
|
NodeID: nodeID, CapturedAt: now, CPUUsagePercent: 41.2,
|
|
MemoryUsedBytes: 123, MemoryTotalBytes: 1000,
|
|
StorageUsedBytes: 456, StorageTotalBytes: 2000,
|
|
DiskReadBytes: 11, DiskWriteBytes: 22, NetworkRxBytes: 33, NetworkTxBytes: 44,
|
|
}); err != nil {
|
|
return fmt.Errorf("insert: %w", err)
|
|
}
|
|
fmt.Println("queued", nodeID)
|
|
|
|
if err := waitForSnapshot(ctx, nodeID, now); err != nil {
|
|
return err
|
|
}
|
|
if err := assertLatestIncludes(ctx, nodeID, now); err != nil {
|
|
return err
|
|
}
|
|
for _, s := range chwriter.WriterStats() {
|
|
fmt.Printf("writer %s running=%v depth=%d drops=%d flush_err=%d\n",
|
|
s.Name, s.Running, s.Depth, s.Drops, s.FlushErrors)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func waitForSnapshot(ctx context.Context, nodeID string, now time.Time) error {
|
|
deadline := time.Now().Add(flushWaitTimeout)
|
|
for time.Now().Before(deadline) {
|
|
rows, err := repository.ListOpenFlareMetricSnapshotsSince(ctx, nodeID, now.Add(-time.Minute), listLimit)
|
|
if err != nil {
|
|
return fmt.Errorf("list: %w", err)
|
|
}
|
|
if len(rows) > 0 {
|
|
fmt.Printf("OK flushed id=%d cpu=%.1f\n", rows[0].ID, rows[0].CPUUsagePercent)
|
|
return nil
|
|
}
|
|
time.Sleep(pollInterval)
|
|
}
|
|
return errors.New("not flushed within timeout")
|
|
}
|
|
|
|
func assertLatestIncludes(ctx context.Context, nodeID string, now time.Time) error {
|
|
latest, err := repository.ListOpenFlareLatestMetricSnapshotsSince(ctx, "", now.Add(-time.Hour))
|
|
if err != nil {
|
|
return fmt.Errorf("latest: %w", err)
|
|
}
|
|
for _, r := range latest {
|
|
if r != nil && r.NodeID == nodeID {
|
|
fmt.Println("OK latest-per-node includes node")
|
|
return nil
|
|
}
|
|
}
|
|
return fmt.Errorf("latest-per-node missing node %s", nodeID)
|
|
}
|