Skip to content
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

add correlation rule layer for events-correlation-engine #7132

Merged
merged 2 commits into from
Apr 17, 2023

Conversation

sbcd90
Copy link
Contributor

@sbcd90 sbcd90 commented Apr 12, 2023

Description

add correlation rule layer for events-correlation-engine

Issues Resolved

#6854

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

Copy link
Collaborator

@nknize nknize left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round review. Let's get a solid foundation here and iterate quickly in followup PRs.

CHANGELOG.md Outdated Show resolved Hide resolved
@sbcd90 sbcd90 force-pushed the corr2 branch 2 times, most recently from ca63ad7 to 9f43a02 Compare April 13, 2023 19:39
@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

Copy link
Collaborator

@nknize nknize left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next round cleanup comments. It's coming together. We need to add the explicit javadoc checker and I left some cleanup comments. I think we can simplify the CorrelationConstants approach and possibly just remove that class altogether? If the public facing API needs it we might figure a cleaner way of doing it.

import java.util.stream.Collectors;
import java.util.stream.Stream;

public class EventsCorrelationPluginTransportIT extends OpenSearchIntegTestCase {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need javadocs here. all public classes will need javadocs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added javadocs

gradle/missing-javadoc.gradle Outdated Show resolved Hide resolved
@Override
public List<Route> routes() {
return List.of(
new Route(RestRequest.Method.POST, EventsCorrelationPlugin.CORRELATION_RULES_BASE_URI),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the RFC it looks like users can only create rules through the global _correlation endpoint.

POST /_correlation/rules

Request Body: 
{
  "correlate": [
    {
      "index": "vpc_flow",
      "query": "dstaddr:4.5.6.7 or dstaddr:4.5.6.6"
    },
    {
      "index": "windows",
      "query": "winlog.event_data.SubjectDomainName:NTAUTHORI*"
    },
    {
      "index": "ad_logs",
      "query": "ResultType:50126"
    },
    {
      "index": "app_logs",
      "query": "endpoint:/customer_records.txt"
    }
  ]
}

Would it also make sense to enable users to do this on a per index basis?

POST /my_ndex/_correlation/rule/{$rule_id}

where {$rule_id} is the (optional) existing rule

If so, we can do this in a follow up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will address this in follow-up pr.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe open an issue for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created the issue: #7184


void start() {
try {
if (!correlationRuleIndices.correlationRuleIndexExists()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, avoid negative conditionals.

Change to be explicit:

Suggested change
if (!correlationRuleIndices.correlationRuleIndexExists()) {
if (correlationRuleIndices.correlationRuleIndexExists() == false) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed this.

/**
* Settings for events-correlation-engine.
*
* @opensearch.api
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you also want to mark as @opensearch.experimental for now? It's largely superficial but a nice flag if you think these Settings might change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

marked as @opensearch.experimental

* @param correlationQueries list of correlation queries part of rule
*/
public CorrelationRule(String id, Long version, String name, List<CorrelationQuery> correlationQueries) {
this.id = id != null ? id : NO_ID;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just have another ctor that doesn't take an ID as a parameter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a new ctor.

*/
public CorrelationRule(String id, Long version, String name, List<CorrelationQuery> correlationQueries) {
this.id = id != null ? id : NO_ID;
this.version = version != null ? version : NO_VERSION;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, just have a ctor that doesn't take a version?

I think we can remove the CorrelationConstants#NO_ID and CorrelationConstants#NO_VERSION altogether.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a new ctor.
removed CorrelationConstants class.

@nknize
Copy link
Collaborator

nknize commented Apr 14, 2023

Also make sure you rebase from main to pick up some of the BWC version check fixes.

@sbcd90
Copy link
Contributor Author

sbcd90 commented Apr 15, 2023

hi @nknize , addressed all the review comments. also rebased from main. please have a look.

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

  • RESULT: UNSTABLE ❕
  • TEST FAILURES:
      1 org.opensearch.client.ReindexIT.testReindexTask

Copy link
Collaborator

@nknize nknize left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few minor nits. Otherwise LGTM!

}
},
"timestampField": {
"type": "text",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a long or date type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the timestamp field name which is a string.

@Override
public List<Route> routes() {
return List.of(
new Route(RestRequest.Method.POST, EventsCorrelationPlugin.CORRELATION_RULES_BASE_URI),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe open an issue for this?

@sbcd90
Copy link
Contributor Author

sbcd90 commented Apr 17, 2023

hi @nknize , thanks a lot for reviewing the pr. created a issue for follow-up on the comment above: #7184

@github-actions
Copy link
Contributor

Gradle Check (Jenkins) Run Completed with:

Copy link
Collaborator

@nknize nknize left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nknize nknize merged commit 2f5bf5b into opensearch-project:main Apr 17, 2023
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Support for HTTP/2 (server-side) ([#3847](https://github.com/opensearch-project/OpenSearch/pull/3847))
- Add getter for path field in NestedQueryBuilder ([#4636](https://github.com/opensearch-project/OpenSearch/pull/4636))
- Allow mmap to use new JDK-19 preview APIs in Apache Lucene 9.4+ ([#5151](https://github.com/opensearch-project/OpenSearch/pull/5151))
- Add events correlation engine plugin ([#6854](https://github.com/opensearch-project/OpenSearch/issues/6854))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to move this to the 2.x section assuming this is to be backported

Comment on lines +63 to +65
.collect(Collectors.toList());
Assert.assertTrue(
pluginInfos.stream()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick...no need to collect to a list here when you just use it as a stream again

@@ -204,5 +204,6 @@ public static class CommonFields {
public static final ParseField FORMAT = new ParseField("format");
public static final ParseField MISSING = new ParseField("missing");
public static final ParseField TIME_ZONE = new ParseField("time_zone");
public static final ParseField _META = new ParseField("_meta");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really a "common field throughout the project" if it is only used in one place. If you're sure this will be used any multiple places this is fine, otherwise it might be simpler to keep it defined where it is used.

Also, the leading underscore (in the Java constant name, not the text) technically violates the standard convention for constant names.

Maybe add a comment too unless you think the meaning of a "meta" field is self-evident.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, this could me moved to scope local once we start using it.

Comment on lines +27 to +31
private String correlationRuleId;

private CorrelationRule correlationRule;

private RestRequest.Method method;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be final?

Comment on lines +32 to +38
private String id;

private Long version;

private RestStatus status;

private CorrelationRule correlationRule;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be final?

*/
public IndexCorrelationRuleRequest(CorrelationRule correlationRule, RestRequest.Method method) {
super();
this.correlationRuleId = "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really okay for one of these instances to exist without a rule id? The meaning of a magic empty string is usually not clear. If this is really an optional field, it is better to store it as null and codify the behavior in the getter type by returning an Optional so that the caller has to explicitly deal with the set/not set cases.

@reta
Copy link
Collaborator

reta commented Apr 17, 2023

@nknize shouldn't the plugin go to sandbox?

@dblock
Copy link
Member

dblock commented Apr 17, 2023

What’s the plan for getting this into 2.x?

austintlee pushed a commit to austintlee/OpenSearch that referenced this pull request Apr 28, 2023
…project#7132)

Adds new correlation engine feature by way of a new 
`:plugins:events-correlation-engine` plugin. The endpoint is /_correlation 
and users can create new rules using the following example DSL:

{
   "name": "s3 to app logs",
   "correlate": [
     {
       "index": "s3_access_logs",
       "query": "aws.cloudtrail.eventName:ReplicateObject",
       "timestampField": "@timestamp",
       "tags": [
         "s3"
      ]
    }
  ]
}

Signed-off-by: Subhobrata Dey <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants