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

Use Stream Names for Content Packs #17089

Conversation

ryan-carroll-graylog
Copy link
Contributor

@ryan-carroll-graylog ryan-carroll-graylog commented Oct 26, 2023

Adds ability to create content packs with entities that reference Streams by title, to enable re-upload on another system where a stream with that title exists.

When creating a content pack, if a selected entity references a stream and the specified stream entity is not selected, a new Stream Reference entity type containing the Stream name will be used in the content pack.

When installing the content pack, the Stream Reference will be resolved to an existing Stream on the system with the exported name.

Description

Creates a new Stream reference content pack entity to be used when a stream dependent entity is exported without the stream itself. Also ads a new Stream reference facade class to cover the specific handling of these Stream reference entities during export/import etc.

Implementation notes:
I went with the new stream reference entity approach instead of using stream titles in place of the current stream IDs with versioning, because the latter required refactoring in every content pack entity class that uses streams in order to resolve back and forth between native entity stream IDs and content pack entity stream titles. Additionally this required adding special handling in the top level ContentPackService because of the way we resolve the entity dependency graphs linked by IDs and to omit decency streams but not streams that were selected by the user.

Open Questions:

  • If an entity with a Stream Reference dependency can't be resolved to one Stream upon installation, what should the behavior be?
    • Fail installation entirely
    • Omit stream from entity and proceed

TODO:

  • Add/update unit tests
  • Update Docs

Motivation and Context

Closes: #16885

How Has This Been Tested?

Locally in dev environment.

Testing notes:

  • Should be able to create and re-upload Content Packs that contain Stream referencing entities (E.x. Dashboards, Even Definitions), with and without the Streams and have them resolve the stream successfully upon import.
  • Should be able to successfully install an Illuminate pack using this new Stream reference entity.

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring (non-breaking change)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@ryan-carroll-graylog ryan-carroll-graylog changed the title Use stream names for content packs WIP: Use Stream Names for Content Packs Oct 27, 2023
@ryan-carroll-graylog
Copy link
Contributor Author

@kingzacko1 @danotorrey opening this up for initial reviews as the main functionality works (just for content packs with filter/aggregation Event Definitions).

I need to implement this for all stream dependent content pack entities but wanted to get y'all's feedback on the approach. After experimenting with a few options this was the cleanest way I could come up with to get this done.

Need to also verify with the SecCon team that this satisfies their need but based on the Engineering week discussion it seems like it should.

@danotorrey
Copy link
Contributor

@ryan-carroll-graylog Apologies, I did not have a chance to review this today, but I will do that as soon as I am back next week.

@ryan-carroll-graylog ryan-carroll-graylog changed the title WIP: Use Stream Names for Content Packs Use Stream Names for Content Packs Nov 7, 2023
@ryan-carroll-graylog ryan-carroll-graylog marked this pull request as ready for review November 7, 2023 14:38
@ryan-carroll-graylog ryan-carroll-graylog marked this pull request as draft November 7, 2023 15:55
@ryan-carroll-graylog ryan-carroll-graylog marked this pull request as ready for review November 7, 2023 19:01
@kingzacko1
Copy link
Contributor

Creating a new revision of the content packs with stream_title entities doesn't seem to work. The stream_title entity no longer exists, is not available to be added, and the new revision cannot be installed after download. @ryan-carroll-graylog

@ryan-carroll-graylog
Copy link
Contributor Author

Creating a new revision of the content packs with stream_title entities doesn't seem to work. The stream_title entity no longer exists, is not available to be added, and the new revision cannot be installed after download. @ryan-carroll-graylog

Thanks for catching this @kingzacko1. I had originally tried to avoid exposing the Stream title entities to the UI for the list of available entities (just to limit possible confusion), but this is clearly a use case where it's needed.

Looks like the stream titles need to be there to be included in what the front end passes back for existing entities to be included in the revision.

With the latest commit the revisions should work correctly. Stream title entities are now included in the available entity list, but otherwise the behavior is the same whether or not a user explicitly includes a dependent stream title.

ryan-carroll-graylog and others added 3 commits November 13, 2023 13:46
…lar Streams. Irrellevant to content packs but was causing problems for start page and related tests.
@danotorrey danotorrey self-assigned this Nov 14, 2023
Copy link
Contributor

@danotorrey danotorrey left a comment

Choose a reason for hiding this comment

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

@ryan-carroll-graylog I have been reviewing and testing, and this is looking really solid. This looks like a great design. And, it fits well backwards compatibility-wise, since the export of an entity attached to a stream was not previously possible unless the stream was associated. This is a really nice way to gain that capability.

My testing of importing content packs with the stream reference all were successful.

I hit one snag though: I exported a content pack with a dashboard including selecting a widget's stream to include it in the content pack too (to test the existing supported path of including both). It worked successfully on the first import to another Graylog system, but for some reason, after uninstalling it and attempting to reinstall, I am hitting this error. I've not figured out why that is happening.

throw new ContentPackException("Missing Stream for widget entity");

ERROR: org.graylog2.shared.rest.exceptionmappers.AnyExceptionClassMapper - Unhandled exception in REST resource
org.graylog2.contentpacks.exceptions.ContentPackException: Failed to install content pack <4d08689c-03fa-4a75-9534-0d4573a94815/1>
	at org.graylog2.contentpacks.ContentPackService.installContentPack(ContentPackService.java:161) ~[classes/:?]
	at org.graylog2.contentpacks.ContentPackService.installContentPack(ContentPackService.java:102) ~[classes/:?]
	at org.graylog2.rest.resources.system.contentpacks.ContentPackResource.installContentPack(ContentPackResource.java:295) ~[classes/:?]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
	...
