Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use same server info for all map modes #137

Merged
merged 7 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions pkg/batchmapper/examples/batchmap-flatmap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,7 @@

An example User Defined Function that demonstrates how to write a batch map based `flatmap` User Defined Function.


To start a vertex in batch map mode we need to add the annotations as following
```yaml
- name: go-split
metadata:
annotations:
numaflow.numaproj.io/batch-map: "true"
scale:
min: 1
udf:
container:
# Split input message into an array with comma, see https://github.com/numaproj/numaflow-go/tree/main/pkg/batchmapper/examples/batchmap-flatmap
image: quay.io/numaio/numaflow-go/batch-map-flatmap:stable
imagePullPolicy: Always
```


Some considerations for batch map are as follows
Some important considerations for batch map are as follows

- The user will have to ensure that the BatchResponse is tagged with the correct request ID as this will be used by Numaflow for populating information required for system correctness like MessageID for the ISB deduplication.

Expand Down
3 changes: 0 additions & 3 deletions pkg/batchmapper/examples/batchmap-flatmap/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ spec:
source:
http: {}
- name: go-split
metadata:
annotations:
numaflow.numaproj.io/batch-map: "true"
scale:
min: 1
udf:
Expand Down
9 changes: 7 additions & 2 deletions pkg/batchmapper/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/numaproj/numaflow-go/pkg"
batchmappb "github.com/numaproj/numaflow-go/pkg/apis/proto/batchmap/v1"
"github.com/numaproj/numaflow-go/pkg/info"
"github.com/numaproj/numaflow-go/pkg/shared"
)

