@ 弹性/ opamp- 客户端- 节点
一个用于Node.js的开放代理管理协议(OpAMP)客户端.
使用量
这个OpAMP客户端的最小用途就是这样:
import {createOpAMPClient} from '@elastic/opamp-client-node';
const client = createOpAMPClient({endpoint: 'http://localhost:4320/v1/opamp'});
client.setAgentDescription({
identifyingAttributes: { 'service.name': 'minimal-example' },
});
client.start();
process.on('beforeExit', async () => {
await client.shutdown();
});
// ...
使用远程配置
以下是如何使用可选的 OpAMP 客户端 OpAMP 代理配置支持数字 :
import {
createOpAMPClient,
AgentCapabilities,
RemoteConfigStatuses
} from '@elastic/opamp-client-node';
const client = createOpAMPClient({
endpoint: 'http://localhost:4320/v1/opamp',
capabilities:
AgentCapabilities.AgentCapabilities_AcceptsRemoteConfig |
AgentCapabilities.AgentCapabilities_ReportsRemoteConfig,
onMessage: ({remoteConfig}) => {
if (remoteConfig) {
console.log('Got remote config:', remoteConfig);
// Apply the remote config.
// ...
// Report the remote config status.
client.setRemoteConfigStatus({
status: RemoteConfigStatuses.RemoteConfigStatuses_APPLIED,
lastRemoteConfigHash: remoteConfig.configHash,
});
}
},
});
client.setAgentDescription({
identifyingAttributes: { 'service.name': 'minimal-example' },
});
client.start();
process.on('beforeExit', async () => {
await client.shutdown();
});
// ...
使用 Agent 的 OpenTeleometry 资源Description
OpAMP 客户端需要 AgentDescription 运行。 此描述中包含哪些数据由用户决定, 但 OpAMP spec对什么语义公约有一些建议 资源属性 包括"SHOULD".
这里有一些代码,从一个 打开远程 JavaScript Resource数字 :
/**
* Copy properties from `fromObj` to `toObj` that match the given name
* patterns (`namePats`). This is a shallow copy.
*
* `namePats` supports an extremely limited subset of glob matching: if a
* pattern ends with an asterisk (`*`), then the rest of string is compared
* with `.startsWith()`. For example `cloud.*` matches a 'cloud.foo' property
* of `fromObj`. Otherwise the pattern uses an exact match.
*/
function pickProps(toObj, fromObj, namePats) {
const fromKeys = Object.keys(fromObj)
for (let namePat of namePats) {
if (namePat.endsWith('*')) {
const prefix = namePat.slice(0, -1);
for (let k of fromKeys) {
if (k.startsWith(prefix)) {
toObj[k] = fromObj[k];
}
}
} else {
if (namePat in fromObj) {
toObj[namePat] = fromObj[namePat];
}
}
}
return toObj;
};
const resource = ...;
const client = createOpAMPClient(...);
await resource?.waitForAsyncAttributes();
client.setAgentDescription({
identifyingAttributes: pickProps({}, resource.attributes, [
'service.name', 'service.namespace', 'service.version',
'service.instance.id',
]
nonIdentifyingAttributes: pickProps({}, resource.attributes, [
'os.type', 'os.version',
'host.*',
'cloud.*',
]
});
// ...
参考文献
TODO: 大部分参考文件
新闻
注:如果 ReportsRemoteConfig 建立了能力,由用户决定
调用 client.setRemoteConfigStatus(...) 视情况而定.
(TODO:这方面的例子)
TODO: 关于使用远程配置的更多细节 - 在Message不应该扔 - 应使用dupe数据处理多个呼叫:例如使用远程Config.configHash 减少工作。 应该处理 序列节点 配置Hash 检查应当同步 . - 提到如何设置状态 APLIED和失败 如果惊讶于配置 - 这需要建立报告检索能力 - 也许JSON配置有用.
可分割
TODO: doc this, 标记为实验性未承诺的 msg 结构
限制
- 只支持HTTP运输(没有WebSocket运输).
- 仅支持 spec 的子集: 没有Beta 或 Development 特性 除非另有说明。 TODO: 请具体说明