Skip to content

Commit

Permalink
Merge pull request #112 from kaleido-io/id-cache
Browse files Browse the repository at this point in the history
Use an LRU cache for the signing identities
  • Loading branch information
nguyer authored Sep 15, 2023
2 parents 37e40f3 + a2da88a commit dc3c843
Show file tree
Hide file tree
Showing 33 changed files with 752 additions and 799 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/docker_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set build tag
id: build_tag_generator
Expand All @@ -25,16 +25,16 @@ jobs:
--label build_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
--label tag=${{ steps.build_tag_generator.outputs.BUILD_TAG }} \
--tag ghcr.io/hyperledger/firefly-fabconnect:${{ steps.build_tag_generator.outputs.BUILD_TAG }} .
- name: Tag release
run: docker tag ghcr.io/hyperledger/firefly-fabconnect:${{ steps.build_tag_generator.outputs.BUILD_TAG }} ghcr.io/hyperledger/firefly-fabconnect:head

- name: Push docker image
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
docker push ghcr.io/hyperledger/firefly-fabconnect:${{ steps.build_tag_generator.outputs.BUILD_TAG }}
- name: Push head tag
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
docker push ghcr.io/hyperledger/firefly-fabconnect:head
docker push ghcr.io/hyperledger/firefly-fabconnect:head
6 changes: 2 additions & 4 deletions .github/workflows/docker_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/checkout@v3

