Skip to content

Commit

Permalink
Upgrade Alerting to 2.0 (#357)
Browse files Browse the repository at this point in the history
Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>
  • Loading branch information
lezzago committed Mar 22, 2022
1 parent 120f7c4 commit 0c5090f
Show file tree
Hide file tree
Showing 21 changed files with 206 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/multi-node-test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
- name: Checkout Branch
uses: actions/checkout@v2
- name: Run integration tests with multi node config
run: ./gradlew integTest -PnumNodes=3 -Dopensearch.version=1.3.0-SNAPSHOT
run: ./gradlew integTest -PnumNodes=3 -Dopensearch.version=2.0.0-SNAPSHOT
2 changes: 1 addition & 1 deletion .github/workflows/security-test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
java-version: 11
- name: Build Alerting
# Only assembling since the full build is governed by other workflows
run: ./gradlew assemble -Dopensearch.version=1.3.0-SNAPSHOT
run: ./gradlew assemble -Dopensearch.version=2.0.0-SNAPSHOT
- name: Pull and Run Docker
run: |
plugin=`ls alerting/build/distributions/*.zip`
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
build:
strategy:
matrix:
java: [8, 11, 14]
java: [11, 14]
# Job name
name: Build Alerting with JDK ${{ matrix.java }}
# This job runs on Linux
Expand All @@ -27,7 +27,7 @@ jobs:
with:
java-version: ${{ matrix.java }}
- name: Build and run with Gradle
run: ./gradlew build -Dopensearch.version=1.3.0-SNAPSHOT
run: ./gradlew build -Dopensearch.version=2.0.0-SNAPSHOT
- name: Create Artifact Path
run: |
mkdir -p alerting-artifacts
Expand Down
16 changes: 8 additions & 8 deletions alerting/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ configurations.all {
}
}