Expand Down Expand Up @@ -36,9 +37,13 @@ func (m *server) Start(ctx context.Context) error {
ctxWithSignal, stop := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
defer stop()

// write server info to the file
// create a server info to the file, we need to add metadata to ensure selection of the
// correct map mode, in this case batch map
serverInfo := info.GetDefaultServerInfo()
serverInfo.Metadata = map[string]string{info.MapModeKey: string(info.BatchMap)}

// start listening on unix domain socket
lis, err := shared.PrepareServer(m.opts.sockAddr, m.opts.serverInfoFilePath)
lis, err := shared.PrepareServer(m.opts.sockAddr, m.opts.serverInfoFilePath, serverInfo)
if err != nil {
return fmt.Errorf("failed to execute net.Listen(%q, %q): %v", uds, address, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/batchmapper/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
uds = "unix"
address = "/var/run/numaflow/batchmap.sock"
defaultMaxMessageSize = 1024 * 1024 * 64
serverInfoFilePath = "/var/run/numaflow/batchmapper-server-info"
serverInfoFilePath = "/var/run/numaflow/mapper-server-info"
)

// Service implements the proto gen server interface and contains the map operation
Expand Down
10 changes: 9 additions & 1 deletion pkg/info/server_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

var END = fmt.Sprintf("%U__END__", '\\') // U+005C__END__

func GetSDKVersion() string {
func getSDKVersion() string {
version := ""
info, ok := debug.ReadBuildInfo()
if !ok {
Expand Down Expand Up @@ -109,3 +109,11 @@ func Read(opts ...Option) (*ServerInfo, error) {
}
return info, nil
}

// GetDefaultServerInfo returns a ServerInfo object with the default fields populated for Go-SDK
func GetDefaultServerInfo() *ServerInfo {
serverInfo := &ServerInfo{Protocol: UDS, Language: Go, MinimumNumaflowVersion: MinimumNumaflowVersion,
Version: getSDKVersion()}
return serverInfo

}
4 changes: 2 additions & 2 deletions pkg/info/server_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func Test_getSDKVersion(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := GetSDKVersion(); got != tt.want {
t.Errorf("GetSDKVersion() = %v, want %v", got, tt.want)
if got := getSDKVersion(); got != tt.want {
t.Errorf("getSDKVersion() = %v, want %v", got, tt.want)
}
})
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/info/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ const (
Java Language = "java"
)

type MapMode string

const (
UnaryMap MapMode = "unary-map"
StreamMap MapMode = "stream-map"
BatchMap MapMode = "batch-map"
)

// MapModeKey is the key used in the server info metadata map to indicate which map mode is enabled.
const MapModeKey = "MAP_MODE"

// MinimumNumaflowVersion specifies the minimum Numaflow version required by the current SDK version
const MinimumNumaflowVersion = "1.2.0-rc4"

Expand Down
9 changes: 7 additions & 2 deletions pkg/mapper/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/numaproj/numaflow-go/pkg"
mappb "github.com/numaproj/numaflow-go/pkg/apis/proto/map/v1"
"github.com/numaproj/numaflow-go/pkg/info"
"github.com/numaproj/numaflow-go/pkg/shared"
)

Expand Down Expand Up @@ -36,9 +37,13 @@ func (m *server) Start(ctx context.Context) error {
ctxWithSignal, stop := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
defer stop()

// write server info to the file
// create a server info to the file, we need to add metadata to ensure selection of the
// correct map mode, in this case unary map
serverInfo := info.GetDefaultServerInfo()
serverInfo.Metadata = map[string]string{info.MapModeKey: string(info.UnaryMap)}

// start listening on unix domain socket
lis, err := shared.PrepareServer(m.opts.sockAddr, m.opts.serverInfoFilePath)
lis, err := shared.PrepareServer(m.opts.sockAddr, m.opts.serverInfoFilePath, serverInfo)
if err != nil {
return fmt.Errorf("failed to execute net.Listen(%q, %q): %v", uds, address, err)
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/mapstreamer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/numaproj/numaflow-go/pkg"
mapstreampb "github.com/numaproj/numaflow-go/pkg/apis/proto/mapstream/v1"
"github.com/numaproj/numaflow-go/pkg/info"
"github.com/numaproj/numaflow-go/pkg/shared"
)

Expand Down Expand Up @@ -35,9 +36,13 @@ func (m *server) Start(ctx context.Context) error {
ctxWithSignal, stop := signal.NotifyContext(ctx, syscall.SIGINT, syscall.SIGTERM)
defer stop()

// write server info to the file
// create a server info to the file, we need to add metadata to ensure selection of the
// correct map mode, in this case streaming map
serverInfo := info.GetDefaultServerInfo()
serverInfo.Metadata = map[string]string{info.MapModeKey: string(info.StreamMap)}

// start listening on unix domain socket
lis, err := shared.PrepareServer(m.opts.sockAddr, m.opts.serverInfoFilePath)
lis, err := shared.PrepareServer(m.opts.sockAddr, m.opts.serverInfoFilePath, serverInfo)
if err != nil {
return fmt.Errorf("failed to execute net.Listen(%q, %q): %v", uds, address, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/mapstreamer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (
uds = "unix"
defaultMaxMessageSize = 1024 * 1024 * 64
address = "/var/run/numaflow/mapstream.sock"
serverInfoFilePath = "/var/run/numaflow/mapstreamer-server-info"
serverInfoFilePath = "/var/run/numaflow/mapper-server-info"
)

// Service implements the proto gen server interface and contains the map
Expand Down
3 changes: 2 additions & 1 deletion pkg/reducer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

numaflow "github.com/numaproj/numaflow-go/pkg"
reducepb "github.com/numaproj/numaflow-go/pkg/apis/proto/reduce/v1"
"github.com/numaproj/numaflow-go/pkg/info"
"github.com/numaproj/numaflow-go/pkg/shared"
)

Expand Down Expand Up @@ -37,7 +38,7 @@ func (r *server) Start(ctx context.Context) error {

// write server info to the file
// start listening on unix domain socket
lis, err := shared.PrepareServer(r.opts.sockAddr, r.opts.serverInfoFilePath)
lis, err := shared.PrepareServer(r.opts.sockAddr, r.opts.serverInfoFilePath, info.GetDefaultServerInfo())
if err != nil {
return fmt.Errorf("failed to execute net.Listen(%q, %q): %v", uds, address, err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/reducestreamer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/numaproj/numaflow-go/pkg"
reducepb "github.com/numaproj/numaflow-go/pkg/apis/proto/reduce/v1"
"github.com/numaproj/numaflow-go/pkg/info"
"github.com/numaproj/numaflow-go/pkg/shared"
)

Expand Down Expand Up @@ -37,7 +38,7 @@ func (r *server) Start(ctx context.Context) error {

// write server info to the file
// start listening on unix domain socket
lis, err := shared.PrepareServer(r.opts.sockAddr, r.opts.serverInfoFilePath)
lis, err := shared.PrepareServer(r.opts.sockAddr, r.opts.serverInfoFilePath, info.GetDefaultServerInfo())
if err != nil {
return fmt.Errorf("failed to execute net.Listen(%q, %q): %v", uds, address, err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/sessionreducer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/numaproj/numaflow-go/pkg"
sessionreducepb "github.com/numaproj/numaflow-go/pkg/apis/proto/sessionreduce/v1"
"github.com/numaproj/numaflow-go/pkg/info"
"github.com/numaproj/numaflow-go/pkg/shared"
)

Expand Down Expand Up @@ -37,7 +38,7 @@ func (r *server) Start(ctx context.Context) error {

// write server info to the file
// start listening on unix domain socket
lis, err := shared.PrepareServer(r.opts.sockAddr, r.opts.serverInfoFilePath)
lis, err := shared.PrepareServer(r.opts.sockAddr, r.opts.serverInfoFilePath, info.GetDefaultServerInfo())
if err != nil {
return fmt.Errorf("failed to execute net.Listen(%q, %q): %v", uds, address, err)
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/shared/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ const (
uds = "unix"
)

func PrepareServer(sockAddr string, infoFilePath string) (net.Listener, error) {
func PrepareServer(sockAddr string, infoFilePath string, serverInfo *info.ServerInfo) (net.Listener, error) {
// If serverInfo is not provided, then create a default server info instance.
if serverInfo == nil {
serverInfo = info.GetDefaultServerInfo()
}
// If infoFilePath is not empty, write the server info to the file.
if infoFilePath != "" {
serverInfo := &info.ServerInfo{Protocol: info.UDS, Language: info.Go, MinimumNumaflowVersion: info.MinimumNumaflowVersion, Version: info.GetSDKVersion()}
if err := info.Write(serverInfo, info.WithServerInfoFilePath(infoFilePath)); err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/sideinput/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/numaproj/numaflow-go/pkg"
sideinputpb "github.com/numaproj/numaflow-go/pkg/apis/proto/sideinput/v1"
"github.com/numaproj/numaflow-go/pkg/info"
"github.com/numaproj/numaflow-go/pkg/shared"
)

Expand Down Expand Up @@ -37,7 +38,7 @@ func (s *server) Start(ctx context.Context) error {
defer stop()

// start listening on unix domain socket
lis, err := shared.PrepareServer(s.opts.sockAddr, s.opts.serverInfoFilePath)
lis, err := shared.PrepareServer(s.opts.sockAddr, s.opts.serverInfoFilePath, info.GetDefaultServerInfo())
if err != nil {
return fmt.Errorf("failed to execute net.Listen(%q, %q): %v", uds, address, err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/sinker/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

numaflow "github.com/numaproj/numaflow-go/pkg"
sinkpb "github.com/numaproj/numaflow-go/pkg/apis/proto/sink/v1"
"github.com/numaproj/numaflow-go/pkg/info"
"github.com/numaproj/numaflow-go/pkg/shared"
)

Expand Down Expand Up @@ -36,7 +37,7 @@ func (s *sinkServer) Start(ctx context.Context) error {

// write server info to the file
// start listening on unix domain socket
lis, err := shared.PrepareServer(s.opts.sockAddr, s.opts.serverInfoFilePath)
lis, err := shared.PrepareServer(s.opts.sockAddr, s.opts.serverInfoFilePath, info.GetDefaultServerInfo())
if err != nil {
return fmt.Errorf("failed to execute net.Listen(%q, %q): %v", uds, address, err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/sourcer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

numaflow "github.com/numaproj/numaflow-go/pkg"
sourcepb "github.com/numaproj/numaflow-go/pkg/apis/proto/source/v1"
"github.com/numaproj/numaflow-go/pkg/info"
"github.com/numaproj/numaflow-go/pkg/shared"
)

Expand Down Expand Up @@ -38,7 +39,7 @@ func (s *server) Start(ctx context.Context) error {

// write server info to the file
// start listening on unix domain socket
lis, err := shared.PrepareServer(s.opts.sockAddr, s.opts.serverInfoFilePath)
lis, err := shared.PrepareServer(s.opts.sockAddr, s.opts.serverInfoFilePath, info.GetDefaultServerInfo())
if err != nil {
return fmt.Errorf("failed to execute net.Listen(%q, %q): %v", uds, address, err)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/sourcetransformer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/numaproj/numaflow-go/pkg"
v1 "github.com/numaproj/numaflow-go/pkg/apis/proto/sourcetransform/v1"
"github.com/numaproj/numaflow-go/pkg/info"
"github.com/numaproj/numaflow-go/pkg/shared"
)

Expand Down Expand Up @@ -37,7 +38,7 @@ func (m *server) Start(ctx context.Context) error {

// write server info to the file
// start listening on unix domain socket
lis, err := shared.PrepareServer(m.opts.sockAddr, m.opts.serverInfoFilePath)
lis, err := shared.PrepareServer(m.opts.sockAddr, m.opts.serverInfoFilePath, info.GetDefaultServerInfo())
if err != nil {
return fmt.Errorf("failed to execute net.Listen(%q, %q): %v", uds, address, err)
}
Expand Down
Loading