Skip to content

Commit

Permalink
Enable CI for badger and grpc-plugin (#2474)
Browse files Browse the repository at this point in the history
* Enable CI for badger and grpc-plugin

Signed-off-by: Yuri Shkuro <[email protected]>

* refactor

Signed-off-by: Yuri Shkuro <[email protected]>

* fmt

Signed-off-by: Yuri Shkuro <[email protected]>

* test

Signed-off-by: Yuri Shkuro <[email protected]>
  • Loading branch information
yurishkuro authored Sep 13, 2020
1 parent a8e83cd commit df2582d
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 44 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ matrix:
- go: "1.15.x"
env:
- CASSANDRA_INTEGRATION_TEST=true
- go: "1.15.x"
env:
- MEM_AND_BADGER_INTEGRATION_TEST=true
- go: "1.15.x"
env:
- HOTROD=true
Expand All @@ -63,6 +66,7 @@ install:
script:
- export BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi)
- if [ "$TESTS" == true ]; then make test-ci ; else echo 'skipping tests'; fi
- if [ "$PROTO_GEN_TEST" == true ]; then make proto && git diff --name-status --exit-code ; else echo 'skipping protoc validation'; fi
- if [ "$ALL_IN_ONE" == true ]; then bash ./scripts/travis/build-all-in-one-image.sh ; else echo 'skipping all_in_one'; fi
- if [ "$CROSSDOCK" == true ]; then bash ./scripts/travis/build-crossdock.sh ; else echo 'skipping crossdock'; fi
- if [ "$CROSSDOCK_OTEL" == true ]; then make build-crossdock crossdock-otel ; else echo 'skipping OpenTelemetry crossdock'; fi
Expand All @@ -73,8 +77,8 @@ script:
- if [ "$ES_OTEL_INTEGRATION_TEST" == true ]; then bash ./scripts/travis/es-integration-test.sh ; else echo 'skipping elastic search integration test'; fi
- if [ "$KAFKA_INTEGRATION_TEST" == true ]; then bash ./scripts/travis/kafka-integration-test.sh ; else echo 'skipping kafka integration test'; fi
- if [ "$CASSANDRA_INTEGRATION_TEST" == true ]; then bash ./scripts/travis/cassandra-integration-test.sh ; else echo 'skipping cassandra integration test'; fi
- if [ "$MEM_AND_BADGER_INTEGRATION_TEST" == true ]; then make mem-and-badger-storage-integration-test ; else echo 'skipping mem and badger integration test'; fi
- if [ "$HOTROD" == true ]; then bash ./scripts/travis/hotrod-integration-test.sh ; else echo 'skipping hotrod example'; fi
- if [ "$PROTO_GEN_TEST" == true ]; then make proto && git diff --name-status --exit-code ; else echo 'skipping protoc validation'; fi

after_success:
- if [ "$COVERAGE" == true ]; then mv cover.out coverage.txt ; else echo 'skipping coverage'; fi
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ storage-integration-test: go-gen
go clean -testcache
bash -c "set -e; set -o pipefail; $(GOTEST) $(STORAGE_PKGS) | $(COLORIZE)"

.PHONY: mem-and-badger-storage-integration-test
mem-and-badger-storage-integration-test: badger-storage-integration-test grpc-plugin-storage-integration-test

.PHONY: badger-storage-integration-test
badger-storage-integration-test:
STORAGE=badger $(MAKE) storage-integration-test

.PHONY: grpc-plugin-storage-integration-test
grpc-plugin-storage-integration-test:
(cd examples/memstore-plugin/ && go build .)
STORAGE=grpc-plugin $(MAKE) storage-integration-test

.PHONY: es-otel-exporter-integration-test
es-otel-exporter-integration-test: go-gen
go clean -testcache
Expand Down
12 changes: 6 additions & 6 deletions plugin/storage/grpc/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ import (
"github.com/jaegertracing/jaeger/plugin/storage/grpc/shared"
)

// Configuration describes the options to customize the storage behavior
// Configuration describes the options to customize the storage behavior.
type Configuration struct {
PluginBinary string `yaml:"binary" mapstructure:"binary"`
PluginConfigurationFile string `yaml:"configuration-file" mapstructure:"configuration_file"`
PluginLogLevel string `yaml:"log-level" mapstructure:"log_level"`
}

// PluginBuilder is used to create storage plugins. Implemented by Configuration.
type PluginBuilder interface {
Build() (shared.StoragePlugin, error)
}

