Skip to content

Commit 4342dc4

Browse files
Fix custom log config (#765)
* Fix log path when using custom java log yaml config * fix ci * Update * fix ci
1 parent 33c1a23 commit 4342dc4

File tree

4 files changed

+191
-3
lines changed

4 files changed

+191
-3
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
apiVersion: compute.functionmesh.io/v1alpha1
2+
kind: Function
3+
metadata:
4+
name: java-log-config-yaml
5+
namespace: default
6+
spec:
7+
image: streamnative/pulsar-functions-java-sample:3.2.2.1
8+
className: org.apache.pulsar.functions.api.examples.ExclamationFunction
9+
forwardSourceMessageProperty: true
10+
maxPendingAsyncRequests: 1000
11+
replicas: 1
12+
maxReplicas: 5
13+
logTopic: persistent://public/default/logging-function-logs
14+
input:
15+
topics:
16+
- persistent://public/default/input-java-log-config-yaml-topic
17+
typeClassName: java.lang.String
18+
output:
19+
topic: persistent://public/default/output-java-log-config-yaml-topic
20+
typeClassName: java.lang.String
21+
resources:
22+
requests:
23+
cpu: 50m
24+
memory: 1G
25+
limits:
26+
cpu: "0.2"
27+
memory: 1.1G
28+
# each secret will be loaded ad an env variable from the `path` secret with the `key` in that secret in the name of `name`
29+
secretsMap:
30+
"name":
31+
path: "test-secret"
32+
key: "username"
33+
"pwd":
34+
path: "test-secret"
35+
key: "password"
36+
pulsar:
37+
pulsarConfig: "test-pulsar"
38+
tlsConfig:
39+
enabled: false
40+
allowInsecure: false
41+
hostnameVerification: true
42+
certSecretName: sn-platform-tls-broker
43+
certSecretKey: ""
44+
authConfig:
45+
oauth2Config:
46+
audience: urn:sn:pulsar:sndev:test
47+
issuerUrl: https://auth.sncloud-stg.dev/
48+
keySecretName: sn-platform-oauth2-private-key
49+
keySecretKey: auth.json
50+
java:
51+
log:
52+
javaLog4JConfigFileType: yaml
53+
logConfig:
54+
name: "java-log-config-cm"
55+
key: "log.yaml"
56+
jar: /pulsar/examples/api-examples.jar
57+
# to be delete & use admission hook
58+
clusterName: test
59+
autoAck: true
60+
---
61+
apiVersion: v1
62+
kind: ConfigMap
63+
metadata:
64+
name: test-pulsar
65+
data:
66+
webServiceURL: http://sn-platform-pulsar-broker.default.svc.cluster.local:8080
67+
brokerServiceURL: pulsar://sn-platform-pulsar-broker.default.svc.cluster.local:6650
68+
---
69+
apiVersion: v1
70+
data:
71+
username: YWRtaW4=
72+
password: MWYyZDFlMmU2N2Rm
73+
kind: Secret
74+
metadata:
75+
name: test-secret
76+
type: Opaque
77+
---
78+
apiVersion: v1
79+
kind: ConfigMap
80+
metadata:
81+
name: java-log-config-cm
82+
data:
83+
log.yaml: |
84+
Configuration:
85+
name: pulsar-functions-kubernetes-instance
86+
monitorInterval: 30
87+
Properties:
88+
Property:
89+
- name: pulsar.log.level
90+
value: DEBUG
91+
- name: bk.log.level
92+
value: DEBUG
93+
94+
Appenders:
95+
Console:
96+
name: Console
97+
target: SYSTEM_OUT
98+
99+
PatternLayout:
100+
Pattern: "%d{ISO8601_OFFSET_DATE_TIME_HHMM} [%t] %-5level %logger{36} - %msg%n"
101+
102+
103+
RollingRandomAccessFile:
104+
name: RollingRandomAccessFile
105+
fileName: "${sys:pulsar.function.log.dir}/${sys:pulsar.function.log.file}.log"
106+
filePattern: "${sys:pulsar.function.log.dir}/${sys:pulsar.function.log.file}.%d{yyyy-MM-dd}-%i.log.gz"
107+
108+
PatternLayout:
109+
Pattern: "%d{yyyy-MMM-dd HH:mm:ss a} [%t] %-5level %logger{36} - %msg%n"
110+
111+
Policies:
112+
SizeBasedTriggeringPolicy:
113+
size: "10MB"
114+
DefaultRolloverStrategy:
115+
max: 5
116+
117+
Loggers:
118+
Root:
119+
level: "${sys:pulsar.log.level}"
120+
AppenderRef:
121+
- ref: Console
122+
level: "${sys:pulsar.log.level}"
123+
- ref: RollingRandomAccessFile
124+
Logger:
125+
name: org.apache.pulsar.functions.runtime.shaded.org.apache.bookkeeper
126+
level: "${sys:bk.log.level}"
127+
additivity: false
128+
AppenderRef:
129+
- ref: Console
130+
- ref: RollingRandomAccessFile
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
#
20+
21+
set -e
22+
23+
E2E_DIR=$(dirname "$0")
24+
BASE_DIR=$(cd "${E2E_DIR}"/../../../../..;pwd)
25+
PULSAR_NAMESPACE=${PULSAR_NAMESPACE:-"default"}
26+
PULSAR_RELEASE_NAME=${PULSAR_RELEASE_NAME:-"sn-platform"}
27+
E2E_KUBECONFIG=${E2E_KUBECONFIG:-"/tmp/e2e-k8s.config"}
28+
29+
source "${BASE_DIR}"/.ci/helm.sh
30+
31+
if [ ! "$KUBECONFIG" ]; then
32+
export KUBECONFIG=${E2E_KUBECONFIG}
33+
fi
34+
35+
manifests_file="${BASE_DIR}"/.ci/tests/integration-oauth2/cases/java-log-config-yaml/manifests.yaml
36+
37+
kubectl apply -f "${manifests_file}" > /dev/null 2>&1
38+
39+
verify_fm_result=$(ci::verify_function_mesh java-log-config-yaml 2>&1)
40+
if [ $? -ne 0 ]; then
41+
echo "$verify_fm_result"
42+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
43+
exit 1
44+
fi
45+
46+
verify_java_result=$(NAMESPACE=${PULSAR_NAMESPACE} CLUSTER=${PULSAR_RELEASE_NAME} ci::verify_exclamation_function_with_auth "persistent://public/default/input-java-log-config-yaml-topic" "persistent://public/default/output-java-log-config-yaml-topic" "test-message" "test-message!" 10 2>&1)
47+
if [ $? -ne 0 ]; then
48+
echo "$verify_java_result"
49+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true
50+
exit 1
51+
fi
52+
53+
verify_log_config_result=$(kubectl logs -l compute.functionmesh.io/name=java-log-config-yaml --tail=-1 | grep "Got result: object:" 2>&1)
54+
if [ $? -eq 0 ]; then
55+
echo "e2e-test: ok" | yq eval -
56+
else
57+
echo "$verify_log_config_result"
58+
fi
59+
kubectl delete -f "${manifests_file}" > /dev/null 2>&1 || true

.ci/tests/integration-oauth2/e2e.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ verify:
122122
cases:
123123
- query: timeout 5m bash .ci/tests/integration-oauth2/cases/java-function/verify.sh
124124
expected: expected.data.yaml
125+
- query: timeout 5m bash .ci/tests/integration-oauth2/cases/java-log-config-yaml/verify.sh
126+
expected: expected.data.yaml
125127
- query: timeout 5m bash .ci/tests/integration-oauth2/cases/java-download-function/verify.sh
126128
expected: expected.data.yaml
127129
- query: timeout 5m bash .ci/tests/integration-oauth2/cases/java-download-function-generic-auth/verify.sh

controllers/spec/common.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -859,9 +859,6 @@ func GenerateJavaLogConfigCommand(runtime *v1alpha1.JavaRuntime, agent v1alpha1.
859859
}
860860

861861
func GenerateJavaLogConfigFileName(runtime *v1alpha1.JavaRuntime) string {
862-
if runtime == nil || (runtime.Log != nil && runtime.Log.LogConfig != nil) {
863-
return DefaultJavaLogConfigPath
864-
}
865862
configFileType := v1alpha1.XML
866863
if runtime != nil && runtime.Log != nil && runtime.Log.JavaLog4JConfigFileType != nil {
867864
configFileType = *runtime.Log.JavaLog4JConfigFileType

0 commit comments

Comments
 (0)