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

Add support for a helia container #5

Merged
merged 1 commit into from
Oct 18, 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
57 changes: 39 additions & 18 deletions cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ var RunCommand = &cli.Command{
EnvVars: []string{"TIROS_RUN_TIMES"},
Value: 3,
},
&cli.BoolFlag{
Name: "lookup-providers",
Usage: "Whether to lookup website providers",
EnvVars: []string{"TIROS_RUN_LOOKUP_PROVIDERS"},
Value: true,
},
&cli.BoolFlag{
Name: "dry-run",
Usage: "Whether to skip DB interactions",
Expand Down Expand Up @@ -79,21 +85,21 @@ var RunCommand = &cli.Command{
EnvVars: []string{"TIROS_RUN_DATABASE_SSL_MODE"},
},
&cli.StringFlag{
Name: "kubo-host",
Usage: "port to reach the Kubo Gateway",
EnvVars: []string{"TIROS_RUN_KUBO_HOST"},
Name: "ipfs-host",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Name: "ipfs-host",
Name: "helia-host",

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this is per instance or the global name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is per instance and would point to either Kubo or Helia. That's why I renamed it. However, I can't find any usage of that config flag anyway :D

Usage: "host at which to reach the IPFS Gateway",
EnvVars: []string{"TIROS_RUN_IPFS_HOST", "TIROS_RUN_KUBO_HOST" /* <- legacy */},
Value: "localhost",
},
&cli.IntFlag{
Name: "kubo-api-port",
Usage: "port to reach the Kubo API",
EnvVars: []string{"TIROS_RUN_KUBO_API_PORT"},
Name: "ipfs-api-port",
Usage: "port to reach a Kubo-compatible RPC API",
EnvVars: []string{"TIROS_RUN_IPFS_API_PORT", "TIROS_RUN_KUBO_API_PORT" /* <- legacy */},
Value: 5001,
},
&cli.IntFlag{
Name: "kubo-gateway-port",
Usage: "port to reach the Kubo Gateway",
EnvVars: []string{"TIROS_RUN_KUBO_GATEWAY_PORT"},
Name: "ipfs-gateway-port",
Usage: "port to reach the IPFS Gateway",
EnvVars: []string{"TIROS_RUN_IPFS_GATEWAY_PORT", "TIROS_RUN_KUBO_GATEWAY_PORT" /* <- legacy */},
Value: 8080,
},
&cli.IntFlag{
Expand All @@ -119,13 +125,19 @@ var RunCommand = &cli.Command{
Usage: "Path to the Udger DB",
EnvVars: []string{"TIROS_UDGER_DB_PATH"},
},
&cli.StringFlag{
Name: "ipfs-implementation",
Usage: "Which implementation are we testing (KUBO, HELIA)",
EnvVars: []string{"TIROS_IPFS_IMPLEMENTATION"},
Value: "KUBO",
},
},
Action: RunAction,
}

type tiros struct {
dbClient IDBClient
kubo *shell.Shell
ipfs *shell.Shell
dbRun *models.Run
mmClient *maxmind.Client
uClient *udger.Client
Expand All @@ -145,8 +157,11 @@ func RunAction(c *cli.Context) error {
}
}

