-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow YamlTemplateRegistry to fallback to TemplateResources #112615
Conversation
InputStream is = clazz.getResourceAsStream(name); | ||
if (is == null) { | ||
is = TemplateResources.class.getResourceAsStream("/"+clazz.getPackageName()+name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[For reviewers] I decided to use the package name as the folder in the template-resources so that we don't have to bloat the interface with fallback root path. Let me know if there is a better suggestion to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure I understand: this would mean that we'd have something like this on disk?
/path/to/override/template-resources/org.elasticsearch.xpack.apmdata/component-templates/whatever.yaml
Is that right? Do plugins live in their own Java module? If so would it make sense to use the module name, rather than the package name?
Is it possible to add a YAML REST test to apm-data showing the overrides working?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be the other way around? i.e. look for an override in template-resources first, and in the plugin second?
Hmm, this does make sense w.r.t. what the template resource is meant to do. I will make the changes.
Is that right?
Yes, I have a sample for this in https://github.com/elastic/elasticsearch/pull/112614/files
Do plugins live in their own Java module?
Not sure if I understand "Java module" correctly and my Java9++ is not that good but from what I can see, we haven't modularized apm-data plugin. I think it should be as simple as adding the correct module-info. If we do that, then we can use the module name. I will give it a shot.
Is it possible to add a YAML REST test to apm-data showing the overrides working?
We are not overriding in this PR, the fallback files are required by the plugin, and failing to locate them would be fatal for starting ES -- so, they are already be covered by the tests. Are you thinking about adding explicit tests to check if all the files are installed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm totally misunderstanding the approach. What I thought we were going to do is:
- Add the "-fallback@lifecycle" component templates in the plugin, in a way that would work with "stateful" Elasticsearch OOTB
- Allow these to be overridden by placing a component template of the same name in template-resources; if that exists, prefer using that
(I was not expecting to see any templates added to template-resources in #112614)
In terms of YAML REST tests, I was thinking we would:
- Add test cases for the scenarios laid out in New indexes created for datastreams after update to
8.15.0
are without lifecycle policies apm-server#13898 (comment) - Add another test case that adds an override
... but thinking about it some more, I'm not sure if (2) is possible. I had in mind that the overrides were on disk, but I think they're also embedded in a jar? Just it's a different jar in serverless vs. stateful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allow these to be overridden by placing a component template of the same name in template-resources; if that exists, prefer using that
Ah, I see the misunderstanding. The overrides for serverless are performed with files in https://github.com/elastic/elasticsearch-serverless/tree/main/libs/serverless-xpack-template-resources. I am not sure if we can override for serverless using template-resources (not sure how we can trigger the if/else condition i.e. if we are on serverless load this...). The approach suggested to us is to provide the fallback to ILM with the default apm-data plugin and override the fallback files for serverless to be empty.
... but thinking about it some more, I'm not sure if (2) is possible. I had in mind that the overrides were on disk, but I think they're also embedded in a jar? Just it's a different jar in serverless vs. stateful.
Exactly. Also, we could have added test if some version of apm-data supported ILM (by upgrading from that version) but with the current state of things, it is not straightforward and will require creating datastreams with ILMs and then applying the apm-data plugin... BTW, the current PR is only about introducing the fallback mechanism for loading template resources in YamlTemplateRegistry
, we can discuss more on the tests in the PR where we introduce the ILM files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good. I think using the module name should be a bit less brittle than the package name. Thinking again, ideally we'd use the plugin name. I'm not aware of a way to get that dynamically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR refactors YamlTemplateRegistry to fallback to TemplateResources for locating resource files if the plugin-module itself doesn't have the resources.
Should it be the other way around? i.e. look for an override in template-resources first, and in the plugin second?
InputStream is = clazz.getResourceAsStream(name); | ||
if (is == null) { | ||
is = TemplateResources.class.getResourceAsStream("/"+clazz.getPackageName()+name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure I understand: this would mean that we'd have something like this on disk?
/path/to/override/template-resources/org.elasticsearch.xpack.apmdata/component-templates/whatever.yaml
Is that right? Do plugins live in their own Java module? If so would it make sense to use the module name, rather than the package name?
Is it possible to add a YAML REST test to apm-data showing the overrides working?
Pinging @elastic/es-data-management (Team:Data Management) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @lahsivjar , thanks for picking this up. This is slightly different than I expected and I am curious about the following:
Have you considered to move all the APM resources to the template-resource so it can follow the same way of working like all the other resources, if yes, what stopped you from following that path?
I have concerns about the module name convention clazz.getModule().getName(). I am concerned that it introduces an implicit dependency. If you rename the module and you forget that this is used in a resource folder in a different place, it will break. Furthermore, the rest of the folders are not named like that, and it has the benefit that the names are shorter and easier to navigate.
I am curious about your thoughts.
I discussed this with @axw and we wanted to keep the resources in the plugin module itself as it is easier to maintain and manage. @axw do you have any other points to add here?
I think having the resource files in 2 places is an implicit dependency by itself. Also, since the folder structure inside template resources needs to follow what we would have in overrides, the same case kinda applies (if we rename a folder here we could end up breaking serverless). I think the better way would be to cover this via serverless tests, would that be possible? |
@lahsivjar Quick question have you tested this with serverless? To see that it works, I am asking because #112614 has failed tests. |
@lahsivjar I entertaining a new idea. Since in this case we do not want to override the component templates, we want them to not be there at all. What if we override the Line 150 in 079cc34
elasticsearch/server/src/main/java/org/elasticsearch/cluster/metadata/DataStreamLifecycle.java Line 59 in bed6e18
It's a new way of doing this, but I think it fits because this is using a setting to detect if ILM is supported and if not exclude these component templates. It removes the need of duplication of templates and introducing a lot of empty ones. Thoughts? |
I haven't added the PR for overriding files yet so it will fail for now.
I love the idea, let me see if I can make this work! |
Closing this, superseded by #112759 |
The PR refactors
YamlTemplateRegistry
to load from TemplateResources for locating resource files and fallbacks to the plugin-module itself if it can't locate the file in the TemplateResources (more details are in the java doc). It also introduces a convention to use the named-module's name as the folder name in theTemplateResource
to keep interfaces a bit simple.Related to
#112137
elastic/apm-server#13898