-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clickhouse db operation processor (#1537)
Co-authored-by: Tamir David <tamirdavid@Tamirs-MacBook-Pro.local> Co-authored-by: Amir Blum <amirgiraffe@gmail.com>
- Loading branch information
1 parent
30ff128
commit 892e05d
Showing
17 changed files
with
646 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
apiVersion: odigos.io/v1alpha1 | ||
kind: Processor | ||
metadata: | ||
name: query-operation-detector | ||
namespace: odigos-system | ||
spec: | ||
type: odigossqldboperationprocessor | ||
processorName: query-operation-detector | ||
notes: "Auto generated rule from query-operation-detector profile. Do not edit." | ||
processorConfig: {} | ||
signals: | ||
- TRACES | ||
collectorRoles: | ||
- CLUSTER_GATEWAY |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# SQL DB Operation Processor | ||
|
||
The SQL DB Operation Processor is responsible for detecting the type of SQL operation performed by analyzing the SQL query within a trace. It extracts the query text, checks for common SQL operations (SELECT, INSERT, UPDATE, DELETE, CREATE), and assigns the appropriate operation name to the trace span. | ||
|
||
This processor ensures that each trace contains clear metadata about the database operation performed, enabling better observability and trace analysis. |
15 changes: 15 additions & 0 deletions
15
collector/processors/odigossqldboperationprocessor/config.go
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package odigossqldboperationprocessor | ||
|
||
import ( | ||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
type Config struct { | ||
} | ||
|
||
var _ component.Config = (*Config)(nil) | ||
|
||
func (cfg *Config) Validate() error { | ||
|
||
return nil | ||
} |
41 changes: 41 additions & 0 deletions
41
collector/processors/odigossqldboperationprocessor/factory.go
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package odigossqldboperationprocessor | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/processor" | ||
"go.opentelemetry.io/collector/processor/processorhelper" | ||
) | ||
|
||
// NewFactory returns a new factory for the Resource processor. | ||
func NewFactory() processor.Factory { | ||
return processor.NewFactory( | ||
component.MustNewType("odigossqldboperationprocessor"), | ||
createDefaultConfig, | ||
processor.WithTraces(createTracesProcessor, component.StabilityLevelBeta), | ||
) | ||
} | ||
|
||
func createDefaultConfig() component.Config { | ||
return &Config{} | ||
} | ||
|
||
func createTracesProcessor( | ||
ctx context.Context, | ||
set processor.Settings, | ||
cfg component.Config, | ||
nextConsumer consumer.Traces) (processor.Traces, error) { | ||
|
||
proc := &DBOperationProcessor{logger: set.Logger} | ||
|
||
return processorhelper.NewTracesProcessor( | ||
ctx, | ||
set, | ||
cfg, | ||
nextConsumer, | ||
proc.processTraces, | ||
processorhelper.WithCapabilities(consumer.Capabilities{MutatesData: true}), | ||
) | ||
} |
92 changes: 92 additions & 0 deletions
92
collector/processors/odigossqldboperationprocessor/generated_component_test.go
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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package odigossqldboperationprocessor | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/component/componenttest" | ||
"go.opentelemetry.io/collector/confmap/confmaptest" | ||
"go.opentelemetry.io/collector/consumer/consumertest" | ||
"go.opentelemetry.io/collector/pdata/pcommon" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
"go.opentelemetry.io/collector/processor" | ||
"go.opentelemetry.io/collector/processor/processortest" | ||
) | ||
|
||
func TestComponentFactoryType(t *testing.T) { | ||
require.Equal(t, "odigossqldboperationprocessor", NewFactory().Type().String()) | ||
} | ||
|
||
func TestComponentConfigStruct(t *testing.T) { | ||
require.NoError(t, componenttest.CheckConfigStruct(NewFactory().CreateDefaultConfig())) | ||
} | ||
|
||
func TestComponentLifecycle(t *testing.T) { | ||
factory := NewFactory() | ||
|
||
tests := []struct { | ||
name string | ||
createFn func(ctx context.Context, set processor.Settings, cfg component.Config) (component.Component, error) | ||
}{ | ||
|
||
{ | ||
name: "traces", | ||
createFn: func(ctx context.Context, set processor.Settings, cfg component.Config) (component.Component, error) { | ||
return factory.CreateTracesProcessor(ctx, set, cfg, consumertest.NewNop()) | ||
}, | ||
}, | ||
} | ||
|
||
cm, err := confmaptest.LoadConf("metadata.yaml") | ||
require.NoError(t, err) | ||
cfg := factory.CreateDefaultConfig() | ||
sub, err := cm.Sub("tests::config") | ||
require.NoError(t, err) | ||
require.NoError(t, sub.Unmarshal(&cfg)) | ||
|
||
for _, test := range tests { | ||
t.Run(test.name+"-shutdown", func(t *testing.T) { | ||
c, err := test.createFn(context.Background(), processortest.NewNopSettings(), cfg) | ||
require.NoError(t, err) | ||
err = c.Shutdown(context.Background()) | ||
require.NoError(t, err) | ||
}) | ||
t.Run(test.name+"-lifecycle", func(t *testing.T) { | ||
c, err := test.createFn(context.Background(), processortest.NewNopSettings(), cfg) | ||
require.NoError(t, err) | ||
host := componenttest.NewNopHost() | ||
err = c.Start(context.Background(), host) | ||
require.NoError(t, err) | ||
require.NotPanics(t, func() { | ||
switch test.name { | ||
case "traces": | ||
e, ok := c.(processor.Traces) | ||
require.True(t, ok) | ||
traces := generateLifecycleTestTraces() | ||
if !e.Capabilities().MutatesData { | ||
traces.MarkReadOnly() | ||
} | ||
err = e.ConsumeTraces(context.Background(), traces) | ||
} | ||
}) | ||
require.NoError(t, err) | ||
err = c.Shutdown(context.Background()) | ||
require.NoError(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func generateLifecycleTestTraces() ptrace.Traces { | ||
traces := ptrace.NewTraces() | ||
rs := traces.ResourceSpans().AppendEmpty() | ||
rs.Resource().Attributes().PutStr("resource", "R1") | ||
span := rs.ScopeSpans().AppendEmpty().Spans().AppendEmpty() | ||
span.Attributes().PutStr("test_attr", "value_1") | ||
span.SetName("test_span") | ||
span.SetStartTimestamp(pcommon.NewTimestampFromTime(time.Now().Add(-1 * time.Second))) | ||
span.SetEndTimestamp(pcommon.NewTimestampFromTime(time.Now())) | ||
return traces | ||
} |
11 changes: 11 additions & 0 deletions
11
collector/processors/odigossqldboperationprocessor/generated_package_test.go
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package odigossqldboperationprocessor | ||
|
||
import ( | ||
"testing" | ||
|
||
"go.uber.org/goleak" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
goleak.VerifyTestMain(m) | ||
} |
Oops, something went wrong.