Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2pg: rebuild dashboard #181

Merged
merged 10 commits into from
Oct 14, 2023
Merged
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
6 changes: 5 additions & 1 deletion abi2/abi2.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ type coldef struct {

// Implements the [e2pg.Integration] interface
type Integration struct {
name string
Event Event
Table Table
Columns []string
Expand Down Expand Up @@ -585,8 +586,9 @@ type Integration struct {
// For example:
//
// {"name": "my_column", "type": "db_type", "filter_op": "contains", "filter_arg": ["0x000"]}
func New(ev Event, bd []BlockData, table Table) (Integration, error) {
func New(name string, ev Event, bd []BlockData, table Table) (Integration, error) {
ig := Integration{
name: name,
Event: ev,
Table: table,
numIndexed: ev.numIndexed(),
Expand Down Expand Up @@ -636,6 +638,8 @@ func col(t Table, name string) (Column, error) {
return Column{}, fmt.Errorf("table %q doesn't contain column %q", t.Name, name)
}

func (ig Integration) Name() string { return ig.name }

func (ig Integration) Events(context.Context) [][]byte { return [][]byte{} }

func (ig Integration) Delete(context.Context, wpg.Conn, uint64) error { return nil }
Expand Down
175 changes: 0 additions & 175 deletions cmd/e2pg/dashboard.go

This file was deleted.

34 changes: 18 additions & 16 deletions cmd/e2pg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"time"

"github.com/indexsupply/x/e2pg"
"github.com/indexsupply/x/e2pg/web"
"github.com/indexsupply/x/pgmig"
"github.com/indexsupply/x/wctx"
"github.com/indexsupply/x/wos"
Expand Down Expand Up @@ -43,7 +44,6 @@ func main() {
version bool
)
flag.StringVar(&cfile, "config", "", "task config file")

flag.BoolVar(&skipMigrate, "skip-migrate", false, "do not run db migrations on startup")
flag.StringVar(&listen, "l", ":8546", "dashboard server listen address")
flag.BoolVar(&notx, "notx", false, "disable pg tx")
Expand Down Expand Up @@ -77,36 +77,37 @@ func main() {
os.Exit(0)
}

var conf e2pg.Config
var (
conf e2pg.Config
pgurl string
)
switch {
case cfile == "":
fmt.Printf("missing config file\n")
os.Exit(1)
pgurl = os.Getenv("DATABASE_URL")
case cfile != "":
f, err := os.Open(cfile)
check(err)
check(json.NewDecoder(f).Decode(&conf))
pgurl = wos.Getenv(conf.PGURL)
}

if !skipMigrate {
migdb, err := pgxpool.New(ctx, wos.Getenv(conf.PGURL))
migdb, err := pgxpool.New(ctx, pgurl)
check(err)
check(pgmig.Migrate(migdb, e2pg.Migrations))
migdb.Close()
}

pg, err := pgxpool.New(ctx, wos.Getenv(conf.PGURL))
pg, err := pgxpool.New(ctx, pgurl)
check(err)

var (
pbuf bytes.Buffer
snaps = make(chan e2pg.StatusSnapshot)
tskmgr = e2pg.NewManager(pg, snaps, conf)
dh = newDashHandler(tskmgr, snaps)
pbuf bytes.Buffer
mgr = e2pg.NewManager(pg, conf)
wh = web.New(mgr, &conf, pg)
)
mux := http.NewServeMux()
mux.HandleFunc("/", dh.Index)
mux.HandleFunc("/updates", dh.Updates)
mux.HandleFunc("/", wh.Index)
mux.HandleFunc("/task-updates", wh.Updates)
mux.HandleFunc("/debug/pprof/", npprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", npprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", npprof.Profile)
Expand All @@ -120,15 +121,16 @@ func main() {
if profile == "cpu" {
check(pprof.StartCPUProfile(&pbuf))
}
tskmgr.Run()

go mgr.Run()

switch profile {
case "cpu":
pprof.StopCPUProfile()
select {}
case "heap":
check(pprof.Lookup("heap").WriteTo(&pbuf, 0))
select {}
}
select {}
}

func log(v bool, h http.Handler) http.Handler {
Expand Down
Loading