Skip to content

feat: add spkg.go for handling Substreams package resolution and loading#116

Open
maoueh wants to merge 2 commits into
developfrom
feature/store-size-from-trace-id
Open

feat: add spkg.go for handling Substreams package resolution and loading#116
maoueh wants to merge 2 commits into
developfrom
feature/store-size-from-trace-id

Conversation

@maoueh
Copy link
Copy Markdown
Contributor

@maoueh maoueh commented May 4, 2026

  • Implemented ResolveAndLoadSpkg function to check for existing spkg variants and load them.
  • Added LoadSpkgFromURL function to read and parse spkg files, with validation options for older formats.
  • Created FindModuleInPackage function to locate modules by name, accommodating prefixed names.
  • Introduced SpkgPackageLabel function to generate a "name@version" label for packages.

- Implemented ResolveAndLoadSpkg function to check for existing spkg variants and load them.
- Added LoadSpkgFromURL function to read and parse spkg files, with validation options for older formats.
- Created FindModuleInPackage function to locate modules by name, accommodating prefixed names.
- Introduced SpkgPackageLabel function to generate a "name@version" label for packages.
@maoueh maoueh self-assigned this May 4, 2026
@maoueh maoueh requested a review from Copilot May 4, 2026 17:46
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds shared utilities and a new CLI subcommand to make it easier to resolve Substreams packages and inspect (or replay) Substreams requests from GCP Cloud Logging.

Changes:

  • Added spkg.go helpers to resolve/load .spkg variants, locate output modules, and format package labels.
  • Introduced tools substreams logs connection <trace-id> to print request details, stats, optional spkg URL/package label, and inferred endpoint.
  • Refactored log querying to support TraceID-based searching and expanded parsed log fields; extracted endpoint + date-range parsing into shared helpers.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
cmd/tools/substreams/spkg.go New helpers for resolving/loading spkg files and locating modules within packages.
cmd/tools/substreams/logs/types.go Extends log query options with TraceID and documents intended usage.
cmd/tools/substreams/logs/gcp_backend.go Adds TraceID-based filter mode and parses additional jsonPayload fields into LogEntry.
cmd/tools/substreams/logs/backend.go Extends LogEntry with additional request fields (session, cursor, mode flags).
cmd/tools/substreams/logs.go Registers the new logs connection subcommand.
cmd/tools/substreams/logs_reexec.go Refactors reexec log querying to use the shared logs backend + shared helpers.
cmd/tools/substreams/logs_connection.go New logs connection command implementation and selection logic for request/stats entries.
cmd/tools/substreams/logs_connection_test.go Tests for the new logs connection command and helpers.
cmd/tools/substreams/endpoint.go New shared endpoint resolution/inference helper extracted from reexec.
cmd/tools/substreams/daterange.go New shared date-range parsing helper extracted from reexec.
cmd/tools/substreams/daterange_test.go Unit tests for the new date-range parsing helper.
CHANGELOG.md Documents the new tools substreams logs connection command.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +85 to +89
var subjectFilter string
if opts.TraceID != "" {
subjectFilter = fmt.Sprintf(`SEARCH("%s")`, opts.TraceID)
} else {
subjectFilter = fmt.Sprintf(`jsonPayload.user_id="%s"`, opts.UserID)
Comment thread cmd/tools/substreams/logs_connection.go Outdated
Comment on lines +180 to +184
if request == nil || entry.Timestamp < request.Timestamp {
request = entry
}
case entry.IsRequestStats():
if stats == nil || entry.Timestamp > stats.Timestamp {
Comment on lines +312 to +316
// queryIncomingRequestByTraceID searches GCP logs for the incoming Substreams
// request matching the given trace ID. Returns the first match (oldest) and
// the total count of matches found.
func queryIncomingRequestByTraceID(ctx context.Context, gcpProject, traceID string, startTime, endTime time.Time, logger *zap.Logger) (*reexecRequest, int, error) {
backend, err := logs.NewGCPBackend(ctx, gcpProject, logger)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants