Skip to content

Commit

Permalink
Merge pull request #1715 from lilai23/feature_opentelemetry
Browse files Browse the repository at this point in the history
Fix args cannot take effect when dynamic install sermant agent with external agent and instance selectable condition in Backend
  • Loading branch information
Sherlockhan authored Dec 30, 2024
2 parents e07ef86 + 6ede784 commit b34b16a
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

/**
* agent core entrance
Expand Down Expand Up @@ -144,15 +145,21 @@ public static void install(String artifact, Map<String, Object> argsMap, Instrum
CommandProcessor.cacheInstrumentation(instrumentation);

// install external agent, such as OTEL
handleExternalAgentInstallation(instrumentation);
handleExternalAgentInstallation(instrumentation, isDynamic, argsMap);
}

private static void handleExternalAgentInstallation(Instrumentation instrumentation) {
private static void handleExternalAgentInstallation(Instrumentation instrumentation, boolean isDynamic,
Map<String, Object> argsMap) {
AgentConfig agentConfig = ConfigManager.getConfig(AgentConfig.class);
if (agentConfig.isExternalAgentInjection()) {
try {
ExternalAgentManager.installExternalAgent(false, agentConfig.getExternalAgentName(),
agentConfig.getExternalAgentFile(), null, instrumentation);
Map<String, String> args = null;
if (isDynamic) {
args = argsMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey,
entry -> entry.getValue() != null ? (String) entry.getValue() : null));
}
ExternalAgentManager.installExternalAgent(isDynamic, agentConfig.getExternalAgentName(),
agentConfig.getExternalAgentFile(), args, instrumentation);
} catch (Exception e) {
LOGGER.severe("Failed to install external agent: " + e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
Expand Down Expand Up @@ -191,8 +192,8 @@ static String loadAgentJar(String agentName, String agentPath, Instrumentation i
* @param argsMap arguments of dynamic installation
*/
static void setArgsToSystemProperties(Map<String, String> argsMap) {
for (String key : argsMap.keySet()) {
System.setProperty(key, argsMap.get(key));
for (Entry<String, String> entry : argsMap.entrySet()) {
System.setProperty(entry.getKey(), entry.getValue());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ public final class Tags {
* Key for the scope tag
*/
public static final String SCOPE = "scope";

/**
* Value for the core scope tag
*/
public static final String SCOPE_VALUE_CORE = "core";

private final Map<String, String> tags = new HashMap<>();

private Tags() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* @since 2024-12-18
*/
public enum MetricCommonTagEnum {

/**
* Define an AGENT tag with key "agent" and a constant value "sermant".
*/
Expand Down Expand Up @@ -64,10 +63,12 @@ public enum MetricCommonTagEnum {
/**
* Define an AGENT_VERSION tag with key "agent.version" and a value supplied by agent version
*/
AGENT_VERSION("agent.version", false, BootArgsIndexer::getCoreVersion),;
AGENT_VERSION("agent.version", false, BootArgsIndexer::getCoreVersion);

private final String key;

private final boolean defaultEnable;

private final Supplier<String> valueSupplier;

/**
Expand Down Expand Up @@ -121,8 +122,8 @@ public static Set<String> getDefaultKeys() {
}

/**
* Get the value of the tag corresponding to the given key.
* If the provided key is empty or does not correspond to any tag, return an empty string.
* Get the value of the tag corresponding to the given key. If the provided key is empty or does not correspond to
* any tag, return an empty string.
*
* @param key The key of the tag
* @return The value of the tag, or an empty string if no matching tag exists
Expand All @@ -138,5 +139,4 @@ public static String of(String key) {
}
return StringUtils.EMPTY;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,6 @@ private void handleError(Throwable throwable, String requestKey) {
Thread.sleep(DELAY_TIME);
} catch (InterruptedException e) {
LOGGER.log(Level.WARNING, "An error occurred in thread sleeping.", e);
Thread.currentThread().interrupt();
}
client.updateChannel();
subscribe(requestKey, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ private static XdsDelay parseDelay(FaultDelay faultDelay) {
* }
* }
* }
*}
* }
*
* @param typedStruct Serial protocol buffer message for rate limiting configuration
* @return Rate limiting configuration information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const messages = {
uninstallAgent: 'Uninstall Agent',
updatePlugin: 'Update Plugin',
updateAgent: 'Update Agent',
installExternalAgent: "Install External Agent",
installExternalAgent: 'Install External Agent',
commandTypePlaceholder: 'Please select The command type',
agentPathPlaceholder: 'Please input the Agent path',
pluginNamePlaceholder: 'Please enter the plugin name',
Expand All @@ -42,7 +42,7 @@ export const messages = {
commandType: 'Command Type',
pluginName: 'Plugin Name',
agentPath: 'Agent Path',
externalAgentName: "Agent Name",
externalAgentName: 'Agent Name',
param: 'Param',
instance: 'Instance',
version: 'Version',
Expand Down Expand Up @@ -134,8 +134,8 @@ export const messages = {
pluginInstall: 'Plugin Install',
pluginUninstall: 'Plugin Uninstall',
pluginUpdate: 'Plugin Update',
externalAgentInstall: "External Agent Install",
otelStart: "OTEL Agent Start",
externalAgentInstall: 'External Agent Install',
otelStart: 'OTEL Agent Start',
},
eventConfigView: {
event: 'Event',
Expand Down Expand Up @@ -298,7 +298,7 @@ export const messages = {
uninstallAgent: '卸载Agent',
updatePlugin: '升级插件',
updateAgent: '升级Agent',
installExternalAgent: "安装外部Agent",
installExternalAgent: '安装外部Agent',
commandTypePlaceholder: '请选择命令类型',
agentPathPlaceholder: '请输入Agent路径',
pluginNamePlaceholder: '请输入插件名称',
Expand All @@ -314,7 +314,7 @@ export const messages = {
commandType: '命令类型',
pluginName: '插件名称',
agentPath: 'Agent路径',
externalAgentName: "Agent名称",
externalAgentName: 'Agent名称',
param: '参数',
instance: '实例',
version: '版本',
Expand Down Expand Up @@ -406,8 +406,8 @@ export const messages = {
pluginInstall: '插件安装',
pluginUninstall: '插件卸载',
pluginUpdate: '插件更新',
externalAgentInstall: "安装外部Agent",
otelStart: "OTEL Agent启动",
externalAgentInstall: '安装外部Agent',
otelStart: 'OTEL Agent启动',
},
eventConfigView: {
event: '事件',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
</el-table-column>
<el-table-column :label="$t('instanceView.operation')" fixed="right" align="center" width="160">
<template #default="scope">
<div style="display: flex; flex-direction: column; gap: 10px;">
<div v-if="scope.row.health" style="display: flex; flex-direction: column; gap: 10px;">
<el-button
type="primary"
class="button-padding"
Expand Down Expand Up @@ -266,7 +266,7 @@ onMounted(() => {
const dialogFormVisible = ref(false)
const selectable = (row: TableData) => true
const selectable = (row: TableData) => row.health;
const goBack = () => {
router.push("/events");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import io.sermant.flowcontrol.common.handler.retry.Retry;
import io.sermant.flowcontrol.common.util.XdsThreadLocalUtil;
import io.sermant.flowcontrol.common.xds.retry.RetryCondition;

/**
* Retry condition check, determine if the current error is a connection reset error before the request, and trigger a
Expand All @@ -27,7 +26,7 @@
* @author zhp
* @since 2024-11-29
*/
public class ResetBeforeRequestErrorCondition extends ResetErrorCondition implements RetryCondition {
public class ResetBeforeRequestErrorCondition extends ResetErrorCondition {
@Override
public boolean needRetry(Retry retry, Throwable ex, String statusCode, Object result) {
return XdsThreadLocalUtil.getSendByteFlag() && super.needRetry(retry, ex, statusCode, result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.sermant.flowcontrol;

import io.sermant.core.exception.SermantRuntimeException;
import io.sermant.core.plugin.agent.entity.ExecuteContext;
import io.sermant.core.utils.LogUtils;
import io.sermant.core.utils.ReflectUtils;
Expand Down Expand Up @@ -192,7 +193,7 @@ private void initFunction() {
try {
return ((HttpServletResponse) obj).getWriter();
} catch (IOException ex) {
throw new RuntimeException(ex);
throw new SermantRuntimeException(ex);
}
};
setStatus = (obj, code) -> ((HttpServletResponse) obj).setStatus(code);
Expand Down

0 comments on commit b34b16a

Please sign in to comment.