-
Notifications
You must be signed in to change notification settings - Fork 9
Implement Content Updater JobScheduler #387
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
base: 6.0.0
Are you sure you want to change the base?
Conversation
Add toXContent logic to ContentUpdater Job parameters Remove unnecesary code from build.gradle
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 have some proposals, but overall everything is right.
plugins/content-manager/src/main/java/com/wazuh/contentmanager/index/ContentIndex.java
Show resolved
Hide resolved
plugins/content-manager/src/main/java/com/wazuh/contentmanager/client/CTIClient.java
Show resolved
Hide resolved
...ent-manager/src/main/java/com/wazuh/contentmanager/jobscheduler/ContentUpdaterJobRunner.java
Show resolved
Hide resolved
Signed-off-by: Álex Ruiz Becerra <alejandro.ruiz.becerra@wazuh.com>
integTest { | ||
// The --debug-jvm command-line option makes the cluster debuggable; this makes the tests debuggable | ||
if (System.getProperty("test.debug") != null) { | ||
jvmArgs '-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005' | ||
} | ||
environment "IS_DEV", System.getenv("IS_DEV") ?: "false" |
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.
What is this for?
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.
Since the required indices are managed by the setup
plugin I needed a way to enable creation of the indices only on development environments.
// @TODO do we want an IS_DEV variable? | ||
if (System.getenv("IS_DEV").equals("true") && localNode.isClusterManagerNode()) { | ||
this.contextIndex.createIndex(); | ||
this.contentIndex.createIndex(); |
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 content index wazuh-cve
is created by the initialization plugin. We only check for its existence here.
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 used the IS_DEV
environment variable to ease development and testing. If the variable is set, the indices are created. Otherwise errors are thrown when running the plugin without the setup
plugin.
plugins/content-manager/src/main/java/com/wazuh/contentmanager/ContentManagerPlugin.java
Outdated
Show resolved
Hide resolved
plugins/content-manager/src/main/java/com/wazuh/contentmanager/client/CTIClient.java
Outdated
Show resolved
Hide resolved
public void createIndex() { | ||
if (!this.exists()) { | ||
client.admin().indices().create(new CreateIndexRequest(INDEX_NAME)).actionGet(); | ||
} | ||
} | ||
|
||
/** | ||
* Checks whether the {@link ContentIndex#INDEX_NAME} index exists. | ||
* | ||
* @see ClusterInfo#indexExists(Client, String) | ||
* @return true if the index exists, false otherwise. | ||
*/ | ||
public boolean exists() { | ||
return ClusterInfo.indexExists(this.client, ContentIndex.INDEX_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.
The content index is created by the initialization plugin.
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.
This is used by onNodeStarted()
when the IS_DEV
variable is set up. Otherwise the snapshot/update process is not triggered.
plugins/content-manager/src/main/java/com/wazuh/contentmanager/index/ContextIndex.java
Outdated
Show resolved
Hide resolved
@@ -137,6 +195,7 @@ public ConsumerInfo get(String context, String consumer) { | |||
"Fetched consumer from the [{}] index: {}", ContextIndex.INDEX_NAME, this.consumerInfo); | |||
} catch (InterruptedException | ExecutionException | TimeoutException e) { | |||
log.error("Failed to fetch consumer [{}][{}]: {}", context, consumer, e.getMessage()); | |||
this.consumerInfo = new ConsumerInfo(consumer, context, 0L, 0L, ""); |
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.
We need to somehow distinguish between a valid consumer with offset 0, or having no consumer information at all (not yet initialized) We return null in this case, as documented in the method's signature.
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.
Previously, null
was returned here, but both a 0
offset and a null
ConsumerInfo
object were handled in the same conditional expression (both were ORed). So for all practical purposes, a zero offset and a null object were the same.
I considered this case and concluded that 0
is not a valid remote offset.
Let me know your thoughts on this.
...-manager/src/main/java/com/wazuh/contentmanager/jobscheduler/ContentUpdaterJobParameter.java
Outdated
Show resolved
Hide resolved
...ent-manager/src/main/java/com/wazuh/contentmanager/jobscheduler/ContentUpdaterJobRunner.java
Outdated
Show resolved
Hide resolved
...tent-manager/src/main/java/com/wazuh/contentmanager/jobscheduler/ContentUpdaterRunnable.java
Outdated
Show resolved
Hide resolved
plugins/content-manager/src/main/java/com/wazuh/contentmanager/updater/ContentUpdater.java
Show resolved
Hide resolved
plugins/content-manager/src/main/java/com/wazuh/contentmanager/utils/Privileged.java
Outdated
Show resolved
Hide resolved
plugins/content-manager/src/main/java/com/wazuh/contentmanager/utils/SnapshotManager.java
Show resolved
Hide resolved
/** | ||
* Alternate constructor that allows injecting CommandManagerClient for test purposes. Dependency | ||
* injection. | ||
* | ||
* @param environment Needed for snapshot file handling. | ||
* @param contextIndex Handles context and consumer related metadata. | ||
* @param contentIndex Handles indexed content. | ||
* @param privileged Handles privileged actions. | ||
* @param ctiClient Instance of CTIClient. | ||
* @param commandManagerClient Instance of CommandManagerClient. | ||
*/ | ||
public SnapshotManager( | ||
Environment environment, | ||
ContextIndex contextIndex, | ||
ContentIndex contentIndex, | ||
Privileged privileged, | ||
CTIClient ctiClient, | ||
CommandManagerClient commandManagerClient) { | ||
this.ctiClient = ctiClient; | ||
this.commandManagerClient = commandManagerClient; | ||
this.environment = environment; | ||
this.contextIndex = contextIndex; | ||
this.contentIndex = contentIndex; | ||
this.privileged = privileged; | ||
this.pluginSettings = PluginSettings.getInstance(); | ||
} |
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.
Probably duplicated. This and the previous constructor are similar and can fit the same use case.
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.
This was added after the merge
plugins/content-manager/src/main/java/com/wazuh/contentmanager/utils/SnapshotManager.java
Outdated
Show resolved
Hide resolved
log.debug("Latest consumer info: {}", latest); | ||
|
||
// Consumer is not yet initialized. Initialize to latest. | ||
if (current == null || current.getOffset() == 0) { |
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.
Consumer's initialization should only happen when it's not ye initialized (null or offset == 0). We are losing this condition now.
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 current
object is created with a zeroed offset. It cannot be null by the point it reaches this expression
plugins/content-manager/src/test/java/com/wazuh/contentmanager/utils/SnapshotManagerTests.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Fede Galland <99492720+f-galland@users.noreply.github.com>
/** Scheduled jobs index name. */ | ||
public static final String JOB_INDEX = ".content_updater_jobs"; | ||
|
||
/** Scheduled job ID. */ | ||
public static final String JOB_ID = "content_updater_job"; |
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.
Could we store these constants into PluginSettings
?
Description
Job Scheduler implementation for the Content Updater module
Issues Resolved
Closes: #366