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 basic Fleet plugin #65275

Merged
merged 11 commits into from
Dec 3, 2020
Merged

Add basic Fleet plugin #65275

merged 11 commits into from
Dec 3, 2020

Conversation

gwbrown
Copy link
Contributor

@gwbrown gwbrown commented Nov 19, 2020

A very basic plugin to manage Fleet system indices.

Currently, just registers these patterns as system indices:

  • .fleet-servers*
  • .fleet-policies*
  • .fleet-agents*
  • .fleet-actions*

Relates to #64971

@gwbrown gwbrown added :Core/Infra/Core Core issues without another label v8.0.0 v7.11.0 labels Nov 19, 2020
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Nov 19, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

@aleksmaus
Copy link
Member

aleksmaus commented Nov 19, 2020

Thank you!

Could you please add support for

.fleet-actions
.fleet-action-results

as well maybe?

Currently coding agents actions with these assumptions. Could possibly change of course.

@jaymode
Copy link
Member

jaymode commented Nov 19, 2020

I think we need to move this to be a plugin within x-pack and change all headers to elastic ones

@pugnascotia
Copy link
Contributor

Are we able to prohibit direct access to just the Fleet indices? I ask because they're new, so we can start off by ensuring all consumers use the APIs. If it's an all-or-nothing settings, then nevermind.

@gwbrown
Copy link
Contributor Author

gwbrown commented Nov 19, 2020

Could you please add support for [...]

Yes, will update shortly.

I think we need to move this to be a plugin within x-pack and change all headers to elastic ones

Good call, will do. I spaced on the licensing aspect of it in my haste. For the Fleet folks, this won't change the endpoints or anything, it's just an internal change.

Are we able to prohibit direct access to just the Fleet indices?

I would be open to this in principle, but I'm not sure there's a great way to implement it without doing something like hardcoding these index patterns into IndexNameExpressionResolver.

new Object[] { ".fleet-policies-enrollment-keys" },
new Object[] { ".fleet-policies-inputs" },
new Object[] { ".fleet-agents" },
new Object[] { ".fleet-agents-checkins" }
Copy link
Contributor

Choose a reason for hiding this comment

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

These have changed slightly the following indexes are needed:

.fleet-servers
.fleet-policies
.fleet-policies-leader
.fleet-agents
.fleet-actions
.fleet-actions-results

As for the Agent check-ins that will occur in logs-elastic_agent.checkin-default. This will follow the indexing strategy of Fleet and will be a datastream. I don't know if this needs to be registered in this plugin or not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I'll update the indices shortly.

The dividing line is "Should a user ever directly query, visualize, and/or write to this index?" - if the answer is no, then it should probably be a system index. There's also a practical consideration in that there's no such thing as a "system data stream" (currently), so if being a data stream is a requirement, it can't be a system index.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the plugin to use this list and removed the ones which were not on the list.

Copy link
Contributor

Choose a reason for hiding this comment

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

A user should be able to directly query and visualize the logs-elastic_agent.checkin-default.


Request getRequest = new Request("GET", "/_fleet/" + indexName + "/_doc/1");
Response getResponse = client().performRequest(getRequest);
assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
assertOK(response);

Request searchRequest = new Request("GET", "/_fleet/" + indexName + "/_search");
searchRequest.setJsonEntity("{ \"query\" : { \"match_all\" : {} } }\n");
Response getResponse = client().performRequest(searchRequest);
assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assertThat(getResponse.getStatusLine().getStatusCode(), is(200));
assertOK(response);


Request deleteRequest = new Request("DELETE", "/_fleet/" + indexName + "/_doc/1");
Response deleteResponse = client().performRequest(deleteRequest);
assertThat(deleteResponse.getStatusLine().getStatusCode(), is(200));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assertThat(deleteResponse.getStatusLine().getStatusCode(), is(200));
assertOK(response);

Comment on lines 141 to 146
"{ \"index\" : { \"_index\" : \""
+ indexName
+ "\", \"_id\" : \"1\" } }\n{ \"foo\" : \"bar\" }\n"
+ "{ \"index\" : { \"_index\" : \""
+ indexName
+ "\", \"_id\" : \"2\" } }\n{ \"baz\" : \"tag\" }\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nothing to change, but I kinda wish we could do something like:

String.join("\n",
	toJson(Map.of("index", Map.of("_index", indexName, "_id", "1"))),
	toJson(Map.of("foo", "bar")),
	toJson(Map.of("index", Map.of("_index", indexName, "_id", "2"))),
	toJson(Map.of("baz", "tag"))
)

Request dbqRequest = new Request("POST", "/_fleet/" + indexName + "/_delete_by_query");
dbqRequest.setJsonEntity("{ \"query\" : { \"match_all\" : {} } }\n");
Response dbqResponse = client().performRequest(dbqRequest);
assertThat(dbqResponse.getStatusLine().getStatusCode(), is(200));
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
assertThat(dbqResponse.getStatusLine().getStatusCode(), is(200));
assertOK(response);

Copy link
Contributor

Choose a reason for hiding this comment

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

There's a bunch more, but I'll stop flagging them 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My find/replace missed a bunch! Thanks.

pugnascotia
pugnascotia previously approved these changes Nov 20, 2020
Copy link
Contributor

@pugnascotia pugnascotia left a comment

Choose a reason for hiding this comment

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

Can we add some JavaDoc, per the contributing guidelines?

@pugnascotia pugnascotia dismissed their stale review November 20, 2020 09:34

Clicked the wrong button

Copy link
Member

@jaymode jaymode left a comment

Choose a reason for hiding this comment

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

LGTM

@blakerouse
Copy link
Contributor

@gwbrown Anything that is blocking this from landing?

@gwbrown gwbrown merged commit 2c33f9f into elastic:master Dec 3, 2020
@gwbrown gwbrown deleted the fleet-plugin branch December 3, 2020 19:18
gwbrown added a commit to gwbrown/elasticsearch that referenced this pull request Dec 3, 2020
A very basic plugin to manage Fleet system indices.

Currently, just registers these patterns as system indices:
- `.fleet-servers*`
- `.fleet-policies*`
- `.fleet-agents*`
- `.fleet-actions*`
@aleksmaus
Copy link
Member

👍 Thank you!

gwbrown added a commit that referenced this pull request Dec 4, 2020
A very basic plugin to manage Fleet system indices.

Currently, just registers these patterns as system indices:
- `.fleet-servers*`
- `.fleet-policies*`
- `.fleet-agents*`
- `.fleet-actions*`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Core Core issues without another label >non-issue Team:Core/Infra Meta label for core/infra team v7.11.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants