Skip to content

Commit

Permalink
Grpc instrumentation (#153)
Browse files Browse the repository at this point in the history
* use flowkit not flow-cli/flowkit and allow dial options

* do not calculate system chunk tx if we are on emulator

* use flowkit commit now that my pr has been merged, still waiting on tag

* use latest version

* tidy
  • Loading branch information
bjartek authored Feb 16, 2024
1 parent 708c99c commit 6e86330
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion event_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/onflow/flow-cli/flowkit"
"github.com/onflow/flowkit"
)

// Event fetching
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ require (
github.com/fatih/structtag v1.2.0
github.com/hexops/autogold v1.3.1
github.com/onflow/cadence v0.42.6
github.com/onflow/flow-cli/flowkit v1.13.0
github.com/onflow/flow-emulator v0.59.0
github.com/onflow/flow-go v0.32.4-0.20231130134727-3c01c7f8966c
github.com/onflow/flow-go-sdk v0.41.17
github.com/onflow/flowkit v1.13.1-0.20240215185900-f0376cec0213
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.29.1
github.com/samber/lo v1.38.1
Expand All @@ -22,6 +22,7 @@ require (
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb
go.uber.org/zap v1.26.0
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
google.golang.org/grpc v1.59.0
)

require (
Expand Down Expand Up @@ -206,7 +207,6 @@ require (
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,6 @@ github.com/onflow/atree v0.6.0/go.mod h1:gBHU0M05qCbv9NN0kijLWMgC47gHVNBIp4KmsVF
github.com/onflow/cadence v0.20.1/go.mod h1:7mzUvPZUIJztIbr9eTvs+fQjWWHTF8veC+yk4ihcNIA=
github.com/onflow/cadence v0.42.6 h1:VtI0EpKrdbfqITRMsvyZC4dhgcW1x1LNUQuEpdMDzus=
github.com/onflow/cadence v0.42.6/go.mod h1:raU8va8QRyTa/eUbhej4mbyW2ETePfSaywoo36MddgE=
github.com/onflow/flow-cli/flowkit v1.13.0 h1:hhhinYkGknKByajdU0sEbCNdj/hBN8WnLt1sYPKBXhM=
github.com/onflow/flow-cli/flowkit v1.13.0/go.mod h1:aH4shan7Ggxd0GIXZD2S4kYMemNfzP1rLWvzKnb6K3g=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20231016154253-a00dbf7c061f h1:S8yIZw9LFXfYD1V5H9BiixihHw3GrXVPrmfplSzYaww=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20231016154253-a00dbf7c061f/go.mod h1:jM6GMAL+m0hjusUgiYDNrixPQ6b9s8xjoJQoEu5bHQI=
github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20231016154253-a00dbf7c061f h1:Ep+Mpo2miWMe4pjPGIaEvEzshRep30dvNgxqk+//FrQ=
Expand All @@ -694,6 +692,8 @@ github.com/onflow/flow-nft/lib/go/contracts v1.1.0/go.mod h1:YsvzYng4htDgRB9sa9j
github.com/onflow/flow/protobuf/go/flow v0.2.2/go.mod h1:gQxYqCfkI8lpnKsmIjwtN2mV/N2PIwc1I+RUK4HPIc8=
github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20231124194313-106cc495def6 h1:KMN+OEVaw7KAgxL3p8ux7CMuyTvacAlYTbasOqowh4M=
github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20231124194313-106cc495def6/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk=
github.com/onflow/flowkit v1.13.1-0.20240215185900-f0376cec0213 h1:ByMhhs3Eql/xFbalQn1JS+t4XSey0gNbOcX+dKKoDCc=
github.com/onflow/flowkit v1.13.1-0.20240215185900-f0376cec0213/go.mod h1:V1vMr/51HpLT8oWw/zoFsLs33ibG8FNeoNbA5SGTHf8=
github.com/onflow/nft-storefront/lib/go/contracts v0.0.0-20221222181731-14b90207cead h1:2j1Unqs76Z1b95Gu4C3Y28hzNUHBix7wL490e61SMSw=
github.com/onflow/nft-storefront/lib/go/contracts v0.0.0-20221222181731-14b90207cead/go.mod h1:E3ScfQb5XcWJCIAdtIeEnr5i5l2y60GT0BTXeIHseWg=
github.com/onflow/sdks v0.5.0 h1:2HCRibwqDaQ1c9oUApnkZtEAhWiNY2GTpRD5+ftdkN8=
Expand Down
6 changes: 3 additions & 3 deletions interaction_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (

"github.com/enescakir/emoji"
"github.com/onflow/cadence"

Check failure on line 11 in interaction_builder.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
"github.com/onflow/flow-cli/flowkit"
"github.com/onflow/flow-cli/flowkit/accounts"
"github.com/onflow/flow-cli/flowkit/transactions"
"github.com/onflow/flowkit"
"github.com/onflow/flowkit/accounts"
"github.com/onflow/flowkit/transactions"
"github.com/onflow/flow-go-sdk"
"github.com/pkg/errors"
)
Expand Down
2 changes: 1 addition & 1 deletion mocks/OverflowBetaClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mocks/OverflowClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion script.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/fatih/color"
"github.com/hexops/autogold"
"github.com/onflow/cadence"
"github.com/onflow/flow-cli/flowkit"
"github.com/onflow/flowkit"
"github.com/pkg/errors"
"github.com/sanity-io/litter"
"github.com/stretchr/testify/assert"
Expand Down
18 changes: 13 additions & 5 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ import (
"strconv"

"github.com/onflow/cadence/runtime"
"github.com/onflow/flow-cli/flowkit"
"github.com/onflow/flow-cli/flowkit/config"
"github.com/onflow/flow-cli/flowkit/gateway"
"github.com/onflow/flow-cli/flowkit/output"
"github.com/onflow/flow-emulator/emulator"
"github.com/onflow/flow-go/fvm/blueprints"
fm "github.com/onflow/flow-go/model/flow"
"github.com/onflow/flowkit"
"github.com/onflow/flowkit/config"
"github.com/onflow/flowkit/gateway"
"github.com/onflow/flowkit/output"
"github.com/pkg/errors"
"github.com/rs/zerolog"
"google.golang.org/grpc"

"github.com/spf13/afero"
)
Expand Down Expand Up @@ -107,6 +108,7 @@ type OverflowBuilder struct {
InputResolver *InputResolver
ArchiveNodeUrl string
Coverage *runtime.CoverageReport
GrpcDialOptions []grpc.DialOption
EmulatorOptions []emulator.Option
}

Expand Down Expand Up @@ -231,7 +233,7 @@ func (o *OverflowBuilder) StartResult() *OverflowState {
overflow.EmulatorGatway = gw
overflow.Flowkit = flowkit.NewFlowkit(state, *network, gw, logger)
} else {
gw, err := gateway.NewGrpcGateway(*network)
gw, err := gateway.NewGrpcGateway(*network, o.GrpcDialOptions...)
if err != nil {
overflow.Error = err
return overflow
Expand Down Expand Up @@ -512,6 +514,12 @@ func WithArchiveNodeUrl(url string) OverflowOption {
}
}

func WithGrpcDialOption(opt ...grpc.DialOption) OverflowOption {
return func(o *OverflowBuilder) {
o.GrpcDialOptions = append(o.GrpcDialOptions, opt...)
}
}

func WithCoverageReport() OverflowOption {
return func(o *OverflowBuilder) {
o.Coverage = runtime.NewCoverageReport()
Expand Down
2 changes: 1 addition & 1 deletion setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package overflow
import (
"testing"

"github.com/onflow/flow-cli/flowkit/output"
"github.com/onflow/flowkit/output"
"github.com/stretchr/testify/assert"
)

Expand Down
12 changes: 6 additions & 6 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import (
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/interpreter"
"github.com/onflow/cadence/runtime/sema"

Check failure on line 23 in state.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
"github.com/onflow/flow-cli/flowkit"
"github.com/onflow/flow-cli/flowkit/accounts"
"github.com/onflow/flow-cli/flowkit/config"
"github.com/onflow/flow-cli/flowkit/gateway"
"github.com/onflow/flow-cli/flowkit/output"
"github.com/onflow/flow-cli/flowkit/project"
"github.com/onflow/flowkit"
"github.com/onflow/flowkit/accounts"
"github.com/onflow/flowkit/config"
"github.com/onflow/flowkit/gateway"
"github.com/onflow/flowkit/output"
"github.com/onflow/flowkit/project"
"github.com/onflow/flow-go-sdk"
"github.com/pkg/errors"
"go.uber.org/zap"
Expand Down
12 changes: 3 additions & 9 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,7 @@ func (o *OverflowState) GetTransactions(ctx context.Context, id flow.Identifier,

tx, txR, err := o.Flowkit.GetTransactionsByBlockID(ctx, id)
if err != nil {
if logg != nil {
logg.Debug("retry getting transactions")
}
time.Sleep(time.Millisecond * 200)
tx, txR, err = o.Flowkit.GetTransactionsByBlockID(ctx, id)
if err != nil {
return nil, nil, errors.Wrap(err, "getting transaction results")
}
return nil, nil, errors.Wrap(err, "getting transaction results")
}

logg.Debug("Fetched tx", zap.String("blockId", id.String()), zap.Int("tx", len(tx)), zap.Int("txR", len(txR)))
Expand All @@ -197,7 +190,8 @@ func (o *OverflowState) GetTransactions(ctx context.Context, id flow.Identifier,
result := lo.FlatMap(txR, func(rp *flow.TransactionResult, i int) []OverflowTransaction {
r := *rp
isLatestResult := totalTxR == i+1
if isLatestResult {
// on network emulator we never have system chunk transactions it looks like
if isLatestResult && o.GetNetwork() != "emulator" {
systemChunkEvents, _ = parseEvents(r.Events, fmt.Sprintf("%d-", r.BlockHeight))
if len(systemChunkEvents) > 0 {
logg.Debug("We have system chunk events", zap.Int("systemEvents", len(systemChunkEvents)))
Expand Down

0 comments on commit 6e86330

Please sign in to comment.