Skip to content

Commit 00def36

Browse files
Merge pull request #6 from streamnative/update
feat: update logic to adopt changes in pulsar-functions-generic-runtime
2 parents 7308e62 + b523c88 commit 00def36

21 files changed

Lines changed: 1084 additions & 21 deletions

File tree

.ci/clusters/oxia.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: oxia
5+
labels:
6+
name: oxia
7+
spec:
8+
ports:
9+
- port: 6648
10+
clusterIP: None
11+
selector:
12+
role: oxia
13+
---
14+
apiVersion: apps/v1
15+
kind: StatefulSet
16+
metadata:
17+
name: oxia
18+
spec:
19+
selector:
20+
matchLabels:
21+
role: oxia
22+
serviceName: "oxia"
23+
replicas: 1
24+
template:
25+
metadata:
26+
labels:
27+
role: oxia
28+
spec:
29+
terminationGracePeriodSeconds: 10
30+
containers:
31+
- name: oxia
32+
image: streamnative/oxia:0.13
33+
command:
34+
- oxia
35+
- standalone
36+
ports:
37+
- containerPort: 6648

.ci/clusters/secret.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: Secret
3+
metadata:
4+
name: test-secret
5+
type: Opaque
6+
data:
7+
key: c2VjLXZhbHVl
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
#
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing,
13+
# software distributed under the License is distributed on an
14+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
# KIND, either express or implied. See the License for the
16+
# specific language governing permissions and limitations
17+
# under the License.
18+
#
19+
20+
## deployed withh emptyDir
21+
volumes:
22+
persistence: false
23+
24+
# disabled AntiAffinity
25+
affinity:
26+
anti_affinity: false
27+
28+
# disable auto recovery
29+
components:
30+
autorecovery: false
31+
pulsar_manager: false
32+
sql_worker: false
33+
proxy: false
34+
35+
## disable monitoring stack
36+
monitoring:
37+
# monitoring - prometheus
38+
prometheus: false
39+
# monitoring - grafana
40+
grafana: false
41+
# monitoring - node_exporter
42+
node_exporter: false
43+
44+
images:
45+
zookeeper:
46+
repository: streamnative/sn-platform
47+
tag: 2.9.2.23
48+
bookie:
49+
repository: streamnative/sn-platform
50+
tag: 2.9.2.23
51+
broker:
52+
repository: streamnative/sn-platform
53+
tag: 2.9.2.23
54+
functions:
55+
repository: streamnative/sn-platform
56+
tag: 2.9.2.23
57+
58+
zookeeper:
59+
replicaCount: 1
60+
resources:
61+
requests:
62+
memory: 256Mi
63+
cpu: 50m
64+
65+
bookkeeper:
66+
replicaCount: 0
67+
metadata:
68+
image:
69+
repository: streamnative/sn-platform
70+
tag: 2.9.2.23
71+
resources:
72+
requests:
73+
memory: 256Mi
74+
cpu: 50m
75+
configData:
76+
PULSAR_PREFIX_autoRecoveryDaemonEnabled: "false"
77+
PULSAR_PREFIX_dlog.bkcEnsembleSize: "1"
78+
PULSAR_PREFIX_dlog.bkcWriteQuorumSize: "1"
79+
PULSAR_PREFIX_dlog.bkcAckQuorumSize: "1"
80+
# `BOOKIE_MEM` is used for `bookie shell`
81+
BOOKIE_MEM: >
82+
-Xms128m
83+
-Xmx256m
84+
-XX:MaxDirectMemorySize=256m
85+
# we use `bin/pulsar` for starting bookie daemons
86+
PULSAR_MEM: >
87+
-Xms128m
88+
-Xmx256m
89+
-XX:MaxDirectMemorySize=256m
90+
PULSAR_GC: >
91+
-XX:+UseG1GC
92+
-XX:MaxGCPauseMillis=10
93+
-XX:+ParallelRefProcEnabled
94+
-XX:+UnlockExperimentalVMOptions
95+
-XX:+AggressiveOpts
96+
-XX:+DoEscapeAnalysis
97+
-XX:ParallelGCThreads=4
98+
-XX:ConcGCThreads=4
99+
-XX:G1NewSizePercent=50
100+
-XX:+DisableExplicitGC
101+
-XX:-ResizePLAB
102+
-XX:+ExitOnOutOfMemoryError
103+
-XX:+PerfDisableSharedMem
104+
105+
pulsar_metadata:
106+
image:
107+
repository: streamnative/sn-platform
108+
tag: 2.9.2.23
109+
110+
broker:
111+
replicaCount: 1
112+
configData:
113+
## Enable `autoSkipNonRecoverableData` since bookkeeper is running
114+
## without persistence
115+
autoSkipNonRecoverableData: "true"
116+
# storage settings
117+
managedLedgerDefaultEnsembleSize: "1"
118+
managedLedgerDefaultWriteQuorum: "1"
119+
managedLedgerDefaultAckQuorum: "1"
120+
enablePackagesManagement: "true"
121+
PULSAR_PREFIX_enablePackagesManagement: "true"
122+
resources:
123+
requests:
124+
memory: 256Mi
125+
cpu: 50m
126+
127+
functions:
128+
functionState: true
129+
useDedicatedRunner: false
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"strings"
7+
8+
"github.com/sirupsen/logrus"
9+
"github.com/streamnative/pulsar-function-go/pf"
10+
)
11+
12+
func HandleExclamation(ctx context.Context, in []byte) ([]byte, error) {
13+
// 1. unmarshal []byte to your struct, use any schema you want
14+
payload := string(in)
15+
16+
// 2. do your logic
17+
if fc, ok := pf.FromContext(ctx); ok {
18+
for _, word := range strings.Split(payload, " ") {
19+
_ = fc.IncrCounter(word, 1)
20+
count, _ := fc.GetCounter(word)
21+
logrus.Infof("got word: %s for %d times", word, count)
22+
}
23+
// test user config and secrets
24+
cfg := fc.GetUserConfValue("configKey")
25+
sec, err := fc.GetSecret("secretKey")
26+
if err == nil {
27+
msg := fmt.Sprintf("config: %v, secret: %s", cfg, *sec)
28+
_, _ = fc.Publish("persistent://public/default/test-exec-package-serde-extra", []byte(msg))
29+
}
30+
}
31+
data := payload + "!"
32+
33+
// 3. marshal your struct to []byte
34+
return []byte(data), nil
35+
36+
}
37+
38+
func main() {
39+
pf.Start(HandleExclamation)
40+
}

0 commit comments

Comments
 (0)