-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
metering updates. add substreams_metering_events to prometheus and so…
…me integration tests
- Loading branch information
1 parent
f76f2b1
commit 9b24472
Showing
8 changed files
with
101 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,70 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/streamingfast/dmetering" | ||
"github.com/streamingfast/substreams" | ||
"github.com/streamingfast/substreams/metering" | ||
pbssinternal "github.com/streamingfast/substreams/pb/sf/substreams/intern/v2" | ||
pbsubstreamsrpc "github.com/streamingfast/substreams/pb/sf/substreams/rpc/v2" | ||
"github.com/streamingfast/substreams/reqctx" | ||
) | ||
|
||
type eventsCollector struct { | ||
events []dmetering.Event | ||
} | ||
|
||
func (c *eventsCollector) Emit(_ context.Context, ev dmetering.Event) { | ||
c.events = append(c.events, ev) | ||
} | ||
|
||
func (c *eventsCollector) Shutdown(_ error) { | ||
return | ||
} | ||
|
||
func (c *eventsCollector) Events() []dmetering.Event { | ||
return c.events | ||
} | ||
|
||
var eventsCollectorKey = "eventsCollector" | ||
|
||
func withEventsCollector(ctx context.Context, collector *eventsCollector) context.Context { | ||
return context.WithValue(ctx, eventsCollectorKey, collector) | ||
} | ||
|
||
func eventsCollectorFromContext(ctx context.Context) *eventsCollector { | ||
if ev, ok := ctx.Value(eventsCollectorKey).(*eventsCollector); ok { | ||
return ev | ||
} | ||
return &eventsCollector{} | ||
} | ||
|
||
type responseCollector struct { | ||
*eventsCollector | ||
|
||
responses []*pbsubstreamsrpc.Response | ||
internalResponses []*pbssinternal.ProcessRangeResponse | ||
|
||
ctx context.Context | ||
} | ||
|
||
func newResponseCollector() *responseCollector { | ||
return &responseCollector{} | ||
func newResponseCollector(ctx context.Context) *responseCollector { | ||
rc := &responseCollector{} | ||
rc.ctx = reqctx.WithEmitter(ctx, rc) | ||
rc.eventsCollector = eventsCollectorFromContext(ctx) | ||
|
||
return rc | ||
} | ||
|
||
func (c *responseCollector) Collect(respAny substreams.ResponseFromAnyTier) error { | ||
switch resp := respAny.(type) { | ||
case *pbsubstreamsrpc.Response: | ||
c.responses = append(c.responses, resp) | ||
metering.Send(c.ctx, "test_user", "test_api_key", "10.0.0.1", "test_meta", "tier1", resp) | ||
case *pbssinternal.ProcessRangeResponse: | ||
c.internalResponses = append(c.internalResponses, resp) | ||
metering.Send(c.ctx, "test_user", "test_api_key", "10.0.0.1", "test_meta", "tier2", resp) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters