Skip to content

Commit

Permalink
Wrap builtin processors in middleware in examples (#1748)
Browse files Browse the repository at this point in the history
* wrap builtin processors in middleware in examples

* simplify processor specification exporting

* disable schema middleware in error and filter processors

* generate processor specs
  • Loading branch information
lovromazgon authored Aug 6, 2024
1 parent 817d52c commit 306defe
Show file tree
Hide file tree
Showing 36 changed files with 507 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build export_processors
// This file is here to export processor specifications. It's named with a "z_"
// prefix to ensure it's processed last by go generate.

//go:generate env EXPORT_PROCESSORS=true go test -count=1 -tags export_processors .

package avro

Expand All @@ -29,6 +32,8 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

// tests passed, export the processors
exampleutil.ExportProcessors()
if os.Getenv("EXPORT_PROCESSORS") == "true" {
// tests passed and env var is included, export the processors
exampleutil.ExportProcessors()
}
}
20 changes: 0 additions & 20 deletions pkg/plugin/processor/builtin/impl/avro/z_examples_test.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build export_processors
// This file is here to export processor specifications. It's named with a "z_"
// prefix to ensure it's processed last by go generate.

//go:generate env EXPORT_PROCESSORS=true go test -count=1 -tags export_processors .

package base64

Expand All @@ -29,6 +32,8 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

// tests passed, export the processors
exampleutil.ExportProcessors()
if os.Getenv("EXPORT_PROCESSORS") == "true" {
// tests passed and env var is included, export the processors
exampleutil.ExportProcessors()
}
}
20 changes: 0 additions & 20 deletions pkg/plugin/processor/builtin/impl/base64/z_examples_test.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build export_processors
// This file is here to export processor specifications. It's named with a "z_"
// prefix to ensure it's processed last by go generate.

//go:generate env EXPORT_PROCESSORS=true go test -count=1 -tags export_processors .

package custom

Expand All @@ -29,6 +32,8 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

// tests passed, export the processors
exampleutil.ExportProcessors()
if os.Getenv("EXPORT_PROCESSORS") == "true" {
// tests passed and env var is included, export the processors
exampleutil.ExportProcessors()
}
}
20 changes: 0 additions & 20 deletions pkg/plugin/processor/builtin/impl/custom/z_examples_test.go

This file was deleted.

15 changes: 15 additions & 0 deletions pkg/plugin/processor/builtin/impl/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/Masterminds/sprig/v3"
"github.com/conduitio/conduit-commons/config"
"github.com/conduitio/conduit-commons/lang"
"github.com/conduitio/conduit-commons/opencdc"
sdk "github.com/conduitio/conduit-processor-sdk"
"github.com/conduitio/conduit/pkg/foundation/cerrors"
Expand Down Expand Up @@ -100,3 +101,17 @@ func (p *errorProcessor) errorMessage(record opencdc.Record) string {
}
return buf.String()
}

func (*errorProcessor) MiddlewareOptions() []sdk.ProcessorMiddlewareOption {
// disable schema middleware by default
return []sdk.ProcessorMiddlewareOption{
sdk.ProcessorWithSchemaEncodeConfig{
PayloadEnabled: lang.Ptr(false),
KeyEnabled: lang.Ptr(false),
},
sdk.ProcessorWithSchemaDecodeConfig{
PayloadEnabled: lang.Ptr(false),
KeyEnabled: lang.Ptr(false),
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build export_processors
// This file is here to export processor specifications. It's named with a "z_"
// prefix to ensure it's processed last by go generate.

//go:generate env EXPORT_PROCESSORS=true go test -count=1 -tags export_processors .

package field

Expand All @@ -29,6 +32,8 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

// tests passed, export the processors
exampleutil.ExportProcessors()
if os.Getenv("EXPORT_PROCESSORS") == "true" {
// tests passed and env var is included, export the processors
exampleutil.ExportProcessors()
}
}
20 changes: 0 additions & 20 deletions pkg/plugin/processor/builtin/impl/field/z_examples_test.go

This file was deleted.

15 changes: 15 additions & 0 deletions pkg/plugin/processor/builtin/impl/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"

"github.com/conduitio/conduit-commons/config"
"github.com/conduitio/conduit-commons/lang"
"github.com/conduitio/conduit-commons/opencdc"
sdk "github.com/conduitio/conduit-processor-sdk"
"github.com/conduitio/conduit/pkg/foundation/log"
Expand Down Expand Up @@ -54,3 +55,17 @@ func (p *filterProcessor) Process(_ context.Context, records []opencdc.Record) [
}
return out
}

func (*filterProcessor) MiddlewareOptions() []sdk.ProcessorMiddlewareOption {
// disable schema middleware by default
return []sdk.ProcessorMiddlewareOption{
sdk.ProcessorWithSchemaEncodeConfig{
PayloadEnabled: lang.Ptr(false),
KeyEnabled: lang.Ptr(false),
},
sdk.ProcessorWithSchemaDecodeConfig{
PayloadEnabled: lang.Ptr(false),
KeyEnabled: lang.Ptr(false),
},
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build export_processors
// This file is here to export processor specifications. It's named with a "z_"
// prefix to ensure it's processed last by go generate.

//go:generate env EXPORT_PROCESSORS=true go test -count=1 -tags export_processors .

package json

Expand All @@ -29,6 +32,8 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

// tests passed, export the processors
exampleutil.ExportProcessors()
if os.Getenv("EXPORT_PROCESSORS") == "true" {
// tests passed and env var is included, export the processors
exampleutil.ExportProcessors()
}
}
20 changes: 0 additions & 20 deletions pkg/plugin/processor/builtin/impl/json/z_examples_test.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build export_processors
// This file is here to export processor specifications. It's named with a "z_"
// prefix to ensure it's processed last by go generate.

//go:generate env EXPORT_PROCESSORS=true go test -count=1 -tags export_processors .

package unwrap

Expand All @@ -29,6 +32,8 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

// tests passed, export the processors
exampleutil.ExportProcessors()
if os.Getenv("EXPORT_PROCESSORS") == "true" {
// tests passed and env var is included, export the processors
exampleutil.ExportProcessors()
}
}
20 changes: 0 additions & 20 deletions pkg/plugin/processor/builtin/impl/unwrap/z_examples_test.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build export_processors
// This file is here to export processor specifications. It's named with a "z_"
// prefix to ensure it's processed last by go generate.

//go:generate env EXPORT_PROCESSORS=true go test -count=1 -tags export_processors .

package webhook

Expand All @@ -29,6 +32,8 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

// tests passed, export the processors
exampleutil.ExportProcessors()
if os.Getenv("EXPORT_PROCESSORS") == "true" {
// tests passed and env var is included, export the processors
exampleutil.ExportProcessors()
}
}
20 changes: 0 additions & 20 deletions pkg/plugin/processor/builtin/impl/webhook/z_examples_test.go

This file was deleted.

11 changes: 8 additions & 3 deletions pkg/plugin/processor/builtin/impl/z_examples_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build export_processors
// This file is here to export processor specifications. It's named with a "z_"
// prefix to ensure it's processed last by go generate.

//go:generate env EXPORT_PROCESSORS=true go test -count=1 -tags export_processors .

package impl

Expand All @@ -29,6 +32,8 @@ func TestMain(m *testing.M) {
os.Exit(code)
}

// tests passed, export the processors
exampleutil.ExportProcessors()
if os.Getenv("EXPORT_PROCESSORS") == "true" {
// tests passed and env var is included, export the processors
exampleutil.ExportProcessors()
}
}
Loading

0 comments on commit 306defe

Please sign in to comment.