// Initialize kubo client
kubo := shell.NewShell(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", c.Int("kubo-api-port")))
// Initialize ipfs client
var ipfsClient *shell.Shell
if c.Int("ipfs-api-port") != 0 {
ipfsClient = shell.NewShell(fmt.Sprintf("/ip4/127.0.0.1/tcp/%d", c.Int("ipfs-api-port")))
}

// Initialize maxmind client
mmClient, err := maxmind.NewClient()
Expand All @@ -163,7 +178,7 @@ func RunAction(c *cli.Context) error {
// configure tiros struct
t := tiros{
dbClient: dbClient,
kubo: kubo,
ipfs: ipfsClient,
mmClient: mmClient,
uClient: uClient,
}
Expand All @@ -182,7 +197,7 @@ func RunAction(c *cli.Context) error {
}()

// shuffle websites, so that we have a different order in which we request the websites.
// If we didn't do this a single website would always be requested with a comparatively "cold" kubo node.
// If we didn't do this a single website would always be requested with a comparatively "cold" ipfs node.
websites := c.StringSlice("websites")
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(websites), func(i, j int) {
Expand All @@ -199,7 +214,12 @@ func RunAction(c *cli.Context) error {
probeResults := make(chan *probeResult)

go t.measureWebsites(c, websites, probeResults)
go t.findAllProviders(c, websites, providerResults)

if c.Bool("lookup-providers") {
go t.findAllProviders(c, websites, providerResults)
} else {
close(providerResults)
}

for {
select {
Expand Down Expand Up @@ -242,12 +262,13 @@ func RunAction(c *cli.Context) error {
}

func (t *tiros) InitRun(c *cli.Context) (*models.Run, error) {
version, sha, err := t.kubo.Version()
version, sha, err := t.ipfs.Version()
if err != nil {
return nil, fmt.Errorf("kubo api offline: %w", err)
return nil, fmt.Errorf("ipfs api offline: %w", err)
}

dbRun, err := t.dbClient.InsertRun(c, fmt.Sprintf("%s-%s", version, sha))
ipfsImpl := c.String("ipfs-implementation")
dbRun, err := t.dbClient.InsertRun(c, ipfsImpl, fmt.Sprintf("%s-%s", version, sha))
Comment on lines 264 to +271

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI @dennis-tra this is failing for me locally saying ERRO[0000] error: init run: ipfs api offline: version: command not found. Is this trying to call 'ipfs' binary locally to return version?

Copy link
Contributor Author

@dennis-tra dennis-tra Oct 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not using the local Kubo binary. It's using the HTTP API exposed by Kubo. In this case, the must be an endpoint that implements this specification: https://docs.ipfs.tech/reference/kubo/rpc/#api-v0-version

I thought this was already done by @whizzzkid?

if err != nil {
return nil, fmt.Errorf("insert run: %w", err)
}
Expand Down
5 changes: 3 additions & 2 deletions db_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
var migrations embed.FS

type IDBClient interface {
InsertRun(c *cli.Context, version string) (*models.Run, error)
InsertRun(c *cli.Context, ipfsImpl string, version string) (*models.Run, error)
SaveMeasurement(c *cli.Context, dbRun *models.Run, pr *probeResult) (*models.Measurement, error)
SaveProvider(c *cli.Context, dbRun *models.Run, provider *provider) (*models.Provider, error)
SealRun(ctx context.Context, dbRun *models.Run) (*models.Run, error)
Expand Down Expand Up @@ -135,7 +135,7 @@ func (db *DBClient) SealRun(ctx context.Context, dbRun *models.Run) (*models.Run
return dbRun, err
}

func (db *DBClient) InsertRun(c *cli.Context, version string) (*models.Run, error) {
func (db *DBClient) InsertRun(c *cli.Context, ipfsImpl string, version string) (*models.Run, error) {
log.Infoln("Inserting Run...")

websites := make([]string, len(c.StringSlice("websites")))
Expand All @@ -148,6 +148,7 @@ func (db *DBClient) InsertRun(c *cli.Context, version string) (*models.Run, erro
Region: c.String("region"),
Websites: websites,
Version: version,
IpfsImpl: ipfsImpl,
Times: int16(c.Int("times")),
CPU: c.Int("cpu"),
Memory: c.Int("memory"),
Expand Down
7 changes: 4 additions & 3 deletions db_dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ func (D DBDummyClient) SealRun(ctx context.Context, dbRun *models.Run) (*models.
return nil, nil
}

func (D DBDummyClient) InsertRun(c *cli.Context, version string) (*models.Run, error) {
func (D DBDummyClient) InsertRun(c *cli.Context, ipfsImpl string, version string) (*models.Run, error) {
return &models.Run{
ID: 2,
Region: "dummy",
ID: 2,
Region: "dummy",
IpfsImpl: ipfsImpl,
}, nil
}

Expand Down
7 changes: 3 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ version: "3.9"
name: tiros
services:
ipfs:
image: ipfs/kubo:v0.19.0
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean our measurement hasn't been using the latest Kubo? Will it use the latest Kubo and Helia going forward?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to indeed run the latest version of kubo and the most common one based on our measurements. In the past, this has been 0.18 and 0.19. While you're correct that we weren't running the very latest version of Kubo, his docker compose file doesn't represent our deployment. The current deployment configuration is here and with the new helia version the config looks like this

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info. I can't click through to the link. Can you please give me access?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done 👍

image: helia:latest
restart: unless-stopped
volumes:
- ipfs_path:/data/ipfs
- ipfs_fuse:/ipfs
- ipns_fuse:/ipns
environment:
DEBUG: helia-server
ports:
- "4001:4001/tcp"
- "4001:4001/udp"
- "0.0.0.0:5001:5001"
- "0.0.0.0:8080:8080"
chrome:
image: browserless/chrome:latest
Expand Down
1 change: 1 addition & 0 deletions migrations/000004_add_providers_table.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE providers;
1 change: 1 addition & 0 deletions migrations/000006_rename_kubo_measurement_type.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE measurement_type RENAME VALUE 'IPFS' TO 'KUBO';
1 change: 1 addition & 0 deletions migrations/000006_rename_kubo_measurement_type.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TYPE measurement_type RENAME VALUE 'KUBO' TO 'IPFS';
6 changes: 6 additions & 0 deletions migrations/000007_add_ipfs_impl_column_to_runs_table.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN;

ALTER TABLE runs
DROP COLUMN ipfs_impl;

COMMIT;
11 changes: 11 additions & 0 deletions migrations/000007_add_ipfs_impl_column_to_runs_table.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
BEGIN;

ALTER TABLE runs
ADD COLUMN ipfs_impl TEXT;

UPDATE runs SET ipfs_impl = 'KUBO';

ALTER TABLE runs
ALTER COLUMN ipfs_impl SET NOT NULL;

COMMIT;
4 changes: 2 additions & 2 deletions models/boil_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions models/runs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ func (t *tiros) measureWebsites(c *cli.Context, websites []string, results chan<

sleepDur := time.Duration(settle) * time.Second

log.Infof("Letting Kubo settle for %s\n", sleepDur)
log.Infof("Letting the IPFS implementation settle for %s\n", sleepDur)
time.Sleep(sleepDur)

for i := 0; i < c.Int("times"); i++ {
for _, mType := range []string{models.MeasurementTypeKUBO, models.MeasurementTypeHTTP} {
for _, mType := range []string{models.MeasurementTypeIPFS, models.MeasurementTypeHTTP} {
for _, website := range websites {

pr, err := newProbe(c, website, mType).run()
Expand All @@ -67,9 +67,9 @@ func (t *tiros) measureWebsites(c *cli.Context, websites []string, results chan<

results <- pr

if mType == models.MeasurementTypeKUBO {
if err = t.KuboGC(c.Context); err != nil {
log.WithError(err).Warnln("error running kubo gc")
if mType == models.MeasurementTypeIPFS {
if err = t.GarbageCollect(c.Context); err != nil {
log.WithError(err).Warnln("error running ipfs gc")
continue
}
}
Expand Down Expand Up @@ -98,7 +98,7 @@ type probeResult struct {
url string
website string

// measurement type (KUBO or HTTP)
// measurement type (IPFS or HTTP)
mType string
try int

Expand Down Expand Up @@ -329,17 +329,17 @@ func (p *probe) close() {

func websiteURL(c *cli.Context, website string, mType string) string {
switch mType {
case models.MeasurementTypeKUBO:
return fmt.Sprintf("http://%s:%d/ipns/%s", c.String("kubo-host"), c.Int("kubo-gateway-port"), website)
case models.MeasurementTypeIPFS:
return fmt.Sprintf("http://%s:%d/ipns/%s", c.String("ipfs-host"), c.Int("ipfs-gateway-port"), website)
case models.MeasurementTypeHTTP:
return fmt.Sprintf("https://%s", website)
default:
panic(fmt.Sprintf("unknown measurement type: %s", mType))
}
}

func (t *tiros) KuboGC(ctx context.Context) error {
return t.kubo.Request("repo/gc").Exec(ctx, nil)
func (t *tiros) GarbageCollect(ctx context.Context) error {
return t.ipfs.Request("repo/gc").Exec(ctx, nil)
}

func p2f(ptr *float64) float64 {
Expand Down
6 changes: 3 additions & 3 deletions providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (t *tiros) findProviders(ctx context.Context, website string, results chan<
logEntry := log.WithField("website", website)
logEntry.Infoln("Finding providers for", website)

nameResp, err := t.kubo.Request("name/resolve").
nameResp, err := t.ipfs.Request("name/resolve").
Option("arg", website).
Option("nocache", "true").
Option("dht-timeout", "30s").Send(ctx)
Expand Down Expand Up @@ -87,7 +87,7 @@ func (t *tiros) findProviders(ctx context.Context, website string, results chan<
return fmt.Errorf("unmarshal name/resolve response: %w", err)
}

findResp, err := t.kubo.
findResp, err := t.ipfs.
Request("routing/findprovs").
Option("arg", nrr.Path).
Option("num-providers", "1000").
Expand Down Expand Up @@ -183,7 +183,7 @@ func (t *tiros) idWorker(ctx context.Context, jobs <-chan *peer.AddrInfo, idResu
var out shell.IdOutput

tCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
err := t.kubo.Request("id", j.ID.String()).Exec(tCtx, &out)
err := t.ipfs.Request("id", j.ID.String()).Exec(tCtx, &out)
cancel()

idResults <- idResult{
Expand Down