- name: Build
run: |
Expand All @@ -30,7 +28,7 @@ jobs:
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
docker push ghcr.io/hyperledger/firefly-fabconnect:${GITHUB_REF##*/}
- name: Push head tag
run: |
echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: 1.17
go-version: "1.20"

- name: Build and Test
run: make
Expand Down
8 changes: 5 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ test: deps lint
coverage.html:
$(VGO) tool cover -html=coverage.txt
coverage: test coverage.html
lint:
GOGC=20 $(shell go list -f '{{.Target}}' github.com/golangci/golangci-lint/cmd/golangci-lint) run -v --timeout 5m
lint: ${LINT}
GOGC=20 $(LINT) run -v --timeout 5m
${LINT}:
$(VGO) install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.47.3
firefly-nocgo: ${GOFILES}
CGO_ENABLED=0 $(VGO) build -o ${BINARY_NAME}-nocgo -ldflags "-X main.buildDate=`date -u +\"%Y-%m-%dT%H:%M:%SZ\"` -X main.buildVersion=$(BUILD_VERSION)" -tags=prod -tags=prod -v
firefly: ${GOFILES}
Expand All @@ -30,7 +32,7 @@ clean:
$(VGO) clean
rm -f *.so ${BINARY_NAME}
builddeps:
$(VGO) get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.44.2
$(VGO) get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.53.3
deps: builddeps
$(VGO) get
mockery: .ALWAYS
Expand Down
66 changes: 66 additions & 0 deletions cmd/debugrouter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package cmd

import (
"net/http"
"net/http/pprof"
runtimepprof "runtime/pprof"

"github.com/julienschmidt/httprouter"
"github.com/rs/cors"
log "github.com/sirupsen/logrus"
)

type debugRouter struct {
router *httprouter.Router
}

func NewDebugRouter() *debugRouter {
r := httprouter.New()
cors.Default().Handler(r)
return &debugRouter{
router: r,
}
}

func (d *debugRouter) addRoutes() {
d.router.GET("/debug/pprof/cmdline", d.cmdline)
d.router.GET("/debug/pprof/profile", d.profile)
d.router.GET("/debug/pprof/symbol", d.symbol)
d.router.GET("/debug/pprof/trace", d.trace)
d.router.GET("/debug/pprof/goroutines", d.goroutines)
d.router.GET("/debug/pprof/", d.index)
}

func (d *debugRouter) cmdline(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
log.Infof("--> %s %s", req.Method, req.URL)
pprof.Cmdline(res, req)
}

func (d *debugRouter) profile(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
log.Infof("--> %s %s", req.Method, req.URL)
pprof.Profile(res, req)
}

func (d *debugRouter) symbol(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
log.Infof("--> %s %s", req.Method, req.URL)

pprof.Symbol(res, req)
}

func (d *debugRouter) trace(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
log.Infof("--> %s %s", req.Method, req.URL)

pprof.Trace(res, req)
}

func (d *debugRouter) index(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
log.Infof("--> %s %s", req.Method, req.URL)

pprof.Index(res, req)
}

func (d *debugRouter) goroutines(res http.ResponseWriter, req *http.Request, params httprouter.Params) {
log.Infof("--> %s %s", req.Method, req.URL)

_ = runtimepprof.Lookup("goroutine").WriteTo(res, 1)
}
21 changes: 15 additions & 6 deletions cmd/fabconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"fmt"
"net/http"
"strings"
"time"

"gopkg.in/yaml.v2"

Expand Down Expand Up @@ -94,15 +95,23 @@ func newRootCmd() (*cobra.Command, *conf.RESTGatewayConf) {

initLogging(rootConfig.DebugLevel)

return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
if rootConfig.DebugPort > 0 {
router := NewDebugRouter()
router.addRoutes()
debugServer := &http.Server{Addr: fmt.Sprintf("127.0.0.1:%d", rootConfig.DebugPort), Handler: router.router, ReadHeaderTimeout: 30 * time.Second}
go func() {
log.Debugf("Debug HTTP endpoint listening on localhost:%d: %s", rootConfig.DebugPort, http.ListenAndServe(fmt.Sprintf("localhost:%d", rootConfig.DebugPort), nil))
_ = debugServer.ListenAndServe()
}()
}
log.Infof("Debug HTTP endpoint listening on 127.0.0.1:%d", rootConfig.DebugPort)

return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
defer func() {
log.Infof("Shutting down the debug server")
_ = debugServer.Close()
}()
}
err := startServer(restGatewayConf, restGateway)
if err != nil {
return err
Expand All @@ -112,7 +121,7 @@ func newRootCmd() (*cobra.Command, *conf.RESTGatewayConf) {
}

rootCmd.Flags().IntVarP(&rootConfig.DebugLevel, "debug", "d", 1, "0=error, 1=info, 2=debug")
rootCmd.Flags().IntVarP(&rootConfig.DebugPort, "debugPort", "Z", 6060, "Port for pprof HTTP endpoints (localhost only)")
rootCmd.Flags().IntVarP(&rootConfig.DebugPort, "debugPort", "Z", 0, "Port for pprof HTTP endpoints (localhost only)")
rootCmd.Flags().BoolVarP(&rootConfig.PrintYAML, "print-yaml-confg", "Y", false, "Print YAML config snippet and exit")
rootCmd.Flags().StringVarP(&rootConfig.Filename, "configfile", "f", "", "Configuration file, must be one of .yml, .yaml, or .json")
conf.CobraInit(rootCmd, restGatewayConf)
Expand Down
18 changes: 18 additions & 0 deletions cmd/fabconnect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,21 @@ func TestKafkaSuccess(t *testing.T) {
assert.Equal([]string{"broker1", "broker2"}, restGatewayConf.Kafka.Brokers)
test.Teardown(tmpdir)
}

func TestDebugServer(t *testing.T) {
assert := assert.New(t)

tmpdir, _ := test.Setup()
rootCmd, _ := newRootCmd()
rootCmd.RunE = runNothing
args := []string{
"-f", path.Join(tmpdir, "config.json"),
"--debugPort", "6060",
}
rootCmd.SetArgs(args)
os.Unsetenv("FC_HTTP_PORT")
err := rootCmd.Execute()
assert.NoError(err)
assert.Equal(6060, rootConfig.DebugPort)
test.Teardown(tmpdir)
}
132 changes: 107 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,53 +1,135 @@
module github.com/hyperledger/firefly-fabconnect

go 1.16
go 1.20

require (
github.com/Shopify/sarama v1.29.1
github.com/frankban/quicktest v1.14.2 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8
github.com/golang/protobuf v1.5.2
github.com/golangci/golangci-lint v1.44.2 // indirect
github.com/golang/protobuf v1.5.3
github.com/google/certificate-transparency-go v1.1.1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.4.2
github.com/hashicorp/golang-lru v0.5.4
github.com/hyperledger/fabric-config v0.0.7 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.4
github.com/hyperledger/fabric-protos-go v0.0.0-20211118165945-23d738fc3553
github.com/hyperledger/fabric-sdk-go v1.0.1-0.20220617091732-e170b98fa821
github.com/julienschmidt/httprouter v1.3.0
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
github.com/oklog/ulid/v2 v2.0.2
github.com/otiai10/copy v1.6.0
github.com/pkg/errors v0.9.1
github.com/rs/cors v1.8.2
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.12.0
github.com/stretchr/testify v1.8.4
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954
github.com/x-cray/logrus-prefixed-formatter v0.5.2
github.com/xeipuuv/gojsonschema v1.2.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cloudflare/cfssl v1.4.1 // indirect
github.com/coreos/go-semver v0.3.0 // indirect
github.com/coreos/go-systemd v0.0.0-20190620071333-e64a0ec8b42a // indirect
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/eapache/go-resiliency v1.2.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/frankban/quicktest v1.14.4 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-kit/kit v0.10.0 // indirect
github.com/go-logfmt/logfmt v0.5.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/snappy v0.0.3 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.2.2 // indirect
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hyperledger/fabric-config v0.0.7 // indirect
github.com/hyperledger/fabric-lib-go v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.0.0 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/jonboulle/clockwork v0.2.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.13.5 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d
github.com/oklog/ulid/v2 v2.0.2
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/gomega v1.18.1 // indirect
github.com/otiai10/copy v1.6.0
github.com/onsi/ginkgo v1.16.4 // indirect
github.com/onsi/gomega v1.27.6 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.0 // indirect
github.com/pkg/errors v0.9.1
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pierrec/lz4 v2.6.0+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.1 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/rs/cors v1.8.2
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.4.0
github.com/spf13/viper v1.11.0
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.7.1
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/soheilhy/cmux v0.1.4 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/subosito/gotenv v1.4.1 // indirect
github.com/tmc/grpc-websocket-proxy v0.0.0-20200427203606-3cfed13b9966 // indirect
github.com/urfave/cli v1.22.2 // indirect
github.com/x-cray/logrus-prefixed-formatter v0.5.2
github.com/xeipuuv/gojsonschema v1.2.0
github.com/weppos/publicsuffix-go v0.5.0 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
github.com/zmap/zcrypto v0.0.0-20190729165852-9051775e6a2e // indirect
github.com/zmap/zlint v0.0.0-20190806154020-fd021b4cfbeb // indirect
go.etcd.io/bbolt v1.3.5 // indirect
go.etcd.io/etcd v0.5.0-alpha.5.0.20200910180754-dd1b699fc489 // indirect
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.24.0 // indirect
golang.org/x/crypto v0.9.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
golang.org/x/tools v0.1.11-0.20220316014157-77aa08bb151a // indirect
gopkg.in/yaml.v2 v2.4.0
golang.org/x/tools v0.9.3 // indirect
google.golang.org/genproto v0.0.0-20220519153652-3a47de7e79bd // indirect
google.golang.org/grpc v1.46.2 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/cheggaaa/pb.v1 v1.0.28 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)

Expand Down
Loading

0 comments on commit dc3c843

Please sign in to comment.