Skip to content

Commit fa5767d

Browse files
committed
- merged with main
2 parents f31b61a + 913727f commit fa5767d

15 files changed

Lines changed: 3728 additions & 182 deletions

File tree

cmd/runner/main.go

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"errors"
66
"flag"
77
"fmt"
8+
"github.com/ponyruntime/pony/runtime/lua/modules/text"
9+
"net/http/pprof"
810

911
"github.com/wippyai/module-registry-proto/gen/registry/identity/v1/identityv1connect"
1012
"github.com/wippyai/module-registry-proto/gen/registry/module/v1/modulev1connect"
@@ -20,7 +22,6 @@ import (
2022
"path/filepath"
2123
"runtime"
2224
"runtime/debug"
23-
"runtime/pprof"
2425
"strings"
2526
"syscall"
2627
"time"
@@ -470,61 +471,22 @@ func (a *App) Stop() error {
470471

471472
// AddCleanup this method to your App struct
472473
func (a *App) StartProfiler() {
473-
// Memory profiling
474-
runtime.MemProfileRate = 1 // Profile all allocations
475-
476-
// Create directory for profiles if it doesn't exist
477-
if err := os.MkdirAll("profiles", 0755); err != nil {
478-
a.logger.Error("failed to create profiles directory", zap.Error(err))
479-
return
480-
}
481-
482-
// CPU profiling
483-
cpuFile, err := os.Create("profiles/cpu.prof")
484-
if err != nil {
485-
a.logger.Error("failed to create CPU profile", zap.Error(err))
486-
return
487-
}
488-
err = pprof.StartCPUProfile(cpuFile)
489-
if err != nil {
490-
a.logger.Error("failed to start CPU profile", zap.Error(err))
491-
return
492-
}
493-
defer pprof.StopCPUProfile()
494-
495-
// Periodic heap profiling
496-
go func() {
497-
tick := time.NewTicker(30 * time.Second)
498-
defer tick.Stop()
499-
500-
for i := 1; ; i++ {
501-
select {
502-
case <-a.ctx.Done():
503-
return
504-
case <-tick.C:
505-
heapFile, err := os.Create(fmt.Sprintf("profiles/heap_%d.prof", i))
506-
if err != nil {
507-
a.logger.Error("failed to create heap profile", zap.Error(err))
508-
continue
509-
}
510-
wErr := pprof.WriteHeapProfile(heapFile)
511-
if wErr != nil {
512-
a.logger.Error("failed to write heap profile", zap.Error(err))
513-
}
514-
cErr := heapFile.Close()
515-
if cErr != nil {
516-
a.logger.Error("failed to close heap profile file", zap.Error(err))
517-
}
518-
}
519-
}
520-
}()
521474

522475
// HTTP server for live profiling
523476
go func() {
524477
profilerAddr := "localhost:6060"
525478
a.logger.Info("starting pprof server", zap.String("address", profilerAddr))
479+
480+
mux := httpbase.NewServeMux()
481+
482+
mux.HandleFunc("/debug/pprof/", pprof.Index)
483+
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
484+
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
485+
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
486+
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
487+
526488
//nolint:gosec // ok for now
527-
if err := httpbase.ListenAndServe(profilerAddr, nil); err != nil {
489+
if err := httpbase.ListenAndServe(profilerAddr, mux); err != nil {
528490
if !errors.Is(err, httpbase.ErrServerClosed) {
529491
a.logger.Error("pprof server failed", zap.Error(err))
530492
}
@@ -975,6 +937,7 @@ func WithLuaRuntime(a *App) []eventbus.EventHandler {
975937
hash.NewHashModule(),
976938
command.NewCommandModule(),
977939
yamlmod.NewYAMLModule(),
940+
text.NewTextModule(),
978941
registrymod.NewLoaderModule(a.logger.Named("loader")),
979942
events.NewEventsModule(a.logger.Named("events")),
980943
exec.NewExecModule(a.logger.Named("exec")),
@@ -996,8 +959,8 @@ func WithLuaRuntime(a *App) []eventbus.EventHandler {
996959
cloudstorage.NewModule(),
997960
system.NewSystemModule(),
998961
},
999-
ProtoCacheSize: 600,
1000-
MainCacheSize: 100,
962+
ProtoCacheSize: 60000,
963+
MainCacheSize: 10000,
1001964
},
1002965
)
1003966
if err != nil {

go.mod

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ require (
2828
github.com/pkg/errors v0.9.1
2929
github.com/ponyruntime/tree-sitter-markdown v0.0.2
3030
github.com/ponyruntime/tree-sitter-sql v0.0.3
31+
github.com/sergi/go-diff v1.3.1
3132
github.com/stretchr/testify v1.10.0
33+
github.com/tmc/langchaingo v0.1.13
3234
github.com/tree-sitter-grammars/tree-sitter-lua v0.2.0
3335
github.com/tree-sitter/go-tree-sitter v0.24.0
3436
github.com/tree-sitter/tree-sitter-c-sharp v0.23.1
@@ -57,11 +59,8 @@ replace github.com/yuin/gopher-lua => github.com/ponyruntime/go-lua v0.0.0-20250
5759

5860
require (
5961
buf.build/gen/go/bufbuild/protovalidate/protocolbuffers/go v1.36.6-20250425153114-8976f5be98c1.1 // indirect
60-
dario.cat/mergo v1.0.1 // indirect
6162
filippo.io/edwards25519 v1.1.0 // indirect
62-
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
6363
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
64-
github.com/Microsoft/go-winio v0.6.2 // indirect
6564
github.com/atotto/clipboard v0.1.4 // indirect
6665
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.10 // indirect
6766
github.com/aws/aws-sdk-go-v2/credentials v1.17.67 // indirect
@@ -79,71 +78,42 @@ require (
7978
github.com/aws/aws-sdk-go-v2/service/sts v1.33.19 // indirect
8079
github.com/aws/smithy-go v1.22.2 // indirect
8180
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
82-
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
8381
github.com/charmbracelet/harmonica v0.2.0 // indirect
8482
github.com/charmbracelet/x/ansi v0.7.0 // indirect
8583
github.com/charmbracelet/x/term v0.2.1 // indirect
86-
github.com/containerd/log v0.1.0 // indirect
87-
github.com/containerd/platforms v0.2.1 // indirect
88-
github.com/cpuguy83/dockercfg v0.3.2 // indirect
8984
github.com/davecgh/go-spew v1.1.1 // indirect
90-
github.com/distribution/reference v0.6.0 // indirect
91-
github.com/docker/docker v28.0.1+incompatible // indirect
92-
github.com/docker/go-connections v0.5.0 // indirect
93-
github.com/docker/go-units v0.5.0 // indirect
94-
github.com/ebitengine/purego v0.8.2 // indirect
85+
github.com/dlclark/regexp2 v1.10.0 // indirect
9586
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
96-
github.com/felixge/httpsnoop v1.0.4 // indirect
97-
github.com/go-logr/logr v1.4.2 // indirect
98-
github.com/go-logr/stdr v1.2.2 // indirect
99-
github.com/go-ole/go-ole v1.2.6 // indirect
10087
github.com/gogo/protobuf v1.3.2 // indirect
10188
github.com/google/go-cmp v0.7.0 // indirect
10289
github.com/grpc-ecosystem/grpc-gateway/v2 v2.25.1 // indirect
103-
github.com/klauspost/compress v1.17.4 // indirect
10490
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
10591
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
10692
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
107-
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
108-
github.com/magiconair/properties v1.8.10 // indirect
10993
github.com/mattn/go-isatty v0.0.20 // indirect
11094
github.com/mattn/go-localereader v0.0.1 // indirect
11195
github.com/mattn/go-pointer v0.0.1 // indirect
11296
github.com/mattn/go-runewidth v0.0.16 // indirect
113-
github.com/moby/docker-image-spec v1.3.1 // indirect
114-
github.com/moby/patternmatcher v0.6.0 // indirect
115-
github.com/moby/sys/sequential v0.5.0 // indirect
116-
github.com/moby/sys/user v0.1.0 // indirect
117-
github.com/moby/sys/userns v0.1.0 // indirect
118-
github.com/moby/term v0.5.0 // indirect
11997
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
120-
github.com/morikuni/aec v1.0.0 // indirect
12198
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
12299
github.com/muesli/cancelreader v0.2.2 // indirect
123-
github.com/opencontainers/go-digest v1.0.0 // indirect
124-
github.com/opencontainers/image-spec v1.1.1 // indirect
100+
github.com/pkoukk/tiktoken-go v0.1.6 // indirect
125101
github.com/pmezard/go-difflib v1.0.0 // indirect
126102
github.com/ponyruntime/go-lua v1.2.1 // indirect
127-
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
128103
github.com/richardlehane/mscfb v1.0.4 // indirect
129104
github.com/richardlehane/msoleps v1.0.4 // indirect
130105
github.com/rivo/uniseg v0.4.7 // indirect
131106
github.com/rogpeppe/go-internal v1.13.1 // indirect
132107
github.com/sahilm/fuzzy v0.1.1 // indirect
133-
github.com/shirou/gopsutil/v4 v4.25.1 // indirect
134-
github.com/sirupsen/logrus v1.9.3 // indirect
135-
github.com/testcontainers/testcontainers-go v0.37.0 // indirect
136-
github.com/tklauser/go-sysconf v0.3.12 // indirect
137-
github.com/tklauser/numcpus v0.6.1 // indirect
138108
github.com/xuri/efp v0.0.0-20240408161823-9ad904a10d6d // indirect
139109
github.com/xuri/nfp v0.0.0-20240318013403-ab9948c2c4a7 // indirect
140-
github.com/yusufpapurcu/wmi v1.2.4 // indirect
141-
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
142-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
110+
gitlab.com/golang-commonmark/html v0.0.0-20191124015941-a22733972181 // indirect
111+
gitlab.com/golang-commonmark/linkify v0.0.0-20191026162114-a0c2df6c8f82 // indirect
112+
gitlab.com/golang-commonmark/markdown v0.0.0-20211110145824-bf3e522c626a // indirect
113+
gitlab.com/golang-commonmark/mdurl v0.0.0-20191124015652-932350d1cb84 // indirect
114+
gitlab.com/golang-commonmark/puny v0.0.0-20191124015043-9f83538fa04f // indirect
143115
go.opentelemetry.io/otel v1.35.0 // indirect
144-
go.opentelemetry.io/otel/metric v1.35.0 // indirect
145116
go.opentelemetry.io/otel/sdk v1.34.0 // indirect
146-
go.opentelemetry.io/otel/trace v1.35.0 // indirect
147117
go.uber.org/multierr v1.11.0 // indirect
148118
golang.org/x/mod v0.18.0 // indirect
149119
golang.org/x/net v0.38.0 // indirect

0 commit comments

Comments
 (0)