Repository navigation
feat(opensearch sink): add first-class OpenSearch sink #26722
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
862522d
feat(opensearch sink): add first-class OpenSearch sink
pront aa1e24b
test(opensearch sink): simplify integration coverage
pront c3c9ad8
refactor(elasticsearch sink): deserialize distribution as an enum
pront f1b2f33
refactor(opensearch sink): select distribution in each constructor
pront 50b0644
fix(opensearch sink): attribute confinement warnings to the selected …
pront File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Add an `opensearch` sink for self-managed OpenSearch, Amazon OpenSearch Service, | ||
| and Amazon OpenSearch Serverless. It shares the Elasticsearch sink's configuration | ||
| options and delivery behavior. Automatic API version detection now recognizes | ||
| OpenSearch in both sinks, so an explicit `api_version: v7` is no longer needed. | ||
|
|
||
| authors: pront |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| use vector_lib::configurable::configurable_component; | ||
|
|
||
| use crate::{ | ||
| config::{ | ||
| AcknowledgementsConfig, GenerateConfig, Input, SinkConfig, SinkContext, ValidatedSink, | ||
| }, | ||
| sinks::{Healthcheck, VectorSink, elasticsearch::ElasticsearchConfig}, | ||
| template::ConfinementConfig, | ||
| }; | ||
|
|
||
| /// Configuration for the `opensearch` sink. | ||
| /// | ||
| /// Uses the Elasticsearch-compatible bulk API supported by OpenSearch. Configuration options | ||
| /// and defaults are shared with the `elasticsearch` sink, including automatic API version | ||
| /// detection and support for Amazon OpenSearch Service and OpenSearch Serverless. | ||
| #[configurable_component(sink("opensearch", "Index observability events in OpenSearch."))] | ||
| #[derive(Clone, Debug, Default)] | ||
| pub struct OpenSearchConfig(ElasticsearchConfig); | ||
|
|
||
| impl GenerateConfig for OpenSearchConfig { | ||
| fn generate_config() -> serde_json::Value { | ||
| ElasticsearchConfig::generate_config() | ||
| } | ||
| } | ||
|
|
||
| #[async_trait::async_trait] | ||
| #[typetag::serde(name = "opensearch")] | ||
| impl SinkConfig for OpenSearchConfig { | ||
| fn confinement_config(&self) -> Option<&ConfinementConfig> { | ||
| self.0.confinement_config() | ||
| } | ||
|
|
||
| fn input(&self) -> Input { | ||
| self.0.input() | ||
| } | ||
|
|
||
| fn acknowledgements(&self) -> &AcknowledgementsConfig { | ||
| self.0.acknowledgements() | ||
| } | ||
| } | ||
|
|
||
| #[async_trait::async_trait] | ||
| impl ValidatedSink for OpenSearchConfig { | ||
| type Validated = <ElasticsearchConfig as ValidatedSink>::Validated; | ||
|
|
||
| fn validate(&self) -> crate::Result<Self::Validated> { | ||
| self.0.validate() | ||
| } | ||
|
|
||
| async fn build( | ||
| &self, | ||
| validated: &Self::Validated, | ||
| cx: SinkContext, | ||
| ) -> crate::Result<(VectorSink, Healthcheck)> { | ||
| ValidatedSink::build(&self.0, validated, cx).await | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use crate::{ | ||
| config::BoxedSink, | ||
| sinks::elasticsearch::{ElasticsearchApiVersion, OpenSearchServiceType}, | ||
| }; | ||
|
|
||
| #[test] | ||
| fn generate_config() { | ||
| crate::test_util::test_generate_config::<OpenSearchConfig>(); | ||
| } | ||
|
|
||
| #[test] | ||
| fn config_roundtrip() { | ||
| let config: BoxedSink = serde_yaml::from_str( | ||
| r" | ||
| type: opensearch | ||
| endpoints: [http://localhost:9200] | ||
| bulk: | ||
| index: logs-%Y.%m.%d | ||
| acknowledgements: | ||
| enabled: true | ||
| ", | ||
| ) | ||
| .unwrap(); | ||
| assert!(config.acknowledgements().enabled()); | ||
| assert!(config.confinement_config().is_some()); | ||
| config.validate_dyn().unwrap(); | ||
|
|
||
| let value = serde_json::to_value(&config).unwrap(); | ||
| assert_eq!(value["type"], "opensearch"); | ||
| assert_eq!(value["bulk"]["index"], "logs-%Y.%m.%d"); | ||
| let roundtrip: BoxedSink = serde_json::from_value(value.clone()).unwrap(); | ||
| assert_eq!(serde_json::to_value(roundtrip).unwrap(), value); | ||
| } | ||
|
|
||
| #[test] | ||
| fn defaults_to_managed_with_automatic_api_detection() { | ||
| let config: OpenSearchConfig = | ||
| serde_yaml::from_str("endpoints: [http://localhost:9200]").unwrap(); | ||
| assert_eq!(config.0.api_version, ElasticsearchApiVersion::Auto); | ||
| assert_eq!( | ||
| config.0.opensearch_service_type, | ||
| OpenSearchServiceType::Managed | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn rejects_invalid_config() { | ||
| for yaml in [ | ||
| "type: opensearch", | ||
| "type: opensearch\nendpoints: [http://localhost:9200]\nbatch:\n max_events: 0", | ||
| "type: opensearch\nendpoints: [http://localhost:9200]\nbulk:\n index: '{{ index }}'", | ||
| "type: opensearch\nendpoints: [http://localhost:9200]\nopensearch_service_type: serverless", | ||
| ] { | ||
| let config: BoxedSink = serde_yaml::from_str(yaml).unwrap(); | ||
| assert!(config.validate_dyn().is_err()); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn rejects_unknown_options() { | ||
| assert!( | ||
| serde_yaml::from_str::<BoxedSink>( | ||
| "type: opensearch\nendpoints: [http://localhost:9200]\nunknown_option: true" | ||
| ) | ||
| .is_err() | ||
| ); | ||
| } | ||
|
|
||
| #[cfg(feature = "aws-core")] | ||
| #[test] | ||
| fn serverless_requires_aws_auth_and_automatic_api_detection() { | ||
| let yaml = r" | ||
| type: opensearch | ||
| endpoints: [https://collection.us-east-1.aoss.amazonaws.com] | ||
| opensearch_service_type: serverless | ||
| auth: | ||
| strategy: aws | ||
| aws: | ||
| region: us-east-1 | ||
| "; | ||
| let config: BoxedSink = serde_yaml::from_str(yaml).unwrap(); | ||
| config.validate_dyn().unwrap(); | ||
|
|
||
| let mut value = serde_json::to_value(config).unwrap(); | ||
| value["api_version"] = serde_json::json!("v7"); | ||
| let config: BoxedSink = serde_json::from_value(value).unwrap(); | ||
| assert!(config.validate_dyn().is_err()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.