Re-vendor the shared files from sneak/prompts at 0653579 (closes #52)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
Takes .golangci.yml, .dockerignore, .gitignore, .editorconfig, the workflow and REPO_POLICIES.md from sneak/prompts 0653579, with this repository's own entries after the shared content. Lint (golangci-lint v2.14.0) and test are Dockerfile phases that script/lint and script/test build alone with a new CACHEBUST value, keeping Go's and golangci-lint's caches; the image build depends on both. make fmt and make fmt-check also format the markdown with prettier, pinned in yarn.lock. The agent guidance moves to AGENTS.md. The Go code is fixed for what the new configuration finds, and the AS and prefix detail reads now return the rows' error after their loops. Model: opus-5-5
This commit was merged in pull request #85.
This commit is contained in:
@@ -33,8 +33,10 @@ type liveCounts struct {
|
||||
|
||||
// seed sets every count to the value read from the tables at startup. It runs
|
||||
// before any writer, so it needs no coordination with the adjust methods.
|
||||
func (c *liveCounts) seed(asns, prefixesV4, prefixesV6, peerings, peers, routesV4, routesV6 int,
|
||||
distributionV4, distributionV6 []PrefixDistribution) {
|
||||
func (c *liveCounts) seed(
|
||||
asns, prefixesV4, prefixesV6, peerings, peers, routesV4, routesV6 int,
|
||||
distributionV4, distributionV6 []PrefixDistribution,
|
||||
) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
@@ -45,9 +47,11 @@ func (c *liveCounts) seed(asns, prefixesV4, prefixesV6, peerings, peers, routesV
|
||||
c.peers = peers
|
||||
c.routesV4 = routesV4
|
||||
c.routesV6 = routesV6
|
||||
|
||||
for _, entry := range distributionV4 {
|
||||
addAtMaskLength(c.distributionV4[:], entry.MaskLength, entry.Count)
|
||||
}
|
||||
|
||||
for _, entry := range distributionV6 {
|
||||
addAtMaskLength(c.distributionV6[:], entry.MaskLength, entry.Count)
|
||||
}
|
||||
@@ -102,6 +106,7 @@ func (c *liveCounts) addToDistribution(maskLengthsV4, maskLengthsV6 []int, n int
|
||||
for _, maskLength := range maskLengthsV4 {
|
||||
addAtMaskLength(c.distributionV4[:], maskLength, n)
|
||||
}
|
||||
|
||||
for _, maskLength := range maskLengthsV6 {
|
||||
addAtMaskLength(c.distributionV6[:], maskLength, n)
|
||||
}
|
||||
@@ -138,9 +143,11 @@ func (c *liveCounts) fill(s *Stats) {
|
||||
// ascending order, the way the distribution query returns them.
|
||||
func distributionList(counts []int) []PrefixDistribution {
|
||||
var list []PrefixDistribution
|
||||
|
||||
for maskLength, count := range counts {
|
||||
if count > 0 {
|
||||
list = append(list, PrefixDistribution{MaskLength: maskLength, Count: count})
|
||||
list = append(list,
|
||||
PrefixDistribution{MaskLength: maskLength, Count: count})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +159,8 @@ func distributionList(counts []int) []PrefixDistribution {
|
||||
func (d *Database) countRows(ctx context.Context, table string) (int, error) {
|
||||
var n int
|
||||
// table is one of a fixed set of literals below, never external input.
|
||||
if err := d.db.QueryRowContext(ctx, "SELECT COUNT(*) FROM "+table).Scan(&n); err != nil {
|
||||
err := d.db.QueryRowContext(ctx, "SELECT COUNT(*) FROM "+table).Scan(&n)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("failed to count %s: %w", table, err)
|
||||
}
|
||||
|
||||
@@ -167,30 +175,37 @@ func (d *Database) seedCounts(ctx context.Context) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
prefixesV4, err := d.countRows(ctx, "prefixes_v4")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
prefixesV6, err := d.countRows(ctx, "prefixes_v6")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
peerings, err := d.countRows(ctx, "peerings")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
peers, err := d.countRows(ctx, "bgp_peers")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
routesV4, err := d.countRows(ctx, "live_routes_v4")
|
||||
|
||||
routesV4, err := d.countRows(ctx, tableLiveRoutesV4)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
routesV6, err := d.countRows(ctx, "live_routes_v6")
|
||||
|
||||
routesV6, err := d.countRows(ctx, tableLiveRoutesV6)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
distributionV4, distributionV6, err := d.GetPrefixDistributionContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user