configurations.testCompile {
configurations.testImplementation {
exclude module: "securemock"
}

dependencies {
compileOnly "org.opensearch.plugin:opensearch-scripting-painless-spi:${versions.opensearch}"

// OpenSearch Nanny state
compile "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"
compile "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}"
compile "org.jetbrains:annotations:13.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"
implementation "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}"
implementation "org.jetbrains:annotations:13.0"

compile project(":alerting-core")
compile project(":alerting-notification")
api project(":alerting-core")
api project(":alerting-notification")
implementation "com.github.seancfoley:ipaddress:5.3.3"

testImplementation "org.jetbrains.kotlin:kotlin-test:${kotlin_version}"
testCompile "org.mockito:mockito-core:3.12.4"
testImplementation "org.mockito:mockito-core:4.3.1"
}

javadoc.enabled = false // turn off javadoc as it barfs on Kotlin code
Expand Down Expand Up @@ -161,7 +161,7 @@ String bwcFilePath = "src/test/resources/bwc"
testClusters {
"${baseName}$i" {
testDistribution = "ARCHIVE"
versions = ["7.10.2","1.3.0-SNAPSHOT"]
versions = ["7.10.2","2.0.0-SNAPSHOT"]
numberOfNodes = 3
plugin(provider(new Callable<RegularFile>(){
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class AlertIndices(
return
}

var putMappingRequest: PutMappingRequest = PutMappingRequest(targetIndex).type(MAPPING_TYPE)
var putMappingRequest: PutMappingRequest = PutMappingRequest(targetIndex)
.source(mapping, XContentType.JSON)
val updateResponse: AcknowledgedResponse = client.admin().indices().suspendUntil { putMapping(putMappingRequest, it) }
if (updateResponse.isAcknowledged) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class TransportIndexDestinationAction @Inject constructor(
})
} else if (!IndexUtils.scheduledJobIndexUpdated) {
IndexUtils.updateIndexMapping(
ScheduledJob.SCHEDULED_JOBS_INDEX, ScheduledJob.SCHEDULED_JOB_TYPE,
ScheduledJob.SCHEDULED_JOBS_INDEX,
ScheduledJobIndices.scheduledJobMappings(), clusterService.state(), client.admin().indices(),
object : ActionListener<AcknowledgedResponse> {
override fun onResponse(response: AcknowledgedResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.opensearch.alerting.action.IndexEmailAccountRequest
import org.opensearch.alerting.action.IndexEmailAccountResponse
import org.opensearch.alerting.core.ScheduledJobIndices
import org.opensearch.alerting.core.model.ScheduledJob.Companion.SCHEDULED_JOBS_INDEX
import org.opensearch.alerting.core.model.ScheduledJob.Companion.SCHEDULED_JOB_TYPE
import org.opensearch.alerting.model.destination.email.EmailAccount
import org.opensearch.alerting.settings.AlertingSettings.Companion.INDEX_TIMEOUT
import org.opensearch.alerting.settings.AlertingSettings.Companion.REQUEST_TIMEOUT
Expand Down Expand Up @@ -94,7 +93,7 @@ class TransportIndexEmailAccountAction @Inject constructor(
})
} else if (!IndexUtils.scheduledJobIndexUpdated) {
IndexUtils.updateIndexMapping(
SCHEDULED_JOBS_INDEX, SCHEDULED_JOB_TYPE,
SCHEDULED_JOBS_INDEX,
ScheduledJobIndices.scheduledJobMappings(), clusterService.state(), client.admin().indices(),
object : ActionListener<AcknowledgedResponse> {
override fun onResponse(response: AcknowledgedResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.opensearch.alerting.action.IndexEmailGroupRequest
import org.opensearch.alerting.action.IndexEmailGroupResponse
import org.opensearch.alerting.core.ScheduledJobIndices
import org.opensearch.alerting.core.model.ScheduledJob.Companion.SCHEDULED_JOBS_INDEX
import org.opensearch.alerting.core.model.ScheduledJob.Companion.SCHEDULED_JOB_TYPE
import org.opensearch.alerting.settings.AlertingSettings.Companion.INDEX_TIMEOUT
import org.opensearch.alerting.settings.DestinationSettings.Companion.ALLOW_LIST
import org.opensearch.alerting.util.AlertingException
Expand Down Expand Up @@ -86,7 +85,7 @@ class TransportIndexEmailGroupAction @Inject constructor(
})
} else if (!IndexUtils.scheduledJobIndexUpdated) {
IndexUtils.updateIndexMapping(
SCHEDULED_JOBS_INDEX, SCHEDULED_JOB_TYPE,
SCHEDULED_JOBS_INDEX,
ScheduledJobIndices.scheduledJobMappings(), clusterService.state(), client.admin().indices(),
object : ActionListener<AcknowledgedResponse> {
override fun onResponse(response: AcknowledgedResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import org.opensearch.alerting.action.IndexMonitorResponse
import org.opensearch.alerting.core.ScheduledJobIndices
import org.opensearch.alerting.core.model.ScheduledJob
import org.opensearch.alerting.core.model.ScheduledJob.Companion.SCHEDULED_JOBS_INDEX
import org.opensearch.alerting.core.model.ScheduledJob.Companion.SCHEDULED_JOB_TYPE
import org.opensearch.alerting.core.model.SearchInput
import org.opensearch.alerting.model.Monitor
import org.opensearch.alerting.settings.AlertingSettings
Expand Down Expand Up @@ -243,7 +242,7 @@ class TransportIndexMonitorAction @Inject constructor(
})
} else if (!IndexUtils.scheduledJobIndexUpdated) {
IndexUtils.updateIndexMapping(
SCHEDULED_JOBS_INDEX, SCHEDULED_JOB_TYPE,
SCHEDULED_JOBS_INDEX,
ScheduledJobIndices.scheduledJobMappings(), clusterService.state(), client.admin().indices(),
object : ActionListener<AcknowledgedResponse> {
override fun onResponse(response: AcknowledgedResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,14 @@ class IndexUtils {
@JvmStatic
fun updateIndexMapping(
index: String,
type: String,
mapping: String,
clusterState: ClusterState,
client: IndicesAdminClient,
actionListener: ActionListener<AcknowledgedResponse>
) {
if (clusterState.metadata.indices.containsKey(index)) {
if (shouldUpdateIndex(clusterState.metadata.indices[index], mapping)) {
val putMappingRequest: PutMappingRequest = PutMappingRequest(index).type(type).source(mapping, XContentType.JSON)
val putMappingRequest: PutMappingRequest = PutMappingRequest(index).source(mapping, XContentType.JSON)
client.putMapping(putMappingRequest, actionListener)
} else {
actionListener.onResponse(AcknowledgedResponse(true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ abstract class AlertingRestTestCase : ODFERestTestCase() {
SearchInput.XCONTENT_REGISTRY,
QueryLevelTrigger.XCONTENT_REGISTRY,
BucketLevelTrigger.XCONTENT_REGISTRY
) + SearchModule(Settings.EMPTY, false, emptyList()).namedXContents
) + SearchModule(Settings.EMPTY, emptyList()).namedXContents
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ fun xContentRegistry(): NamedXContentRegistry {
return NamedXContentRegistry(
listOf(
SearchInput.XCONTENT_REGISTRY, QueryLevelTrigger.XCONTENT_REGISTRY, BucketLevelTrigger.XCONTENT_REGISTRY
) + SearchModule(Settings.EMPTY, false, emptyList()).namedXContents
) + SearchModule(Settings.EMPTY, emptyList()).namedXContents
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,12 @@ class IndexUtilsTests : OpenSearchTestCase() {
fun `test should update index with same version`() {
val indexContent = "{\"testIndex\":{\"settings\":{\"index\":{\"creation_date\":\"1558407515699\"," +
"\"number_of_shards\":\"1\",\"number_of_replicas\":\"1\",\"uuid\":\"t-VBBW6aR6KpJ3XP5iISOA\"," +
"\"version\":{\"created\":\"6040399\"},\"provided_name\":\"data_test\"}},\"mappings\":" +
"\"version\":{\"created\":\"6040399\"},\"provided_name\":\"data_test\"}},\"mapping_version\":\"1\"," +
"\"settings_version\":\"1\",\"aliases_version\":\"1\",\"mappings\":" +
"{\"_doc\":{\"_meta\":{\"schema_version\":1},\"properties\":{\"name\":{\"type\":\"keyword\"}}}}}}"
val newMapping = "{\"_meta\":{\"schema_version\":1},\"properties\":{\"name\":{\"type\":\"keyword\"}}}"
val index: IndexMetadata = IndexMetadata.fromXContent(parser(indexContent))
val xContentParser = parser(indexContent)
val index: IndexMetadata = IndexMetadata.fromXContent(xContentParser)

val shouldUpdateIndex = IndexUtils.shouldUpdateIndex(index, newMapping)
assertFalse(shouldUpdateIndex)
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
apply from: 'build-tools/repositories.gradle'

ext {
opensearch_version = System.getProperty("opensearch.version", "1.3.0-SNAPSHOT")
opensearch_version = System.getProperty("opensearch.version", "2.0.0-SNAPSHOT")
// 1.0.0 -> 1.0.0.0, and 1.0.0-SNAPSHOT -> 1.0.0.0-SNAPSHOT
opensearch_build = opensearch_version.replaceAll(/(\.\d)([^\d]*)$/, '$1.0$2')
common_utils_version = System.getProperty("common_utils.version", opensearch_build)
Expand Down Expand Up @@ -77,10 +77,10 @@ allprojects {
apply from: "$rootDir/build-tools/repositories.gradle"

plugins.withId('java') {
sourceCompatibility = targetCompatibility = "1.8"
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_11
}
plugins.withId('org.jetbrains.kotlin.jvm') {
compileKotlin.kotlinOptions.jvmTarget = compileTestKotlin.kotlinOptions.jvmTarget = "1.8"
compileKotlin.kotlinOptions.jvmTarget = compileTestKotlin.kotlinOptions.jvmTarget = JavaVersion.VERSION_11
compileKotlin.dependsOn ktlint
}
}
Expand Down
16 changes: 8 additions & 8 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ apply plugin: 'jacoco'

dependencies {
compileOnly "org.opensearch:opensearch:${opensearch_version}"
compile "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlin_version}"
compile "com.cronutils:cron-utils:9.1.6"
compile "org.opensearch.client:opensearch-rest-client:${opensearch_version}"
compile 'com.google.googlejavaformat:google-java-format:1.10.0'
compile "org.opensearch:common-utils:${common_utils_version}"
compile 'commons-validator:commons-validator:1.7'
implementation "org.jetbrains.kotlin:kotlin-stdlib:${kotlin_version}"
api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1'
api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlin_version}"
implementation "com.cronutils:cron-utils:9.1.6"
api "org.opensearch.client:opensearch-rest-client:${opensearch_version}"
implementation 'com.google.googlejavaformat:google-java-format:1.10.0'
api "org.opensearch:common-utils:${common_utils_version}"
implementation 'commons-validator:commons-validator:1.7'

testImplementation "org.opensearch.test:framework:${opensearch_version}"
testImplementation "org.jetbrains.kotlin:kotlin-test:${kotlin_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface XContentTestBase {
fun xContentRegistry(): NamedXContentRegistry {
return NamedXContentRegistry(
listOf(SearchInput.XCONTENT_REGISTRY) +
SearchModule(Settings.EMPTY, false, emptyList()).namedXContents
SearchModule(Settings.EMPTY, emptyList()).namedXContents
)
}
}
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 0c5090f

Please sign in to comment.