Skip to content

Commit

Permalink
Send User-Agent header with commit hash
Browse files Browse the repository at this point in the history
  • Loading branch information
vegarsti committed Jul 1, 2024
1 parent 5d6b524 commit f472ff0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@
# Go workspace file
go.work
go.work.sum

# Binary
indexer
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bin/gofumpt: bin
GOBIN=$(PWD)/bin go install mvdan.cc/gofumpt@v0.6.0

build: cmd/main.go
CGO_ENABLED=0 go build -o indexer cmd/main.go
CGO_ENABLED=0 go build -ldflags="-X github.com/duneanalytics/blockchain-ingester/client/duneapi.commitHash=$(shell git rev-parse HEAD)" -o indexer cmd/main.go

lint: bin/golangci-lint bin/gofumpt
go fmt ./...
Expand Down
5 changes: 5 additions & 0 deletions client/duneapi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ func (c *client) buildRequest(payloads []models.RPCBlock, buffer *bytes.Buffer)
return request, nil
}

// We inject the commit hash here at build time, using the -X linker flag, so we can use it in the User-Agent header
var commitHash string
var userAgent = fmt.Sprintf("node-indexer/%s", commitHash)

func (c *client) sendRequest(ctx context.Context, request BlockchainIngestRequest) error {
start := time.Now()
var err error
Expand Down Expand Up @@ -172,6 +176,7 @@ func (c *client) sendRequest(ctx context.Context, request BlockchainIngestReques
req.Header.Set("Content-Encoding", request.ContentEncoding)
}
req.Header.Set("Content-Type", "application/x-ndjson")
req.Header.Set("User-Agent", userAgent)
req.Header.Set("x-idempotency-key", request.IdempotencyKey)
req.Header.Set("x-dune-evm-stack", request.EVMStack)
req.Header.Set("x-dune-api-key", c.cfg.APIKey)
Expand Down

0 comments on commit f472ff0

Please sign in to comment.