Skip to content

Commit 022fa86

Browse files
authored
[RORDEV-1927][RORDEV-1929][RORDEV-1931] ES 9.3.0, 9.2.5, 8.19.11 support (#1209)
1 parent 802dfd1 commit 022fa86

File tree

10 files changed

+54
-27
lines changed

10 files changed

+54
-27
lines changed

ci/supported-es-versions/es8x.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
8.19.11
12
8.19.10
23
8.19.9
34
8.19.8

ci/supported-es-versions/es9x.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
9.3.0
2+
9.2.5
13
9.2.4
24
9.2.3
35
9.2.2

es818x/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
latestSupportedEsVersion=8.19.10
1+
latestSupportedEsVersion=8.19.11

es92x/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ dependencies {
3838
implementation project(path: ':core')
3939
implementation project(path: ':ror-tools', configuration: 'shadow')
4040
implementation project(path: ':ror-tools-core')
41-
implementation group: 'org.elasticsearch', name: 'elasticsearch' , version: moduleEsVersion
41+
implementation (group: 'org.elasticsearch', name: 'elasticsearch' , version: moduleEsVersion) {
42+
exclude group: 'org.elasticsearch', module: 'exponential-histogram'
43+
}
4244
implementation group: 'org.elasticsearch.client', name: 'elasticsearch-rest-client', version: moduleEsVersion
4345
implementation group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.14'
4446
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.1'

es92x/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
latestSupportedEsVersion=9.2.4
1+
latestSupportedEsVersion=9.3.0

es92x/src/main/scala/tech/beshu/ror/es/IndexLevelActionFilter.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ class IndexLevelActionFilter(clusterService: ClusterService,
167167
request,
168168
rorActionListener,
169169
chain,
170-
JavaConverters.flattenPair(threadPool.getThreadContext.getResponseHeaders).toCovariantSet
170+
JavaConverters.flattenPair(threadPool.getThreadContext.getResponseHeaders).toCovariantSet,
171+
esEnv.esVersion
171172
)
172173
)
173174
} recover {

es92x/src/main/scala/tech/beshu/ror/es/handler/AclAwareRequestFilter.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ import tech.beshu.ror.es.handler.request.context.types.repositories.*
7575
import tech.beshu.ror.es.handler.request.context.types.ror.*
7676
import tech.beshu.ror.es.handler.request.context.types.snapshots.*
7777
import tech.beshu.ror.es.handler.request.context.types.templates.*
78-
import tech.beshu.ror.es.{HidingInternalErrorDetailsRorActionListener, RorActionListener, RorClusterService, RorRestChannel, AtEsLevelUpdateActionResponseListener}
78+
import tech.beshu.ror.es.{EsVersion, HidingInternalErrorDetailsRorActionListener, RorActionListener, RorClusterService, RorRestChannel, AtEsLevelUpdateActionResponseListener}
7979
import tech.beshu.ror.implicits.*
8080
import tech.beshu.ror.syntax.*
8181

@@ -278,7 +278,8 @@ object AclAwareRequestFilter {
278278
val actionRequest: ActionRequest,
279279
val listener: RorActionListener[ActionResponse],
280280
val chain: EsChain,
281-
val threadContextResponseHeaders: Set[(String, String)]) {
281+
val threadContextResponseHeaders: Set[(String, String)],
282+
val esVersion: EsVersion) {
282283

283284
val timestamp: Instant = Instant.now()
284285

es92x/src/main/scala/tech/beshu/ror/es/handler/request/context/types/EsqlIndicesEsRequestContext.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp
4040
esContext: EsContext,
4141
aclContext: AccessControlStaticContext,
4242
clusterService: RorClusterService,
43-
override val threadPool: ThreadPool)
43+
override val threadPool: ThreadPool,
44+
esqlRequestHelper: EsqlRequestHelper)
4445
extends BaseFilterableEsRequestContext[ActionRequest with CompositeIndicesRequest](actionRequest, esContext, aclContext, clusterService, threadPool) {
4546

4647
override protected def requestFieldsUsage: RequestFieldsUsage = RequestFieldsUsage.NotUsingFields
4748

48-
private lazy val requestClassification = EsqlRequestHelper.classifyEsqlRequest(actionRequest)
49+
private lazy val requestClassification = esqlRequestHelper.classifyEsqlRequest(actionRequest)
4950

5051
override protected def requestedIndicesFrom(request: ActionRequest with CompositeIndicesRequest): Set[RequestedIndex[ClusterIndexName]] = {
5152
requestClassification match {
@@ -74,7 +75,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp
7475
case Right(r@EsqlRequestClassification.IndicesRelated(tables)) =>
7576
val filteredIndicesStrings = filteredIndices.stringify.toCovariantSet
7677
if (filteredIndicesStrings != r.indices) {
77-
EsqlRequestHelper.modifyIndicesOf(request, tables, filteredIndicesStrings)
78+
esqlRequestHelper.modifyIndicesOf(request, tables, filteredIndicesStrings)
7879
} else {
7980
request
8081
}
@@ -103,7 +104,7 @@ class EsqlIndicesEsRequestContext private(actionRequest: ActionRequest with Comp
103104
private def applyFieldLevelSecurityTo(response: ActionResponse,
104105
fieldLevelSecurity: Option[FieldLevelSecurity]) = {
105106
fieldLevelSecurity match {
106-
case Some(fls) => EsqlRequestHelper.modifyResponseAccordingToFieldLevelSecurity(response, fls)
107+
case Some(fls) => esqlRequestHelper.modifyResponseAccordingToFieldLevelSecurity(response, fls)
107108
case None => response
108109
}
109110
}
@@ -126,7 +127,8 @@ object EsqlIndicesEsRequestContext {
126127
arg.esContext,
127128
arg.aclContext,
128129
arg.clusterService,
129-
arg.threadPool
130+
arg.threadPool,
131+
new EsqlRequestHelper(arg.esContext.esVersion)
130132
))
131133
} else {
132134
None

es92x/src/main/scala/tech/beshu/ror/es/utils/EsqlRequestHelper.scala

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ import org.joor.Reflect.*
2323
import org.joor.ReflectException
2424
import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity
2525
import tech.beshu.ror.accesscontrol.domain.FieldLevelSecurity.FieldsRestrictions
26+
import tech.beshu.ror.es.EsVersion
2627
import tech.beshu.ror.es.handler.response.FieldsFiltering
2728
import tech.beshu.ror.es.handler.response.FieldsFiltering.NonMetadataDocumentFields
29+
import tech.beshu.ror.es.utils.EsqlRequestHelper.{ClassificationError, EsqlRequestClassification, IndexTable}
2830
import tech.beshu.ror.syntax.*
2931
import tech.beshu.ror.utils.ScalaOps.*
3032

@@ -33,7 +35,7 @@ import java.util.List as JList
3335
import scala.jdk.CollectionConverters.*
3436
import scala.util.{Failure, Success, Try}
3537

36-
object EsqlRequestHelper {
38+
class EsqlRequestHelper(esVersion: EsVersion) {
3739

3840
def modifyIndicesOf(request: CompositeIndicesRequest,
3941
requestTables: NonEmptyList[IndexTable],
@@ -117,15 +119,36 @@ object EsqlRequestHelper {
117119
}
118120

119121
private def indicesFrom(statement: Any) = {
120-
val preAnalyze = doPreAnalyze(newPreAnalyzer, statement)
121-
val indexPattern = indexPatternFrom(preAnalyze)
122+
val plan = esVersion match {
123+
case v if v >= EsVersion(9, 3, 0) => on(statement).call("plan").get[Any]()
124+
case _ => statement
125+
}
126+
val preAnalysis = doPreAnalyze(newPreAnalyzer, plan)
127+
esVersion match {
128+
case v if v >= EsVersion(9, 3, 0) => indicesFromPreAnalysisForEsEqualOrAbove930(preAnalysis)
129+
case _ => indicesFromPreAnalysisForEsBelow930(preAnalysis)
130+
}
131+
}
132+
133+
private def indicesFromPreAnalysisForEsBelow930(preAnalysis: Any) = {
134+
val indexPattern = indexPatternFrom(preAnalysis)
122135
val indexPatternString = indexPatternStringFrom(indexPattern)
123136
NonEmptyList
124137
.fromList(splitIntoIndices(indexPatternString))
125138
.map(IndexTable(indexPatternString, _))
126139
.toList
127140
}
128141

142+
private def indicesFromPreAnalysisForEsEqualOrAbove930(preAnalysis: Any) = {
143+
val indexesMap = on(preAnalysis).get[java.util.Map[Any, Any]]("indexes")
144+
indexesMap.keySet().asScala.toList.flatMap { indexPattern =>
145+
val indexPatternString = on(indexPattern).call("indexPattern").get[String]()
146+
NonEmptyList
147+
.fromList(splitIntoIndices(indexPatternString))
148+
.map(IndexTable(indexPatternString, _))
149+
}
150+
}
151+
129152
private def splitIntoIndices(tableString: String) = {
130153
tableString.split(',').asSafeList.filter(_.nonEmpty)
131154
}
@@ -243,6 +266,9 @@ object EsqlRequestHelper {
243266
}
244267
}
245268
}
269+
}
270+
271+
object EsqlRequestHelper {
246272

247273
final case class IndexTable(tableStringInQuery: String, indices: NonEmptyList[String])
248274

@@ -258,4 +284,4 @@ object EsqlRequestHelper {
258284
object ClassificationError {
259285
final case class ParsingException(cause: Throwable) extends ClassificationError
260286
}
261-
}
287+
}

es92x/src/main/scala/tech/beshu/ror/es/utils/XPackSecurityAuthenticationHeader.scala

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package tech.beshu.ror.es.utils
1818

1919
import eu.timepit.refined.types.string.NonEmptyString
20-
import org.elasticsearch.{TransportVersion, TransportVersions}
20+
import org.elasticsearch.TransportVersion
2121
import org.elasticsearch.common.bytes.BytesReference
2222
import org.elasticsearch.common.io.stream.BytesStreamOutput
2323
import tech.beshu.ror.accesscontrol.domain.Header
@@ -58,18 +58,10 @@ object XPackSecurityAuthenticationHeader {
5858
output.writeString(nodeName)
5959
output.writeString("__attach")
6060
output.writeString("__attach")
61-
if(output.getTransportVersion.onOrAfter(TransportVersions.V_8_2_0)) {
62-
output.writeBoolean(false)
63-
}
6461
output.writeBoolean(false)
65-
if (output.getTransportVersion.onOrAfter(TransportVersions.V_7_0_0)) {
66-
output.writeVInt(4) // Internal
67-
if(output.getTransportVersion.onOrAfter(TransportVersions.V_8_8_0)) {
68-
output.writeVInt(0)
69-
} else {
70-
output.writeGenericMap(Map.empty[String, Object].asJava)
71-
}
72-
}
62+
output.writeBoolean(false)
63+
output.writeVInt(4) // Internal
64+
output.writeVInt(0)
7365
NonEmptyString.unsafeFrom {
7466
Base64.getEncoder.encodeToString(BytesReference.toBytes(output.bytes()))
7567
}

0 commit comments

Comments
 (0)