// Build instantiates a StoragePlugin
func (c *Configuration) Build() (shared.StoragePlugin, error) {
// #nosec G204
Expand Down Expand Up @@ -70,8 +75,3 @@ func (c *Configuration) Build() (shared.StoragePlugin, error) {

return storagePlugin, nil
}

// PluginBuilder is used to create storage plugins
type PluginBuilder interface {
Build() (shared.StoragePlugin, error)
}
3 changes: 2 additions & 1 deletion plugin/storage/grpc/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package grpc

import (
"flag"
"fmt"

"github.com/spf13/viper"
"github.com/uber/jaeger-lib/metrics"
Expand Down Expand Up @@ -66,7 +67,7 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)

store, err := f.builder.Build()
if err != nil {
return err
return fmt.Errorf("grpc-plugin builder failed to create a store: %w", err)
}

f.store = store
Expand Down
5 changes: 4 additions & 1 deletion plugin/storage/grpc/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/spf13/viper"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/uber/jaeger-lib/metrics"
"go.uber.org/zap"

Expand Down Expand Up @@ -75,7 +76,9 @@ func TestGRPCStorageFactory(t *testing.T) {
f.builder = &mockPluginBuilder{
err: errors.New("made-up error"),
}
assert.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "made-up error")
err := f.Initialize(metrics.NullFactory, zap.NewNop())
require.Error(t, err)
assert.Contains(t, err.Error(), "made-up error")

f.builder = &mockPluginBuilder{
plugin: &mockPlugin{
Expand Down
30 changes: 0 additions & 30 deletions plugin/storage/grpc/shared/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
package shared

import (
"context"

"github.com/hashicorp/go-plugin"
"google.golang.org/grpc"

"github.com/jaegertracing/jaeger/proto-gen/storage_v1"
"github.com/jaegertracing/jaeger/storage/dependencystore"
"github.com/jaegertracing/jaeger/storage/spanstore"
)
Expand All @@ -45,29 +41,3 @@ type StoragePlugin interface {
SpanWriter() spanstore.Writer
DependencyReader() dependencystore.Reader
}

// StorageGRPCPlugin is the implementation of plugin.GRPCPlugin so we can serve/consume this.
type StorageGRPCPlugin struct {
plugin.Plugin
// Concrete implementation, written in Go. This is only used for plugins
// that are written in Go.
Impl StoragePlugin
}

// GRPCServer is used by go-plugin to create a grpc plugin server
func (p *StorageGRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
server := &grpcServer{Impl: p.Impl}
storage_v1.RegisterSpanReaderPluginServer(s, server)
storage_v1.RegisterSpanWriterPluginServer(s, server)
storage_v1.RegisterDependenciesReaderPluginServer(s, server)
return nil
}

// GRPCClient is used by go-plugin to create a grpc plugin client
func (*StorageGRPCPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return &grpcClient{
readerClient: storage_v1.NewSpanReaderPluginClient(c),
writerClient: storage_v1.NewSpanWriterPluginClient(c),
depsReaderClient: storage_v1.NewDependenciesReaderPluginClient(c),
}, nil
}
53 changes: 53 additions & 0 deletions plugin/storage/grpc/shared/plugin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2020 The Jaeger Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package shared

import (
"context"

"github.com/hashicorp/go-plugin"
"google.golang.org/grpc"

"github.com/jaegertracing/jaeger/proto-gen/storage_v1"
)

// Ensure plugin.GRPCPlugin API match.
var _ plugin.GRPCPlugin = (*StorageGRPCPlugin)(nil)

// StorageGRPCPlugin is the implementation of plugin.GRPCPlugin.
type StorageGRPCPlugin struct {
plugin.Plugin

// Concrete implementation, This is only used for plugins that are written in Go.
Impl StoragePlugin
}

// GRPCServer implements plugin.GRPCPlugin. It is used by go-plugin to create a grpc plugin server.
func (p *StorageGRPCPlugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
server := &grpcServer{Impl: p.Impl}
storage_v1.RegisterSpanReaderPluginServer(s, server)
storage_v1.RegisterSpanWriterPluginServer(s, server)
storage_v1.RegisterDependenciesReaderPluginServer(s, server)
return nil
}

// GRPCClient implements plugin.GRPCPlugin. It is used by go-plugin to create a grpc plugin client.
func (*StorageGRPCPlugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
return &grpcClient{
readerClient: storage_v1.NewSpanReaderPluginClient(c),
writerClient: storage_v1.NewSpanWriterPluginClient(c),
depsReaderClient: storage_v1.NewDependenciesReaderPluginClient(c),
}, nil
}
18 changes: 13 additions & 5 deletions plugin/storage/integration/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,22 @@ import (
"github.com/jaegertracing/jaeger/plugin/storage/grpc"
)

const defaultPluginBinaryPath = "../../../examples/memstore-plugin/memstore-plugin"

type GRPCStorageIntegrationTestSuite struct {
StorageIntegration
logger *zap.Logger
logger *zap.Logger
pluginBinaryPath string
}

func (s *GRPCStorageIntegrationTestSuite) initialize() error {
s.logger, _ = testutils.NewLogger()
gopath := os.Getenv("GOPATH")
path := gopath + "/src/github.com/jaegertracing/jaeger/examples/memstore-plugin/memstore-plugin"

f := grpc.NewFactory()
v, command := config.Viperize(f.AddFlags)
err := command.ParseFlags([]string{
"--grpc-storage-plugin.binary",
path,
s.pluginBinaryPath,
})
if err != nil {
return err
Expand Down Expand Up @@ -78,7 +79,14 @@ func TestGRPCStorage(t *testing.T) {
if os.Getenv("STORAGE") != "grpc-plugin" {
t.Skip("Integration test against grpc skipped; set STORAGE env var to grpc-plugin to run this")
}
s := &GRPCStorageIntegrationTestSuite{}
path := os.Getenv("PLUGIN_BINARY_PATH")
if path == "" {
t.Logf("PLUGIN_BINARY_PATH env var not set, using %s", defaultPluginBinaryPath)
path = defaultPluginBinaryPath
}
s := &GRPCStorageIntegrationTestSuite{
pluginBinaryPath: path,
}
require.NoError(t, s.initialize())
s.IntegrationTestAll(t)
}

0 comments on commit df2582d

Please sign in to comment.