Create a new ElasticsearchDatastreamWriter to more efficiently store data in elasticsearch.
PR for #10576. For right now, this will be hidden behind a build-flag, until the feature is sufficiently tested and ready for production use. For all the changes made to the original elasticsearch writer, please consult the individual commits.
https://github.com/Icinga/icinga2/pull/10577#pullrequestreview-3334293923 Hi, thanks for having a look at it, I really appreciate it.
I'd suggest you squash down your commits [...]
I left the commits separate deliberately, so it's easier to review. Each commit can be looked at on their own, without having to reason about all changes at once.
Thank you for this PR. I've briefly spoken to @lippserd about this and I'm going to take another look when I can. I know next to nothing about Elasticsearch yet, so it might take some until I can test this thoroughly.
Hi,
Just a hint, I recently addressed other issue with the ElasticsearchWriter format here https://github.com/Icinga/icinga2/issues/10511
I provided a small but breaking change here: https://github.com/Icinga/icinga2/pull/10518
If the ElasticsearchDatastreamWriter is introduced, both Writers should use the same format, right?
@jschmidt-icinga let me know if you need help with Elasticsearch knowhow, you know where my office is.
FYI, I think this would also (somewhat) addresses this issue https://github.com/Icinga/icinga2/issues/9837
With datastreams the backing indices are managed by Elasticsearch.
Thanks @martialblog for the insight. I'd encourage you to read the commit messages, as I tried to lay out my reasoning for some decisions there. Also, take a look at the example config file, as I think it clears up some of your concerns.
@w1ll-i-code Maybe we need to handle fact that CheckCommand object can have names that are not allowed and index names.
For example:
object CheckCommand "example_FOOBAR_bar-foo" {
import "ping-common"
command += [ "-4" ]
vars.ping_address = "$address$"
}
apply Service "ping1" {
import "generic-service"
check_command = "example_FOOBAR_bar-foo"
assign where host.address
}
object CheckCommand "i like icinga" {
import "ping-common"
command += [ "-4" ]
vars.ping_address = "$address$"
}
apply Service "foobar" {
import "generic-service"
check_command = "i like icinga"
assign where host.address
}
This will result in:
[2025-10-31 13:15:29 +0000] warning/ElasticsearchDatastreamWriter: Error during document creation: illegal_argument_exception: data_stream [metrics-icinga2.example_FOOBAR_bar-foo-default] must be lowercase
[2025-10-31 13:15:51 +0000] warning/ElasticsearchDatastreamWriter: Error during document creation: illegal_argument_exception: data_stream [metrics-icinga2.i like icinga-default] must not contain the following characters ['?','*','<','"',' ','','/',',','|','>']
Not sure yet what a good solution might be. Maybe some form of normalization, maybe just letting the users know they need to be careful with the object names, maybe both.
@w1ll-i-code I've resolved all the conversations solved by your last push but there are still some outstanding comments not yet addressed. Can you please fix those and I think we're good from my side.
Hi,I had to change the @timestamp field from cr->GetScheduleEnd() to cr->GetExecutionEnd() because it was miss-behaving with passive checks over the API.
@w1ll-i-code Please also address my last review comment above.
Edit: This might also be a good point where you squash down your PR to one or two commits. I'd suggest one commit for the entire DatastreamWriter and one for the changes to remote/endpoint. Documentation changes could also be separate commit if you prefer.
@jschmidt-icinga @martialblog I have run into two small things while testing that I would like to address first:
- For some reason on one test system icinga2 is giving me timestamps two hours in the future, which breaks writing to the datastream with the error:
[2025-11-26 10:52:13 +0000] debug/ElasticsearchDatastreamWriter: Error response: {"_id":null,"_index":"metrics-icinga2.ps-master","error":{"reason":"the document timestamp [2025-11-26T12:53:38.000Z] is outside of ranges of currently writable indices [[2025-11-26T08:38:47.000Z,2025-11-26T11:25:09.000Z]]","type":"timestamp_error"},"status":400}
The time config on all nodes seems to be all correct:
---- neteye01 ---------------------------------------------------
Wed Nov 26 11:17:05 UTC 2025
Local time: Wed 2025-11-26 11:17:05 UTC
Universal time: Wed 2025-11-26 11:17:05 UTC
RTC time: Wed 2025-11-26 11:17:03
Time zone: UTC (UTC, +0000)
System clock synchronized: no
NTP service: active
RTC in local TZ: no
---- neteye02 ---------------------------------------------------
Wed Nov 26 11:16:47 UTC 2025
Local time: Wed 2025-11-26 11:16:47 UTC
Universal time: Wed 2025-11-26 11:16:47 UTC
RTC time: Wed 2025-11-26 11:16:43
Time zone: UTC (UTC, +0000)
System clock synchronized: no
NTP service: active
RTC in local TZ: no
---- neteye03 ---------------------------------------------------
Wed Nov 26 11:17:28 UTC 2025
Local time: Wed 2025-11-26 11:17:28 UTC
Universal time: Wed 2025-11-26 11:17:28 UTC
RTC time: Wed 2025-11-26 11:17:26
Time zone: UTC (UTC, +0000)
System clock synchronized: no
NTP service: active
RTC in local TZ: no
- I noticed on the
diskcheck, the name for the performance data is just the file-path which breaks my normalization for the system root/which would be an empty string. Should we default to insert a default value if the perf data label only contains special characters?
I'd really appreciate if you could help me out there so we can close this issue.
Fixed the first one. Turns out one of the satellites was living two hours in the future.
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: William Calliari. This is most likely caused by a git client misconfiguration; please make sure to:
- check if your git client is configured with an email to sign commits
git config --list | grep email - If not, set it up using
git config --global user.email [email protected] - Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails
I noticed on the disk check, the name for the performance data is just the file-path which breaks my normalization for the system root / which would be an empty string. Should we default to insert a default value if the perf data label only contains special characters?
Yeah Johannes and I have been talking about this as well. Icinga2 object names are very flexible, the normalization needs to be quite robust.
Ideally it's collision-free, reversible (you might need the original name when rendering a chart) and human-readable (meaning the name of the checkcommand should be decipherable).
There are encodings like Base64 (not really human-readable and uses UPPERCASE) or hash functions like SHA (not reversible). We want something like "slugify", which is not really a standard and probably not collision-free.
I'm not sure yet what a good solution would be.
- Oh, apparently more stuff was merged? I rebased it before the squash of the commits.
- Yeah, I don't think a reversible and readable format is possible. I'm planning to do a follow-up PR anyways, just don't want this one hanging too long here. I can take a shot at it as well later.
- As for the check names, I discovered that the field names are far more forgiving than the index names. We just need to remove any dots from them. Again, we cannot use an array, as elasticsearch doesn't support them for timeseries data at the moment.
- I'll fix it and push the rebased commits.
Edit: Also, sorry for the long response times, I was on holiday.
- Yeah, I don't think a reversible and readable format is possible. I'm planning to do a follow-up PR anyways, just don't want this one hanging too long here. I can take a shot at it as well later.
I think that's reasonable. If we merge this soon I can also include the DatastreamWriter in #10668 and you can work on your follow-up PR in parallel. I'll approve this as soon as the checks all complete successfully. My colleagues still might want to weigh in, though.
Also, there was one other suggestion from one of my colleagues that I tend to agree with: You should move the index template to the source directory, i.e. to lib/perfdata/elasticsearch instead of usr/elasticsearch to avoid the additional top-level directory. There is precedence for this with the files in lib/db_ido_mysql/schema, which get installed to usr/share too.
@w1ll-i-code I've talked to @yhabteab and we think it's better to merge your PR into a feature branch first, where we can make some more adjustments until we merge it to master. I'll open another PR later where we can iterate a bit more on this without you needing to go through all the back and forth. Thank you for your contribution.