英文:
How to send a log message to Datadog Vector from k6
问题
我们有一些带有矢量数据源的Datadog Vector应用程序。
我们想要使用k6进行断点和负载测试的性能测试。
然而,k6中没有现有的插件适用于这种用例。
数据源的实现是一个GRPC端点,因此应该可以使用k6的GRPC客户端来实现这一目的。
如果有任何已经这样做的人愿意分享他们的示例,我将不胜感激。
英文:
We have some Datadog Vector applications with vector datasources.
We would like to run some performance tests using k6 for breakpoint and load tests.
However there there is not existing plugin in k6 for this use case.
The datasource implementation is a GRPC endpoint, therefore it should be possible to use k6 GRPC client for this purpose.
I would really appreciate if anybody who did this would share their example.
答案1
得分: 0
我们需要从Datadog Vector的Git仓库中获取两个protobuf定义:
https://github.com/vectordotdev/vector/blob/master/lib/vector-core/proto/event.proto
https://github.com/vectordotdev/vector/blob/master/proto/vector.proto
将它们放入以下文件夹结构中:
./definitions/vector.proto
./definitions/vector.proto
./k6_test.js
k6测试的内容如下:
import {check, sleep} from 'k6';
import grpc from 'k6/net/grpc';
import encoding from 'k6/encoding';
const client = new grpc.Client();
client.load(['definitions'], 'event.proto', 'vector.proto');
export default () => {
client.connect('vector-logs:6000', {
plaintext: true
});
const data = {
events: [
{
log: {
fields: {
field1: {integer: 111},
field2: {boolean: true}
},
value: {
map: {
fields: {
message: {raw_bytes: encoding.b64encode("message from k6")}
}
}
},
metadata: {
map: {
fields: {
key111: {raw_bytes: encoding.b64encode("value1")},
key2: {raw_bytes: encoding.b64encode("value2")}
}
}
}
}
}
]
};
const response = client.invoke('vector.Vector/PushEvents', data);
check(response, {
'status is OK': (r) => r && r.status === grpc.StatusOK
});
console.log(JSON.stringify(response.message));
client.close();
sleep(1);
};
我创建了一个包含整数、布尔、字符串和映射内容类型的消息示例。如果您需要其他类型,请参考:https://protobuf.dev/programming-guides/proto3/#json
PS:我对Rust、k6和protobuf几乎没有经验,因此请将其视为示例。
英文:
We would need 2 proto buf definitions from Datadog vector git repo:
https://github.com/vectordotdev/vector/blob/master/lib/vector-core/proto/event.proto
https://github.com/vectordotdev/vector/blob/master/proto/vector.proto
Put them into following folder structure:
./definitions/vector.proto
./definitions/vector.proto
./k6_test.js
Contents for k6 test
import {check, sleep} from 'k6';
import grpc from 'k6/net/grpc';
import encoding from 'k6/encoding';
const client = new grpc.Client();
client.load(['definitions'], 'event.proto', 'vector.proto');
export default () => {
client.connect('vector-logs:6000', {
plaintext: true
});
const data = {
events: [
{log: {
fields: {
field1: {integer: 111},
field2: {boolean: true},
},
value: {
map: {
fields: {
message: {raw_bytes: encoding.b64encode("message from k6")}
}
}
},
metadata: {
map: {
fields: {
key111: {
raw_bytes: encoding.b64encode("value1")
},
key2: {
raw_bytes: encoding.b64encode("value2")
}
}
}
}
}
}
]
}
const response = client.invoke('vector.Vector/PushEvents', data);
check(response, {
'status is OK': (r) => r && r.status === grpc.StatusOK,
});
console.log(JSON.stringify(response.message));
client.close();
sleep(1);
};
I've create example for messages with int, boolean, string and map content types.
In case if you need any other types, you might need to consult with: https://protobuf.dev/programming-guides/proto3/#json
PS: I have almost zero experience with rust, k6 and protobuf therefore treat it just as an example.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论