paras200 commented on code in PR #986: URL: https://github.com/apache/ranger/pull/986#discussion_r3382319204
########## audit-server/audit-dispatcher/dispatcher-opensearch/src/main/java/org/apache/ranger/audit/dispatcher/OpenSearchDispatcherManager.java: ########## @@ -0,0 +1,208 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ranger.audit.dispatcher; + +import org.apache.ranger.audit.dispatcher.kafka.AuditDispatcher; +import org.apache.ranger.audit.dispatcher.kafka.AuditDispatcherTracker; +import org.apache.ranger.audit.dispatcher.kafka.AuditOpenSearchDispatcher; +import org.apache.ranger.audit.provider.MiscUtil; +import org.apache.ranger.audit.server.AuditServerConstants; +import org.apache.ranger.audit.utils.AuditServerLogFormatter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Properties; + +public final class OpenSearchDispatcherManager { + private static final Logger LOG = LoggerFactory.getLogger(OpenSearchDispatcherManager.class); + private static final String CONFIG_DISPATCHER_TYPE = AuditServerConstants.PROP_DISPATCHER_TYPE; + private static final String TYPE_OPENSEARCH = "opensearch"; + private static final String ES_DEST_PROP = "xasecure.audit.destination.elasticsearch"; Review Comment: The current approach reuses `xasecure.audit.destination.elasticsearch` intentionally — here's why: The dispatcher uses the Elasticsearch low-level `RestClient` (not `RestHighLevelClient`) to talk to OpenSearch, which is wire-compatible with ES. The enablement flag `xasecure.audit.destination.elasticsearch=true` was chosen because the dispatcher doesn't have a corresponding `OpenSearchAuditDestination` class in `agents-audit` — unlike Solr, where `dispatcher-solr` delegates to the existing `SolrAuditDestination` class and shares the `xasecure.audit.destination.solr.*` namespace. Simply renaming to `xasecure.audit.destination.opensearch` creates a half-measure: the property name implies an `OpenSearchAuditDestination` class exists (following the pattern in `AuditProviderFactory.getProviderFromConfig()`), but it doesn't — there's no `"opensearch"` case mapped in that factory, and plugins couldn't write directly to OpenSearch. **Proposed approach (follow-up PR):** To do this properly, I'd like to introduce a full `OpenSearchAuditDestination` class in `agents-audit` (following the `SolrAuditDestination` pattern), register `"opensearch"` in `AuditProviderFactory`, and have the dispatcher delegate to it — exactly as `dispatcher-solr` delegates to `SolrAuditDestination`. This would: 1. Enable `xasecure.audit.destination.opensearch=true` with proper semantics 2. Allow plugins to write audits directly to OpenSearch (bypassing Kafka) if needed 3. Share connection/write logic between the plugin path and the dispatcher 4. Use the `xasecure.audit.destination.opensearch.*` namespace consistently for urls/port/index/user/password For this PR, I've kept the `elasticsearch` namespace since the dispatcher's inlined REST logic is functionally equivalent to talking to an ES-compatible backend. The dedicated `OpenSearchAuditDestination` + namespace rename can follow as a separate PR once we align on the approach. Would you prefer we add `OpenSearchAuditDestination` in this PR itself, or is a follow-up acceptable? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
