From d7fd6ae6e86e46c6f88d9a1023804f09f67075e2 Mon Sep 17 00:00:00 2001 From: fredrikliu <139424001+fredrikliu@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:42:00 +0800 Subject: [PATCH 1/6] Update patch.go --- pkg/inject/pkg/kube/inject/apply/javaagent/patch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go b/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go index ac86079..5ed968d 100644 --- a/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go +++ b/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go @@ -154,7 +154,7 @@ func (pb *PodPatchBuilder) handleJavaAgentInit(opt *inject.PatchOptions, pod *co Value: defaultParam["PolarisDiscoverPort"], }, corev1.EnvVar{ - Name: "POLARIS_CONFIG_PORT", + Name: "POLARIS_CONFIG_IP", Value: defaultParam["PolarisConfigIP"], }, corev1.EnvVar{ From 8444e492cd1e6f219944ef08642cd29e8909c7d9 Mon Sep 17 00:00:00 2001 From: shuhanliu Date: Wed, 3 Jul 2024 16:49:57 +0800 Subject: [PATCH 2/6] not issue JAVA_AGENT_PLUGIN_CONF --- .../pkg/kube/inject/apply/javaagent/patch.go | 433 +++++++++--------- 1 file changed, 216 insertions(+), 217 deletions(-) diff --git a/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go b/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go index 5ed968d..ccca79d 100644 --- a/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go +++ b/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go @@ -15,275 +15,274 @@ package javaagent import ( - "bufio" - "bytes" - "context" - "encoding/json" - "fmt" - "strconv" - "strings" - "text/template" + "bufio" + "bytes" + "context" + "fmt" + "strconv" + "strings" + "text/template" - "github.com/polarismesh/polaris-controller/common/log" - "github.com/polarismesh/polaris-controller/pkg/inject/pkg/kube/inject" - "github.com/polarismesh/polaris-controller/pkg/inject/pkg/kube/inject/apply/base" - "github.com/polarismesh/polaris-controller/pkg/polarisapi" - "github.com/polarismesh/polaris-controller/pkg/util" - utils "github.com/polarismesh/polaris-controller/pkg/util" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "github.com/polarismesh/polaris-controller/common/log" + "github.com/polarismesh/polaris-controller/pkg/inject/pkg/kube/inject" + "github.com/polarismesh/polaris-controller/pkg/inject/pkg/kube/inject/apply/base" + "github.com/polarismesh/polaris-controller/pkg/polarisapi" + "github.com/polarismesh/polaris-controller/pkg/util" + utils "github.com/polarismesh/polaris-controller/pkg/util" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) // Java Agent 场景下的特殊 annonations 信息 const ( - customJavaAgentVersion = "polarismesh.cn/javaagentVersion" - customJavaAgentPluginFramework = "polarismesh.cn/javaagentFrameworkName" - customJavaAgentPluginFrameworkVersion = "polarismesh.cn/javaagentFrameworkVersion" - customJavaAgentPluginConfig = "polarismesh.cn/javaagentConfig" + customJavaAgentVersion = "polarismesh.cn/javaagentVersion" + customJavaAgentPluginFramework = "polarismesh.cn/javaagentFrameworkName" + customJavaAgentPluginFrameworkVersion = "polarismesh.cn/javaagentFrameworkVersion" + customJavaAgentPluginConfig = "polarismesh.cn/javaagentConfig" ) var oldAgentVersions = map[string]struct{}{ - "1.7.0-RC4": {}, - "1.7.0-RC3": {}, - "1.7.0-RC2": {}, - "1.7.0-RC1": {}, - "1.6.1": {}, - "1.6.0": {}, + "1.7.0-RC4": {}, + "1.7.0-RC3": {}, + "1.7.0-RC2": {}, + "1.7.0-RC1": {}, + "1.6.1": {}, + "1.6.0": {}, } const ( - ActiveJavaAgentCmd = "-javaagent:/app/lib/.polaris/java_agent/polaris-java-agent-%s/polaris-agent-core-bootstrap.jar" + ActiveJavaAgentCmd = "-javaagent:/app/lib/.polaris/java_agent/polaris-java-agent-%s/polaris-agent-core-bootstrap.jar" ) func init() { - inject.RegisterPatchBuilder(utils.SidecarJavaAgentModeName, &PodPatchBuilder{}) + inject.RegisterPatchBuilder(utils.SidecarJavaAgentModeName, &PodPatchBuilder{}) } // PodPatchBuilder type PodPatchBuilder struct { - *base.PodPatchBuilder + *base.PodPatchBuilder } func (pb *PodPatchBuilder) PatchContainer(req *inject.OperateContainerRequest) ([]inject.Rfc6902PatchOperation, error) { - switch req.Type { - case inject.PatchType_Remove: - return pb.PodPatchBuilder.PatchContainer(req) - case inject.PatchType_Add: - pod := req.Option.Pod - added := req.External - for index, add := range added { - if add.Name == "polaris-javaagent-init" { - log.InjectScope().Infof("begin deal polaris-javaagent-init inject for pod=[%s, %s]", pod.Namespace, pod.Name) - if err := pb.handleJavaAgentInit(req.Option, pod, &add); err != nil { - log.InjectScope().Errorf("handle polaris-javaagent-init inject for pod=[%s, %s] failed: %v", pod.Namespace, pod.Name, err) - } - } - added[index] = add - } - // 重新更新请求参数中的 req.External - req.External = added - log.InjectScope().Infof("finish deal polaris-javaagent-init inject for pod=[%s, %s] added: %#v", pod.Namespace, pod.Name, added) - return pb.PodPatchBuilder.PatchContainer(req) - case inject.PatchType_Update: - return pb.updateContainer(req.Option, req.Option.SidecarMode, req.Option.Pod, req.Option.Pod.Spec.Containers, req.BasePath), nil - } - return nil, nil + switch req.Type { + case inject.PatchType_Remove: + return pb.PodPatchBuilder.PatchContainer(req) + case inject.PatchType_Add: + pod := req.Option.Pod + added := req.External + for index, add := range added { + if add.Name == "polaris-javaagent-init" { + log.InjectScope().Infof("begin deal polaris-javaagent-init inject for pod=[%s, %s]", pod.Namespace, pod.Name) + if err := pb.handleJavaAgentInit(req.Option, pod, &add); err != nil { + log.InjectScope().Errorf("handle polaris-javaagent-init inject for pod=[%s, %s] failed: %v", pod.Namespace, pod.Name, err) + } + } + added[index] = add + } + // 重新更新请求参数中的 req.External + req.External = added + log.InjectScope().Infof("finish deal polaris-javaagent-init inject for pod=[%s, %s] added: %#v", pod.Namespace, pod.Name, added) + return pb.PodPatchBuilder.PatchContainer(req) + case inject.PatchType_Update: + return pb.updateContainer(req.Option, req.Option.SidecarMode, req.Option.Pod, req.Option.Pod.Spec.Containers, req.BasePath), nil + } + return nil, nil } func (pb *PodPatchBuilder) handleJavaAgentInit(opt *inject.PatchOptions, pod *corev1.Pod, add *corev1.Container) error { - annonations := pod.Annotations - log.InjectScope().Infof("handle polaris-javaagent-init inject for pod=[%s, %s] annonations: %#v image: %s", - pod.Namespace, pod.Name, pod.Annotations, add.Image) - // 判断用户是否自定义了 javaagent 的版本 - oldImageInfo := strings.Split(add.Image, ":") - if len(oldImageInfo) > 1 { - opt.ExternalInfo[customJavaAgentVersion] = oldImageInfo[1] - } - if val, ok := annonations[customJavaAgentVersion]; ok && val != "" { - add.Image = fmt.Sprintf("%s:%s", oldImageInfo[0], val) - opt.ExternalInfo[customJavaAgentVersion] = val - } + annonations := pod.Annotations + log.InjectScope().Infof("handle polaris-javaagent-init inject for pod=[%s, %s] annonations: %#v image: %s", + pod.Namespace, pod.Name, pod.Annotations, add.Image) + // 判断用户是否自定义了 javaagent 的版本 + oldImageInfo := strings.Split(add.Image, ":") + if len(oldImageInfo) > 1 { + opt.ExternalInfo[customJavaAgentVersion] = oldImageInfo[1] + } + if val, ok := annonations[customJavaAgentVersion]; ok && val != "" { + add.Image = fmt.Sprintf("%s:%s", oldImageInfo[0], val) + opt.ExternalInfo[customJavaAgentVersion] = val + } - frameworkName, frameworkNameOk := annonations[customJavaAgentPluginFramework] - if !frameworkNameOk { - log.InjectScope().Warnf("handle polaris-javaagent-init inject for pod=[%s, %s] not found frameworkName", - pod.Namespace, pod.Name) - } + frameworkName, frameworkNameOk := annonations[customJavaAgentPluginFramework] + if !frameworkNameOk { + log.InjectScope().Warnf("handle polaris-javaagent-init inject for pod=[%s, %s] not found frameworkName", + pod.Namespace, pod.Name) + } - frameworkVersion, frameworkVersionOk := annonations[customJavaAgentPluginFrameworkVersion] - if !frameworkVersionOk { - log.InjectScope().Warnf("handle polaris-javaagent-init inject for pod=[%s, %s] not found frameworkVersion", - pod.Namespace, pod.Name) - } + frameworkVersion, frameworkVersionOk := annonations[customJavaAgentPluginFrameworkVersion] + if !frameworkVersionOk { + log.InjectScope().Warnf("handle polaris-javaagent-init inject for pod=[%s, %s] not found frameworkVersion", + pod.Namespace, pod.Name) + } - pluginType := frameworkName + frameworkVersion - if frameworkName != "" && frameworkVersion != "" { - add.Env = append(add.Env, corev1.EnvVar{ - Name: "JAVA_AGENT_PLUGIN_TYPE", - Value: pluginType, - }) - add.Env = append(add.Env, corev1.EnvVar{ - Name: "JAVA_AGENT_FRAMEWORK_NAME", - Value: frameworkName, - }) - add.Env = append(add.Env, corev1.EnvVar{ - Name: "JAVA_AGENT_FRAMEWORK_VERSION", - Value: frameworkVersion, - }) - } + pluginType := frameworkName + frameworkVersion + if frameworkName != "" && frameworkVersion != "" { + add.Env = append(add.Env, corev1.EnvVar{ + Name: "JAVA_AGENT_PLUGIN_TYPE", + Value: pluginType, + }) + add.Env = append(add.Env, corev1.EnvVar{ + Name: "JAVA_AGENT_FRAMEWORK_NAME", + Value: frameworkName, + }) + add.Env = append(add.Env, corev1.EnvVar{ + Name: "JAVA_AGENT_FRAMEWORK_VERSION", + Value: frameworkVersion, + }) + } - defaultParam := map[string]string{ - "MicroserviceName": opt.Annotations[util.SidecarServiceName], - "PolarisServerIP": strings.Split(polarisapi.PolarisGrpc, ":")[0], - "PolarisDiscoverPort": strings.Split(polarisapi.PolarisGrpc, ":")[1], - "PolarisConfigIP": strings.Split(polarisapi.PolarisConfigGrpc, ":")[0], - "PolarisConfigPort": strings.Split(polarisapi.PolarisConfigGrpc, ":")[1], - } + defaultParam := map[string]string{ + "MicroserviceName": opt.Annotations[util.SidecarServiceName], + "PolarisServerIP": strings.Split(polarisapi.PolarisGrpc, ":")[0], + "PolarisDiscoverPort": strings.Split(polarisapi.PolarisGrpc, ":")[1], + "PolarisConfigIP": strings.Split(polarisapi.PolarisConfigGrpc, ":")[0], + "PolarisConfigPort": strings.Split(polarisapi.PolarisConfigGrpc, ":")[1], + } - add.Env = append(add.Env, - corev1.EnvVar{ - Name: "POLARIS_SERVER_IP", - Value: defaultParam["PolarisServerIP"], - }, - corev1.EnvVar{ - Name: "POLARIS_DISCOVER_IP", - Value: defaultParam["PolarisServerIP"], - }, - corev1.EnvVar{ - Name: "POLARIS_DISCOVER_PORT", - Value: defaultParam["PolarisDiscoverPort"], - }, - corev1.EnvVar{ - Name: "POLARIS_CONFIG_IP", - Value: defaultParam["PolarisConfigIP"], - }, - corev1.EnvVar{ - Name: "POLARIS_CONFIG_PORT", - Value: defaultParam["PolarisConfigPort"], - }, - ) - defaultProperties := make(map[string]string) - // 判断是不是老版本,如果是老版本且客户填写的版本号不为空则走老的逻辑,否则走新的逻辑,只下发北极星的地址和端口信息 - newImageInfo := strings.Split(add.Image, ":") - if _, valid := oldAgentVersions[newImageInfo[1]]; valid { - kubeClient := opt.KubeClient - pluginCm, err := kubeClient.CoreV1().ConfigMaps(util.RootNamespace).Get(context.Background(), - "plugin-default.properties", metav1.GetOptions{}) - if err != nil { - return err - } - tpl, err := template.New(pluginType).Parse(pluginCm.Data[nameOfPluginDefault(pluginType)]) - if err != nil { - return err - } - buf := new(bytes.Buffer) - if err := tpl.Execute(buf, defaultParam); err != nil { - return err - } - scanner := bufio.NewScanner(strings.NewReader(buf.String())) - scanner.Split(bufio.ScanLines) - for scanner.Scan() { - line := scanner.Text() - // 注释不放在 defaultProperties 中 - if !strings.HasPrefix(line, "#") { - kvs := strings.Split(line, "=") - if len(kvs) == 2 && kvs[0] != "" && kvs[1] != "" { - defaultProperties[strings.TrimSpace(kvs[0])] = strings.TrimSpace(kvs[1]) - } - } - } - } + add.Env = append(add.Env, + corev1.EnvVar{ + Name: "POLARIS_SERVER_IP", + Value: defaultParam["PolarisServerIP"], + }, + corev1.EnvVar{ + Name: "POLARIS_DISCOVER_IP", + Value: defaultParam["PolarisServerIP"], + }, + corev1.EnvVar{ + Name: "POLARIS_DISCOVER_PORT", + Value: defaultParam["PolarisDiscoverPort"], + }, + corev1.EnvVar{ + Name: "POLARIS_CONFIG_IP", + Value: defaultParam["PolarisConfigIP"], + }, + corev1.EnvVar{ + Name: "POLARIS_CONFIG_PORT", + Value: defaultParam["PolarisConfigPort"], + }, + ) + defaultProperties := make(map[string]string) + // 判断是不是老版本,如果是老版本且客户填写的版本号不为空则走老的逻辑,否则走新的逻辑,只下发北极星的地址和端口信息 + newImageInfo := strings.Split(add.Image, ":") + if _, valid := oldAgentVersions[newImageInfo[1]]; valid { + kubeClient := opt.KubeClient + pluginCm, err := kubeClient.CoreV1().ConfigMaps(util.RootNamespace).Get(context.Background(), + "plugin-default.properties", metav1.GetOptions{}) + if err != nil { + return err + } + tpl, err := template.New(pluginType).Parse(pluginCm.Data[nameOfPluginDefault(pluginType)]) + if err != nil { + return err + } + buf := new(bytes.Buffer) + if err := tpl.Execute(buf, defaultParam); err != nil { + return err + } + scanner := bufio.NewScanner(strings.NewReader(buf.String())) + scanner.Split(bufio.ScanLines) + for scanner.Scan() { + line := scanner.Text() + // 注释不放在 defaultProperties 中 + if !strings.HasPrefix(line, "#") { + kvs := strings.Split(line, "=") + if len(kvs) == 2 && kvs[0] != "" && kvs[1] != "" { + defaultProperties[strings.TrimSpace(kvs[0])] = strings.TrimSpace(kvs[1]) + } + } + } + // 查看用户是否自定义了相关配置信息 + // 需要根据用户的自定义参数信息,将 agent 的特定 application.properties 文件注入到 javaagent-init 中 + if properties, ok := annonations[customJavaAgentPluginConfig]; ok { + customProperties := map[string]string{} + if err := json.Unmarshal([]byte(properties), &customProperties); err != nil { + return err + } + // 先从 configmap 中获取 java-agent 不同 plugin-type 的默认配置信息 + for k, v := range customProperties { + defaultProperties[k] = v + } + } - // 查看用户是否自定义了相关配置信息 - // 需要根据用户的自定义参数信息,将 agent 的特定 application.properties 文件注入到 javaagent-init 中 - if properties, ok := annonations[customJavaAgentPluginConfig]; ok { - customProperties := map[string]string{} - if err := json.Unmarshal([]byte(properties), &customProperties); err != nil { - return err - } - // 先从 configmap 中获取 java-agent 不同 plugin-type 的默认配置信息 - for k, v := range customProperties { - defaultProperties[k] = v - } - } + exportAgentPluginConf := "" + for key, value := range defaultProperties { + exportAgentPluginConf += fmt.Sprintf("%s=%s\n", key, value) + } - exportAgentPluginConf := "" - for key, value := range defaultProperties { - exportAgentPluginConf += fmt.Sprintf("%s=%s\n", key, value) - } + add.Env = append(add.Env, corev1.EnvVar{ + Name: "JAVA_AGENT_PLUGIN_CONF", + Value: exportAgentPluginConf, + }) + } - add.Env = append(add.Env, corev1.EnvVar{ - Name: "JAVA_AGENT_PLUGIN_CONF", - Value: exportAgentPluginConf, - }) - return nil + return nil } func nameOfPluginDefault(v string) string { - return v + "-default-properties" + return v + "-default-properties" } func (pb *PodPatchBuilder) updateContainer(opt *inject.PatchOptions, sidecarMode utils.SidecarMode, pod *corev1.Pod, - target []corev1.Container, basePath string) []inject.Rfc6902PatchOperation { + target []corev1.Container, basePath string) []inject.Rfc6902PatchOperation { - patchs := make([]inject.Rfc6902PatchOperation, 0, len(target)) + patchs := make([]inject.Rfc6902PatchOperation, 0, len(target)) - for index, container := range target { - envs := container.Env - javaEnvIndex := -1 - if len(envs) != 0 { - for i := range envs { - if envs[i].Name == "JAVA_TOOL_OPTIONS" { - javaEnvIndex = i - break - } - } - if javaEnvIndex != -1 { - oldVal := envs[javaEnvIndex].Value - envs[javaEnvIndex] = corev1.EnvVar{ - Name: "JAVA_TOOL_OPTIONS", - Value: oldVal + " " + fmt.Sprintf(ActiveJavaAgentCmd, opt.ExternalInfo[customJavaAgentVersion]), - } - } - } - if javaEnvIndex == -1 { - // 注入 java agent 需要用到的参数信息 - container.Env = append(container.Env, corev1.EnvVar{ - Name: "JAVA_TOOL_OPTIONS", - Value: fmt.Sprintf(ActiveJavaAgentCmd, opt.ExternalInfo[customJavaAgentVersion]), - }) - } + for index, container := range target { + envs := container.Env + javaEnvIndex := -1 + if len(envs) != 0 { + for i := range envs { + if envs[i].Name == "JAVA_TOOL_OPTIONS" { + javaEnvIndex = i + break + } + } + if javaEnvIndex != -1 { + oldVal := envs[javaEnvIndex].Value + envs[javaEnvIndex] = corev1.EnvVar{ + Name: "JAVA_TOOL_OPTIONS", + Value: oldVal + " " + fmt.Sprintf(ActiveJavaAgentCmd, opt.ExternalInfo[customJavaAgentVersion]), + } + } + } + if javaEnvIndex == -1 { + // 注入 java agent 需要用到的参数信息 + container.Env = append(container.Env, corev1.EnvVar{ + Name: "JAVA_TOOL_OPTIONS", + Value: fmt.Sprintf(ActiveJavaAgentCmd, opt.ExternalInfo[customJavaAgentVersion]), + }) + } - // container 需要新挂载磁盘 - container.VolumeMounts = append(container.VolumeMounts, - corev1.VolumeMount{ - Name: "java-agent-dir", - MountPath: "/app/lib/.polaris/java_agent", - }) + // container 需要新挂载磁盘 + container.VolumeMounts = append(container.VolumeMounts, + corev1.VolumeMount{ + Name: "java-agent-dir", + MountPath: "/app/lib/.polaris/java_agent", + }) - path := basePath - path += "/" + strconv.Itoa(index) - patchs = append(patchs, inject.Rfc6902PatchOperation{ - Op: "replace", - Path: path, - Value: container, - }) - } - return patchs + path := basePath + path += "/" + strconv.Itoa(index) + patchs = append(patchs, inject.Rfc6902PatchOperation{ + Op: "replace", + Path: path, + Value: container, + }) + } + return patchs } func (pb *PodPatchBuilder) PatchVolumes(req *inject.OperateVolumesRequest) ([]inject.Rfc6902PatchOperation, error) { - return pb.PodPatchBuilder.PatchVolumes(req) + return pb.PodPatchBuilder.PatchVolumes(req) } func (pb *PodPatchBuilder) PatchImagePullSecrets(req *inject.OperateImagePullSecretsRequest) ([]inject.Rfc6902PatchOperation, error) { - return pb.PodPatchBuilder.PatchImagePullSecrets(req) + return pb.PodPatchBuilder.PatchImagePullSecrets(req) } func (pb *PodPatchBuilder) PatchSecurityContext() ([]inject.Rfc6902PatchOperation, error) { - return nil, nil + return nil, nil } func (pb *PodPatchBuilder) PatchDnsConfig() ([]inject.Rfc6902PatchOperation, error) { - return nil, nil + return nil, nil } From a44b16fcdfb6f311730122d0ee131549ef80b030 Mon Sep 17 00:00:00 2001 From: shuhanliu Date: Wed, 3 Jul 2024 16:54:14 +0800 Subject: [PATCH 3/6] not issue JAVA_AGENT_PLUGIN_CONF --- pkg/inject/pkg/kube/inject/apply/javaagent/patch.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go b/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go index ccca79d..5584995 100644 --- a/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go +++ b/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go @@ -18,6 +18,7 @@ import ( "bufio" "bytes" "context" + "encoding/json" "fmt" "strconv" "strings" From d69c8a9c120440b2366324c861bdbbb2b9212ecc Mon Sep 17 00:00:00 2001 From: shuhanliu Date: Wed, 3 Jul 2024 17:30:54 +0800 Subject: [PATCH 4/6] change agent jar path --- pkg/inject/pkg/kube/inject/apply/javaagent/patch.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go b/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go index 5584995..08908af 100644 --- a/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go +++ b/pkg/inject/pkg/kube/inject/apply/javaagent/patch.go @@ -52,7 +52,7 @@ var oldAgentVersions = map[string]struct{}{ } const ( - ActiveJavaAgentCmd = "-javaagent:/app/lib/.polaris/java_agent/polaris-java-agent-%s/polaris-agent-core-bootstrap.jar" + ActiveJavaAgentCmd = "-javaagent:/app/lib/.polaris/java_agent/polaris-java-agent/polaris-agent-core-bootstrap.jar" ) func init() { @@ -242,7 +242,7 @@ func (pb *PodPatchBuilder) updateContainer(opt *inject.PatchOptions, sidecarMode oldVal := envs[javaEnvIndex].Value envs[javaEnvIndex] = corev1.EnvVar{ Name: "JAVA_TOOL_OPTIONS", - Value: oldVal + " " + fmt.Sprintf(ActiveJavaAgentCmd, opt.ExternalInfo[customJavaAgentVersion]), + Value: oldVal + " " + ActiveJavaAgentCmd, } } } @@ -250,7 +250,7 @@ func (pb *PodPatchBuilder) updateContainer(opt *inject.PatchOptions, sidecarMode // 注入 java agent 需要用到的参数信息 container.Env = append(container.Env, corev1.EnvVar{ Name: "JAVA_TOOL_OPTIONS", - Value: fmt.Sprintf(ActiveJavaAgentCmd, opt.ExternalInfo[customJavaAgentVersion]), + Value: ActiveJavaAgentCmd, }) } From c689456bae2869fb8968a6b37d8860de7463535c Mon Sep 17 00:00:00 2001 From: shuhanliu Date: Fri, 5 Jul 2024 15:09:26 +0800 Subject: [PATCH 5/6] change javaagent configmap --- .../kubernetes/javaagent-configmap.yaml | 67 ++++++++++++++++++- .../kubernetes/javaagent-configmap.yaml | 67 ++++++++++++++++++- 2 files changed, 130 insertions(+), 4 deletions(-) diff --git a/deploy/kubernetes_v1.21/kubernetes/javaagent-configmap.yaml b/deploy/kubernetes_v1.21/kubernetes/javaagent-configmap.yaml index fc4a735..a25d677 100644 --- a/deploy/kubernetes_v1.21/kubernetes/javaagent-configmap.yaml +++ b/deploy/kubernetes_v1.21/kubernetes/javaagent-configmap.yaml @@ -66,6 +66,69 @@ data: spring.cloud.tencent.metadata.content.zone="" spring.cloud.tencent.metadata.content.campus="" + spring-cloud2022-default-properties: |+ + # 应用名称 + spring.application.name={{ .MicroserviceName }} + # 配置北极星服务端地址 + spring.cloud.polaris.address=grpc\://{{ .PolarisServerIP }}\:{{ .PolarisDiscoverPort }} + spring.cloud.polaris.enabled=true + + # 启用 Java Agent 的 Spring Cloud Tencent 注册发现能力 + spring.cloud.discovery.enabled=true + # 配置服务注册发现的命名空间信息 + spring.cloud.polaris.discovery.namespace=default + # 启用从北极星 + spring.cloud.polaris.discovery.enabled=true + spring.cloud.polaris.discovery.register=true + + ## 是否启用北极星的 LoadBalancer + spring.cloud.polaris.loadbalancer.enabled=true + #spring.cloud.polaris.loadbalancer.discoveryType=POLARIS + #spring.cloud.polaris.loadbalancer.strategy=random + + ## 是否启用北极星服务路由能力 + spring.cloud.polaris.router.enabled=true + # 是否启用北极星的自定义路由能力 + spring.cloud.polaris.router.rule-router.enabled=true + # 是否启用北极星的元数据路由能力 + spring.cloud.polaris.router.metadata-router.enabled=true + # 是否启用北极星的就近路由能力 + spring.cloud.polaris.router.nearby-router.enabled=true + + ## 是否启用北极星的服务限流能力 + spring.cloud.polaris.ratelimit.enabled=false + # 设置触发限流时的提示信息 + # spring.cloud.polaris.ratelimit.rejectRequestTips="" + # 设置触发限流时的响应码 + spring.cloud.polaris.ratelimit.rejectHttpCode=429 + # 设置限流匀速排队最大排队时间 + spring.cloud.polaris.ratelimit.maxQueuingTime=1000 + + ## 是否启用优雅上下线功能 + spring.cloud.polaris.lossless.enabled=true + spring.cloud.polaris.lossless.port=28080 + spring.cloud.polaris.lossless.delayRegisterInterval=30000 + + ## RPC 调用增强 + spring.cloud.tencent.rpc-enhancement.enabled=true + # 开启 RPC 调用结果上报 + spring.cloud.tencent.rpc-enhancement.reporter.enabled=true + + ## 是否启用北极星的服务熔断能力 + spring.cloud.polaris.circuitbreaker.enabled=true + + # 配置北极星监控指标上报 + spring.cloud.polaris.stat.enabled=false + # 指标上报监听端口 + spring.cloud.polaris.stat.port=0 + # 指标上报暴露的 http path + spring.cloud.polaris.stat.path=/metrics + + # 地域信息 + spring.cloud.tencent.metadata.content.region="" + spring.cloud.tencent.metadata.content.zone="" + spring.cloud.tencent.metadata.content.campus="" + spring-cloud2021-default-properties: |+ # 应用名称 spring.application.name={{ .MicroserviceName }} @@ -196,7 +259,7 @@ data: spring.cloud.polaris.router.nearby-router.enabled=true ## 是否启用北极星的服务限流能力 - spring.cloud.polaris.ratelimit.enabled=true + spring.cloud.polaris.ratelimit.enabled=false # 设置触发限流时的提示信息 # spring.cloud.polaris.ratelimit.rejectRequestTips="" # 设置触发限流时的响应码 @@ -210,7 +273,7 @@ data: spring.cloud.tencent.rpc-enhancement.reporter.enabled=false ## 是否启用北极星的服务熔断能力 - spring.cloud.polaris.circuitbreaker.enabled=true + spring.cloud.polaris.circuitbreaker.enabled=false # 配置北极星监控指标上报 spring.cloud.polaris.stat.enabled=false diff --git a/deploy/kubernetes_v1.22/kubernetes/javaagent-configmap.yaml b/deploy/kubernetes_v1.22/kubernetes/javaagent-configmap.yaml index 49d7bf1..b19b86a 100644 --- a/deploy/kubernetes_v1.22/kubernetes/javaagent-configmap.yaml +++ b/deploy/kubernetes_v1.22/kubernetes/javaagent-configmap.yaml @@ -65,6 +65,69 @@ data: spring.cloud.tencent.metadata.content.region="" spring.cloud.tencent.metadata.content.zone="" spring.cloud.tencent.metadata.content.campus="" + + spring-cloud2022-default-properties: |+ + # 应用名称 + spring.application.name={{ .MicroserviceName }} + # 配置北极星服务端地址 + spring.cloud.polaris.address=grpc\://{{ .PolarisServerIP }}\:{{ .PolarisDiscoverPort }} + spring.cloud.polaris.enabled=true + + # 启用 Java Agent 的 Spring Cloud Tencent 注册发现能力 + spring.cloud.discovery.enabled=true + # 配置服务注册发现的命名空间信息 + spring.cloud.polaris.discovery.namespace=default + # 启用从北极星 + spring.cloud.polaris.discovery.enabled=true + spring.cloud.polaris.discovery.register=true + + ## 是否启用北极星的 LoadBalancer + spring.cloud.polaris.loadbalancer.enabled=true + #spring.cloud.polaris.loadbalancer.discoveryType=POLARIS + #spring.cloud.polaris.loadbalancer.strategy=random + + ## 是否启用北极星服务路由能力 + spring.cloud.polaris.router.enabled=true + # 是否启用北极星的自定义路由能力 + spring.cloud.polaris.router.rule-router.enabled=true + # 是否启用北极星的元数据路由能力 + spring.cloud.polaris.router.metadata-router.enabled=true + # 是否启用北极星的就近路由能力 + spring.cloud.polaris.router.nearby-router.enabled=true + + ## 是否启用北极星的服务限流能力 + spring.cloud.polaris.ratelimit.enabled=false + # 设置触发限流时的提示信息 + # spring.cloud.polaris.ratelimit.rejectRequestTips="" + # 设置触发限流时的响应码 + spring.cloud.polaris.ratelimit.rejectHttpCode=429 + # 设置限流匀速排队最大排队时间 + spring.cloud.polaris.ratelimit.maxQueuingTime=1000 + + ## 是否启用优雅上下线功能 + spring.cloud.polaris.lossless.enabled=true + spring.cloud.polaris.lossless.port=28080 + spring.cloud.polaris.lossless.delayRegisterInterval=30000 + + ## RPC 调用增强 + spring.cloud.tencent.rpc-enhancement.enabled=true + # 开启 RPC 调用结果上报 + spring.cloud.tencent.rpc-enhancement.reporter.enabled=true + + ## 是否启用北极星的服务熔断能力 + spring.cloud.polaris.circuitbreaker.enabled=false + + # 配置北极星监控指标上报 + spring.cloud.polaris.stat.enabled=false + # 指标上报监听端口 + spring.cloud.polaris.stat.port=0 + # 指标上报暴露的 http path + spring.cloud.polaris.stat.path=/metrics + + # 地域信息 + spring.cloud.tencent.metadata.content.region="" + spring.cloud.tencent.metadata.content.zone="" + spring.cloud.tencent.metadata.content.campus="" spring-cloud2021-default-properties: |+ # 应用名称 @@ -196,7 +259,7 @@ data: spring.cloud.polaris.router.nearby-router.enabled=true ## 是否启用北极星的服务限流能力 - spring.cloud.polaris.ratelimit.enabled=true + spring.cloud.polaris.ratelimit.enabled=false # 设置触发限流时的提示信息 # spring.cloud.polaris.ratelimit.rejectRequestTips="" # 设置触发限流时的响应码 @@ -210,7 +273,7 @@ data: spring.cloud.tencent.rpc-enhancement.reporter.enabled=false ## 是否启用北极星的服务熔断能力 - spring.cloud.polaris.circuitbreaker.enabled=true + spring.cloud.polaris.circuitbreaker.enabled=false # 配置北极星监控指标上报 spring.cloud.polaris.stat.enabled=false From 73e99d673a44ca6bf0f96b4be612b56d214af8fa Mon Sep 17 00:00:00 2001 From: shuhanliu Date: Fri, 5 Jul 2024 15:19:26 +0800 Subject: [PATCH 6/6] change javaagent configmap --- deploy/kubernetes_v1.21/kubernetes/javaagent-configmap.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/kubernetes_v1.21/kubernetes/javaagent-configmap.yaml b/deploy/kubernetes_v1.21/kubernetes/javaagent-configmap.yaml index a25d677..8fd0e29 100644 --- a/deploy/kubernetes_v1.21/kubernetes/javaagent-configmap.yaml +++ b/deploy/kubernetes_v1.21/kubernetes/javaagent-configmap.yaml @@ -115,7 +115,7 @@ data: spring.cloud.tencent.rpc-enhancement.reporter.enabled=true ## 是否启用北极星的服务熔断能力 - spring.cloud.polaris.circuitbreaker.enabled=true + spring.cloud.polaris.circuitbreaker.enabled=false # 配置北极星监控指标上报 spring.cloud.polaris.stat.enabled=false