Skip to content

Commit

Permalink
add part_of_batch column to metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
pirtleshell committed Apr 15, 2024
1 parent 4da24a5 commit 23ed28c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE
IF EXISTS proxied_request_metrics
ADD
part_of_batch boolean NOT NULL DEFAULT false;
1 change: 1 addition & 0 deletions clients/database/request_metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type ProxiedRequestMetric struct {
ResponseBackend string
ResponseBackendRoute string
CacheHit bool
PartOfBatch bool
}

// Save saves the current ProxiedRequestMetric to
Expand Down
7 changes: 7 additions & 0 deletions service/batchmdw/batchmdw.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,10 @@ func CreateBatchProcessingMiddleware(
batchProcessor.RequestAndServe(w)
}
}

// IsBatchContext returns true when the passed in context is for a batch EVM request
func IsBatchContext(ctx context.Context, decodedBatchContextKey string) bool {
batch := ctx.Value(decodedBatchContextKey)
batchReq, ok := (batch).([]*decode.EVMRPCRequestEnvelope)
return ok && len(batchReq) > 0
}
4 changes: 4 additions & 0 deletions service/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/kava-labs/kava-proxy-service/config"
"github.com/kava-labs/kava-proxy-service/decode"
"github.com/kava-labs/kava-proxy-service/logging"
"github.com/kava-labs/kava-proxy-service/service/batchmdw"
"github.com/kava-labs/kava-proxy-service/service/cachemdw"
)

Expand Down Expand Up @@ -486,6 +487,8 @@ func createAfterProxyFinalizer(service *ProxyService, config config.Config) http
blockNumber = &rawBlockNumber
}

partOfBatch := batchmdw.IsBatchContext(r.Context(), DecodedBatchRequestContextKey)

isCached := cachemdw.IsRequestCached(r.Context())

// create a metric for the request
Expand All @@ -502,6 +505,7 @@ func createAfterProxyFinalizer(service *ProxyService, config config.Config) http
ResponseBackend: proxyMetadata.BackendName,
ResponseBackendRoute: proxyMetadata.BackendRoute.String(),
CacheHit: isCached,
PartOfBatch: partOfBatch,
}

// save metric to database async
Expand Down

0 comments on commit 23ed28c

Please sign in to comment.