From c5b9c990050a475172db5896cfebc358cb08dbe0 Mon Sep 17 00:00:00 2001 From: divyam234 <47589864+divyam234@users.noreply.github.com> Date: Sat, 6 Jul 2024 11:23:30 +0530 Subject: [PATCH] chore: update stataviz monitoring --- .github/workflows/release.yml | 4 ++-- .goreleaser.yml | 1 - cmd/run.go | 15 +++++++++++++++ go.mod | 1 + go.sum | 2 ++ internal/config/config.go | 1 + 6 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 43bb14b..3c545ef 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,10 +30,10 @@ jobs: uses: docker/setup-qemu-action@v3 - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v6 + uses: goreleaser/goreleaser-action@v5 with: distribution: goreleaser - version: "~> v2" + version: latest args: release --clean env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/.goreleaser.yml b/.goreleaser.yml index f2c4de6..fbbf66b 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -1,4 +1,3 @@ -version: 2 project_name: teldrive env: - GO111MODULE=on diff --git a/cmd/run.go b/cmd/run.go index 6239505..3fbfcc5 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -11,6 +11,7 @@ import ( "time" "unicode" + "github.com/arl/statsviz" "github.com/divyam234/teldrive/api" "github.com/divyam234/teldrive/internal/config" "github.com/divyam234/teldrive/internal/database" @@ -54,6 +55,7 @@ func NewRun() *cobra.Command { runCmd.Flags().IntVarP(&config.Server.Port, "server-port", "p", 8080, "Server port") duration.DurationVar(runCmd.Flags(), &config.Server.GracefulShutdown, "server-graceful-shutdown", 15*time.Second, "Server graceful shutdown timeout") runCmd.Flags().BoolVar(&config.Server.EnablePprof, "server-enable-pprof", false, "Enable Pprof Profiling") + runCmd.Flags().BoolVar(&config.Server.EnableStatsviz, "server-enable-statsviz", false, "Enable Statsviz Monitoring") runCmd.Flags().BoolVar(&config.CronJobs.Enable, "cronjobs-enable", true, "Run cron jobs") @@ -230,6 +232,19 @@ func initApp(lc fx.Lifecycle, cfg *config.Config, c *controller.Controller) *gin pprof.Register(r) } + if cfg.Server.EnableStatsviz { + srv, _ := statsviz.NewServer() + ws := srv.Ws() + index := srv.Index() + r.GET("/debug/statsviz/*filepath", func(context *gin.Context) { + if context.Param("filepath") == "/ws" { + ws(context.Writer, context.Request) + return + } + index(context.Writer, context.Request) + }) + } + r.Use(gin.Recovery()) r.Use(ginzap.GinzapWithConfig(logging.DefaultLogger().Desugar(), &ginzap.Config{ diff --git a/go.mod b/go.mod index ca794be..911e4e4 100644 --- a/go.mod +++ b/go.mod @@ -33,6 +33,7 @@ require ( require ( filippo.io/edwards25519 v1.1.0 // indirect + github.com/arl/statsviz v0.6.0 // indirect github.com/bytedance/sonic/loader v0.1.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cloudwego/base64x v0.1.4 // indirect diff --git a/go.sum b/go.sum index 0e1cb42..2b1b89a 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7Oputl github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU= github.com/WinterYukky/gorm-extra-clause-plugin v0.2.1 h1:G0e4eFRrh3WdM1I3EKKidV2yF5J09uRIJlKYxt6zNR4= github.com/WinterYukky/gorm-extra-clause-plugin v0.2.1/go.mod h1:qAN5KRJJTCM49X2wUHZAVB3rfvO8A8L0ISd/uB1WM5s= +github.com/arl/statsviz v0.6.0 h1:jbW1QJkEYQkufd//4NDYRSNBpwJNrdzPahF7ZmoGdyE= +github.com/arl/statsviz v0.6.0/go.mod h1:0toboo+YGSUXDaS4g1D5TVS4dXs7S7YYT5J/qnW2h8s= github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= diff --git a/internal/config/config.go b/internal/config/config.go index d008fe4..012ee9c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -17,6 +17,7 @@ type ServerConfig struct { Port int GracefulShutdown time.Duration EnablePprof bool + EnableStatsviz bool } type CronJobConfig struct {