Skip to content

Commit

Permalink
Initial structure for the in-memory storage (jaegertracing#2882)
Browse files Browse the repository at this point in the history
Partial solution to jaegertracing#2881

Signed-off-by: Juraci Paixão Kröhling <[email protected]>
  • Loading branch information
jpkrohling authored Mar 17, 2021
1 parent 915d3af commit 40e96f9
Show file tree
Hide file tree
Showing 11 changed files with 1,747 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ updates:
schedule:
interval: daily

- package-ecosystem: gomod
directory: "/v2"
schedule:
interval: daily

- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
9 changes: 9 additions & 0 deletions v2/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module github.com/jaegertracing/jaeger/v2

go 1.16

require (
github.com/stretchr/testify v1.7.0
go.opentelemetry.io/collector v0.22.0
go.uber.org/zap v1.16.0
)
1,428 changes: 1,428 additions & 0 deletions v2/go.sum

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions v2/storage/memory/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# In-memory storage for Jaeger

This storage component is an OpenTelemetry Exporter that receives OTLP data and stores in memory using Jaeger format.

## Configuration

TBD.

## Metrics

TBD.
22 changes: 22 additions & 0 deletions v2/storage/memory/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) 2021 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 memory

import "go.opentelemetry.io/collector/config/configmodels"

// Config defines configuration for the exporter.
type Config struct {
configmodels.ExporterSettings `mapstructure:",squash"`
}
48 changes: 48 additions & 0 deletions v2/storage/memory/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2021 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 memory

import (
"context"
"path"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configtest"
"go.uber.org/zap"
)

func TestLoadConfig(t *testing.T) {
factories, err := componenttest.ExampleComponents()
assert.NoError(t, err)

factory := NewFactory()
factories.Exporters[typeStr] = factory
cfg, err := configtest.LoadConfigFile(t, path.Join(".", "testdata", "config.yaml"), factories)

require.NoError(t, err)
require.NotNil(t, cfg)

e0 := cfg.Exporters["memory"]
assert.Equal(t, e0, factory.CreateDefaultConfig())

params := component.ExporterCreateParams{Logger: zap.NewNop()}
te, err := factory.CreateTracesExporter(context.Background(), params, e0)
require.NoError(t, err)
require.NotNil(t, te)
}
69 changes: 69 additions & 0 deletions v2/storage/memory/exporter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright (c) 2021 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 memory

import (
"context"
"sync"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.uber.org/zap"
)

// inMemoryExporter stores traces in memory.
type inMemoryExporter struct {
name string
logger *zap.Logger

stopCh chan (struct{})
stopped bool
stopLock sync.Mutex
}

// newExporter returns a new exporter for the in-memory storage.
func newExporter(cfg *Config, logger *zap.Logger) (component.TracesExporter, error) {
s := &inMemoryExporter{
name: cfg.NameVal,
logger: logger,

stopCh: make(chan (struct{})),
}

return exporterhelper.NewTraceExporter(
cfg,
logger,
s.pushTraceData,
exporterhelper.WithStart(s.start),
exporterhelper.WithShutdown(s.shutdown),
)
}

func (s *inMemoryExporter) pushTraceData(ctx context.Context, td pdata.Traces) (droppedSpans int, err error) {
return 0, nil
}

func (s *inMemoryExporter) shutdown(context.Context) error {
s.stopLock.Lock()
s.stopped = true
s.stopLock.Unlock()
close(s.stopCh)
return nil
}

func (s *inMemoryExporter) start(context.Context, component.Host) error {
return nil
}
34 changes: 34 additions & 0 deletions v2/storage/memory/exporter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2021 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 memory

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/consumer/pdata"
"go.uber.org/zap"
)

func TestNew(t *testing.T) {
exp, err := newExporter(&Config{}, zap.NewNop())
require.NoError(t, err)
require.NotNil(t, exp)

err = exp.ConsumeTraces(context.Background(), pdata.NewTraces())
assert.NoError(t, err)
}
50 changes: 50 additions & 0 deletions v2/storage/memory/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2021 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 memory

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/configmodels"
"go.opentelemetry.io/collector/exporter/exporterhelper"
)

const (
// The value of "type" key in configuration.
typeStr = "memory"
)

// NewFactory creates a factory for the in-memory exporter
func NewFactory() component.ExporterFactory {
return exporterhelper.NewFactory(
typeStr,
createDefaultConfig,
exporterhelper.WithTraces(createTraceExporter))
}

func createDefaultConfig() configmodels.Exporter {
return &Config{
ExporterSettings: configmodels.ExporterSettings{
TypeVal: typeStr,
NameVal: typeStr,
},
}
}

func createTraceExporter(_ context.Context, params component.ExporterCreateParams, config configmodels.Exporter) (component.TracesExporter, error) {
expCfg := config.(*Config)
return newExporter(expCfg, params.Logger)
}
56 changes: 56 additions & 0 deletions v2/storage/memory/factory_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2021 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 memory

import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/configcheck"
"go.opentelemetry.io/collector/config/configerror"
"go.uber.org/zap"
)

func TestCreateDefaultConfig(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
assert.NotNil(t, cfg, "failed to create default config")
assert.NoError(t, configcheck.ValidateConfig(cfg))
}

func TestCreateMetricsExporter(t *testing.T) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()

params := component.ExporterCreateParams{Logger: zap.NewNop()}
_, err := factory.CreateMetricsExporter(context.Background(), params, cfg)
assert.Error(t, err, configerror.ErrDataTypeIsNotSupported)
}

func TestCreateInstanceViaFactory(t *testing.T) {
factory := NewFactory()

cfg := factory.CreateDefaultConfig()
params := component.ExporterCreateParams{Logger: zap.NewNop()}
exp, err := factory.CreateTracesExporter(context.Background(), params, cfg)
assert.NoError(t, err)
assert.NotNil(t, exp)

assert.NoError(t, exp.Start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, exp.Shutdown(context.Background()))
}
15 changes: 15 additions & 0 deletions v2/storage/memory/testdata/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
receivers:
examplereceiver:

processors:
exampleprocessor:

exporters:
memory:

service:
pipelines:
traces:
receivers: [examplereceiver]
processors: [exampleprocessor]
exporters: [memory]

0 comments on commit 40e96f9

Please sign in to comment.