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

Implement script to compare providers across two indexers #1251

Merged
merged 2 commits into from
Feb 8, 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
90 changes: 90 additions & 0 deletions scripts/compare_providers/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package main

import (
"context"
"flag"
"fmt"
"log"

finderhttpclient "github.com/ipni/storetheindex/api/v0/finder/client/http"
"github.com/ipni/storetheindex/api/v0/finder/model"
"github.com/libp2p/go-libp2p/core/peer"
)

type compareProvidersStats struct {
unknown uint
latestAdMismatch uint
latestAdMatch uint
totalSourceProviders uint
totalTargetProviders uint
}

func (s compareProvidersStats) print() {
fmt.Println("Stats:")
fmt.Printf(" OK: %d\n", s.latestAdMatch)
fmt.Printf(" Unknown by target: %d\n", s.unknown)
fmt.Printf(" Latest Ad Mismatch: %d\n", s.latestAdMismatch)
fmt.Println(" --------------------------")
fmt.Printf(" Total source providers: %d\n", s.totalSourceProviders)
fmt.Printf(" Total target providers: %d\n", s.totalTargetProviders)
}

func main() {
source := flag.String("source", "", "Source indexer")
target := flag.String("target", "", "Target indexer")

flag.Parse()

if *source == "" || *target == "" {
log.Fatal("both indexer instances must be specified")
}

sourceClient, err := finderhttpclient.New(*source)
if err != nil {
log.Fatal(err)
}

targetClient, err := finderhttpclient.New(*target)
if err != nil {
log.Fatal(err)
}
ctx := context.Background()

sourceProvs, err := sourceClient.ListProviders(ctx)
if err != nil {
log.Fatal(err)
}

targetProvs, err := targetClient.ListProviders(ctx)
if err != nil {
log.Fatal(err)
}

targets := make(map[peer.ID]*model.ProviderInfo)
for _, target := range targetProvs {
if target.AddrInfo.ID == "" {
continue
}
targets[target.AddrInfo.ID] = target
}
var stats compareProvidersStats
for _, p := range sourceProvs {
id := p.AddrInfo.ID
fmt.Printf("%s: ", id)
if other, exists := targets[id]; !exists {
fmt.Println("Unknown by target indexer.")
stats.unknown++
} else if p.LastAdvertisement != other.LastAdvertisement {
fmt.Println("Mismatching latest ad")
// TODO implement diagnosis of which is ahead/behind and by how many ads.
stats.latestAdMismatch++
} else {
fmt.Println("OK")
stats.latestAdMatch++
}
}
stats.totalSourceProviders = uint(len(sourceProvs))
stats.totalTargetProviders = uint(len(targetProvs))
fmt.Println()
stats.print()
}
File renamed without changes.