Caused by: org.graylog2.contentpacks.exceptions.ContentPackException: Stream with title <Illuminate:Cisco Device Messages> does not exist!
	at org.graylog2.contentpacks.facades.StreamReferenceFacade.findExisting(StreamReferenceFacade.java:153) ~[classes/:?]
	at org.graylog2.contentpacks.facades.StreamReferenceFacade.findExisting(StreamReferenceFacade.java:123) ~[classes/:?]
	at org.graylog2.contentpacks.ContentPackService.installContentPack(ContentPackService.java:134) ~[classes/:?]
	... 29 more

Here's the content pack:
content-pack-ebe297d5-469c-4c5c-a978-0a1ca7d558ce-1.json

I was also testing with installing/uninstalling this content pack that only has the dashboard and the stream reference. Not sure it that somehow impacted the issue.
content-pack-4d08689c-03fa-4a75-9534-0d4573a94815-1.json

@@ -52,6 +52,10 @@ public interface StreamService extends PersistedService {

List<Stream> loadAllEnabled();

default List<Stream> loadAllByTitle(String title) {
throw new UnsupportedOperationException("loadAllByTitle method not implemented");
Copy link
Contributor

Choose a reason for hiding this comment

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

Great idea to add the default method here. One potential improvement suggestion: Instead of throwing the unsupported exception, could it be implemented using the existing loadAll() method and a title filter? Definitely not as efficient as the Mongo implementation, but perhaps could be used as a backup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! No reason not to have the naive implementation as the default. Just updated the function as suggested.

@ryan-carroll-graylog
Copy link
Contributor Author

I hit one snag though:

@danotorrey I think I've tracked this down to a separate potential bug in master. I created a separate PR with some more details as I'm thinking it's best to tackle separately but would love your feedback: #17370

@danotorrey
Copy link
Contributor

@danotorrey I think I've tracked this down to a separate potential bug in master. I created a separate PR with some more details as I'm thinking it's best to tackle separately but would love your feedback: #17370

Great work @ryan-carroll-graylog! I will take a look on Monday morn.

Copy link
Contributor

@danotorrey danotorrey left a comment

Choose a reason for hiding this comment

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

@ryan-carroll-graylog I tested every combination I could think of, and all is testing successfully with latest code. All LGTM and tests successfully. Very well done working through this! I am sure folks will really enjoy using this new functionality in Illuminate.

Copy link
Contributor

@kingzacko1 kingzacko1 left a comment

Choose a reason for hiding this comment

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

Nice work on all of this @ryan-carroll-graylog!

@ryan-carroll-graylog ryan-carroll-graylog merged commit c8dc8bd into master Nov 21, 2023
6 checks passed
@ryan-carroll-graylog ryan-carroll-graylog deleted the 16885-update-content-pack-system-to-handle-streams-by-name-rather-than-id branch November 21, 2023 16:46
ryan-carroll-graylog added a commit that referenced this pull request Dec 6, 2023
* Use stream names for content packs

* Cleanup

* Fix install

* cleanup

* remove unused import

* Handle multiple streams better, minor name refactoring

* Add handling for the rest of the entity types that reference streams

* Fix line spacing

* Add missing license header

* Fix failing tests

* Add changelog entry

* Return StreamReference Entity Exerpts to front end to ensure proper handling of existing entities

* Use Stream title to generate excerpt IDs to avoid collision with regular Streams. Irrellevant to content packs but was causing problems for start page and related tests.

* Add default naive implementation of StreamService loadAllByTitle()

* Resolve stream deps for dashboard widgets
ryan-carroll-graylog added a commit that referenced this pull request Dec 8, 2023
* Use stream names for content packs

* Cleanup

* Fix install

* cleanup

* remove unused import

* Handle multiple streams better, minor name refactoring

* Add handling for the rest of the entity types that reference streams

* Fix line spacing

* Add missing license header

* Fix failing tests

* Add changelog entry

* Return StreamReference Entity Exerpts to front end to ensure proper handling of existing entities

* Use Stream title to generate excerpt IDs to avoid collision with regular Streams. Irrellevant to content packs but was causing problems for start page and related tests.

* Add default naive implementation of StreamService loadAllByTitle()

* Resolve stream deps for dashboard widgets
@htolic
Copy link

htolic commented Jan 9, 2024

Hi everyone here,
I think this change introduced regression on /api/authz/shares/entities/{entityGRN}/prepare API endpoint. If I click Share button on any event definition at /alerts/definitions the error is: {"type":"ApiError","message":"type <stream_title> does not exist"}

@ryan-carroll-graylog
Copy link
Contributor Author

Hi everyone here, I think this change introduced regression on /api/authz/shares/entities/{entityGRN}/prepare API endpoint. If I click Share button on any event definition at /alerts/definitions the error is: {"type":"ApiError","message":"type <stream_title> does not exist"}

Thank you @htolic!

I am also able to reproduce this with any Stream scoped Event Definition. I'm investigating further now and will open an issue.

@ryan-carroll-graylog
Copy link
Contributor Author

Hi everyone here, I think this change introduced regression on /api/authz/shares/entities/{entityGRN}/prepare API endpoint. If I click Share button on any event definition at /alerts/definitions the error is: {"type":"ApiError","message":"type <stream_title> does not exist"}

Thank you @htolic!

I am also able to reproduce this with any Stream scoped Event Definition. I'm investigating further now and will open an issue.

Here's the opened issue: #17882

In the mean time a workaround to share entities with users is:

  1. Remove any Streams from entity that needs to be shared
  2. Share the entity (and dependent Stream)
  3. Add Stream back to the entity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Content Pack system to handle Streams by name rather than ID
4 participants