Skip to content

Commit

Permalink
Update detekt version (#1226)
Browse files Browse the repository at this point in the history
Signed-off-by: Rupal Mahajan <[email protected]>
  • Loading branch information
rupal-bq authored Nov 4, 2022
1 parent 37fcd04 commit 03b62c2
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 42 deletions.
3 changes: 2 additions & 1 deletion opensearch-observability/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ buildscript {
classpath "org.opensearch.gradle:build-tools:${opensearch_version}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}"
classpath "org.jetbrains.kotlin:kotlin-allopen:${kotlin_version}"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.12.0"
classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.21.0"
classpath "org.jacoco:org.jacoco.agent:0.8.5"
}
}
Expand Down Expand Up @@ -141,6 +141,7 @@ configurations.all {
force "org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin_version}"
force "com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:2.13.4"
force "org.mockito:mockito-core:4.6.1"
force "org.yaml:snakeyaml:1.32"
}
}

Expand Down
5 changes: 5 additions & 0 deletions opensearch-observability/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ style:
ReturnCount:
active: true
max: 10
complexity:
LongMethod:
threshold: 120
NestedBlockDepth:
threshold: 5
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ internal object ObservabilityIndex {
private const val NOTEBOOKS_INDEX_NAME = ".opensearch-notebooks"
private const val OBSERVABILITY_MAPPING_FILE_NAME = "observability-mapping.yml"
private const val OBSERVABILITY_SETTINGS_FILE_NAME = "observability-settings.yml"
private const val MAPPING_TYPE = "_doc"

private var mappingsUpdated: Boolean = false
private lateinit var client: Client
Expand Down Expand Up @@ -102,10 +101,12 @@ internal object ObservabilityIndex {
log.info("$LOG_PREFIX:Index $INDEX_NAME creation Acknowledged")
reindexNotebooks()
} else {
throw IllegalStateException("$LOG_PREFIX:Index $INDEX_NAME creation not Acknowledged")
error("$LOG_PREFIX:Index $INDEX_NAME creation not Acknowledged")
}
} catch (exception: ResourceAlreadyExistsException) {
log.warn("message: ${exception.message}")
} catch (exception: Exception) {
if (exception !is ResourceAlreadyExistsException && exception.cause !is ResourceAlreadyExistsException) {
if (exception.cause !is ResourceAlreadyExistsException) {
throw exception
}
}
Expand All @@ -129,7 +130,7 @@ internal object ObservabilityIndex {
if (response.isAcknowledged) {
log.info("$LOG_PREFIX:Index $INDEX_NAME update mapping Acknowledged")
} else {
throw IllegalStateException("$LOG_PREFIX:Index $INDEX_NAME update mapping not Acknowledged")
error("$LOG_PREFIX:Index $INDEX_NAME update mapping not Acknowledged")
}
this.mappingsUpdated = true
} catch (exception: IndexNotFoundException) {
Expand All @@ -152,11 +153,11 @@ internal object ObservabilityIndex {
.refresh(true)
.get()
if (reindexResponse.isTimedOut) {
throw IllegalStateException("$LOG_PREFIX:Index - reindex $NOTEBOOKS_INDEX_NAME timed out")
error("$LOG_PREFIX:Index - reindex $NOTEBOOKS_INDEX_NAME timed out")
} else if (reindexResponse.searchFailures.isNotEmpty()) {
throw IllegalStateException("$LOG_PREFIX:Index - reindex $NOTEBOOKS_INDEX_NAME failed with searchFailures")
error("$LOG_PREFIX:Index - reindex $NOTEBOOKS_INDEX_NAME failed with searchFailures")
} else if (reindexResponse.bulkFailures.isNotEmpty()) {
throw IllegalStateException("$LOG_PREFIX:Index - reindex $NOTEBOOKS_INDEX_NAME failed with bulkFailures")
error("$LOG_PREFIX:Index - reindex $NOTEBOOKS_INDEX_NAME failed with bulkFailures")
} else if (reindexResponse.total != reindexResponse.created + reindexResponse.updated) {
throw IllegalStateException(
"$LOG_PREFIX:Index - reindex number of docs created:${reindexResponse.created} + " +
Expand All @@ -167,8 +168,10 @@ internal object ObservabilityIndex {
"$LOG_PREFIX:Index - reindex ${reindexResponse.created} docs created " +
"and ${reindexResponse.updated} docs updated in $INDEX_NAME"
)
} catch (exception: ResourceNotFoundException) {
log.warn("message: ${exception.message}")
} catch (exception: Exception) {
if (exception !is ResourceNotFoundException && exception.cause !is ResourceNotFoundException) {
if (exception.cause !is ResourceNotFoundException) {
throw exception
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ internal class ObservabilityQueryHelper(private val types: EnumSet<Observability
}
}

private fun addTermQueryBuilder(query: BoolQueryBuilder, queryKey: String, queryValue: String) {
prefixes.forEach { query.filter(QueryBuilders.termQuery("${it.tag}.$queryKey", queryValue)) }
}

private fun addTermsQueryBuilder(query: BoolQueryBuilder, queryKey: String, queryValue: String) {
prefixes.forEach { query.filter(QueryBuilders.termsQuery("${it.tag}.$queryKey", queryValue.split(","))) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal object SecurityAccess {
SpecialPermission.check()
return try {
AccessController.doPrivileged(operation)
} catch (e: PrivilegedActionException) {
} catch (@Suppress("SwallowedException") e: PrivilegedActionException) {
throw (e.cause as Exception?)!!
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ internal object PluginSettings {
try {
settings = Settings.builder().loadFromPath(defaultSettingYmlFile).build()
} catch (exception: IOException) {
log.warn("$LOG_PREFIX:Failed to load ${defaultSettingYmlFile.toAbsolutePath()}")
log.warn("$LOG_PREFIX:Failed to load ${defaultSettingYmlFile.toAbsolutePath()} message:${exception.message}")
}
}
// Initialize the settings values to default values
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fun constructNotebookRequest(name: String = "test notebook"): String {
}
""".trimIndent()
}

@Suppress("MaxLineLength")
fun constructSavedQueryRequest(name: String = "test saved query"): String {
return """
{
Expand Down Expand Up @@ -101,7 +101,7 @@ fun constructSavedQueryRequest(name: String = "test saved query"): String {
}
""".trimIndent()
}

@Suppress("MaxLineLength")
fun constructSavedVisualizationRequest(name: String = "test saved visualization"): String {
return """
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ internal class CreateObservabilityObjectRequestTests {
@Test
fun `Create object should deserialize json object using parser`() {
val jsonString =
"{\"timestamp\":{\"name\":\"test-timestamp\",\"index\":\"opensearch_dashboards_sample_data_logs\",\"type\":\"timestamp\",\"dsl_type\":\"date\"}}"
"{\"timestamp\":{\"name\":\"test-timestamp\",\"index\":\"opensearch_dashboards_sample_data_logs\"," +
"\"type\":\"timestamp\",\"dsl_type\":\"date\"}}"
val recreatedObject = createObjectFromJsonString(jsonString) { CreateObservabilityObjectRequest.parse(it) }
assertEquals(sampleTimestamp, recreatedObject.objectData)
}
Expand All @@ -59,7 +60,8 @@ internal class CreateObservabilityObjectRequestTests {
@Test
fun `Create object should safely ignore extra field in json object`() {
val jsonString =
"{\"timestamp\":{\"name\":\"test-timestamp\",\"index\":\"opensearch_dashboards_sample_data_logs\",\"type\":\"timestamp\",\"dsl_type\":\"date\",\"another\":\"field\"}}"
"{\"timestamp\":{\"name\":\"test-timestamp\",\"index\":\"opensearch_dashboards_sample_data_logs\"," +
"\"type\":\"timestamp\",\"dsl_type\":\"date\",\"another\":\"field\"}}"
val recreatedObject = createObjectFromJsonString(jsonString) { CreateObservabilityObjectRequest.parse(it) }
assertEquals(sampleTimestamp, recreatedObject.objectData)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ internal class NotebookTests {
@Test
fun `Notebook should deserialize json object using parser`() {
val jsonString =
"{\"name\":\"test-notebook\",\"dateCreated\":\"2021-12-01T18:33:40.017Z\",\"dateModified\":\"2021-12-01T18:33:40.017Z\",\"backend\":\"Default\",\"paragraphs\":[{\"output\":[{\"result\":\"sample paragraph\",\"outputType\":\"MARKDOWN\",\"execution_time\":\"0 ms\"}],\"input\":{\"inputText\":\"%md sample paragraph\",\"inputType\":\"MARKDOWN\"},\"dateCreated\":\"2021-12-01T18:33:40.017Z\",\"dateModified\":\"2021-12-01T18:33:40.017Z\",\"id\":\"paragraph_bcd3c65c-91db-489d-b667-496fd378714e\"}]}"
"{\"name\":\"test-notebook\",\"dateCreated\":\"2021-12-01T18:33:40.017Z\",\"dateModified\":\"2021-12-01T18:33:40.017Z\"," +
"\"backend\":\"Default\",\"paragraphs\":[{\"output\":[{\"result\":\"sample paragraph\",\"outputType\":\"MARKDOWN\"," +
"\"execution_time\":\"0 ms\"}],\"input\":{\"inputText\":\"%md sample paragraph\",\"inputType\":\"MARKDOWN\"}," +
"\"dateCreated\":\"2021-12-01T18:33:40.017Z\",\"dateModified\":\"2021-12-01T18:33:40.017Z\"," +
"\"id\":\"paragraph_bcd3c65c-91db-489d-b667-496fd378714e\"}]}"
val recreatedObject = createObjectFromJsonString(jsonString) { Notebook.parse(it) }
assertEquals(sampleNotebook, recreatedObject)
}
Expand All @@ -62,7 +66,11 @@ internal class NotebookTests {
@Test
fun `Notebook should safely ignore extra field in json object`() {
val jsonString =
"{\"name\":\"test-notebook\",\"dateCreated\":\"2021-12-01T18:33:40.017Z\",\"dateModified\":\"2021-12-01T18:33:40.017Z\",\"backend\":\"Default\",\"paragraphs\":[{\"output\":[{\"result\":\"sample paragraph\",\"outputType\":\"MARKDOWN\",\"execution_time\":\"0 ms\"}],\"input\":{\"inputText\":\"%md sample paragraph\",\"inputType\":\"MARKDOWN\"},\"dateCreated\":\"2021-12-01T18:33:40.017Z\",\"dateModified\":\"2021-12-01T18:33:40.017Z\",\"id\":\"paragraph_bcd3c65c-91db-489d-b667-496fd378714e\"}],\"another\":\"field\"}"
"{\"name\":\"test-notebook\",\"dateCreated\":\"2021-12-01T18:33:40.017Z\",\"dateModified\":\"2021-12-01T18:33:40.017Z\"," +
"\"backend\":\"Default\",\"paragraphs\":[{\"output\":[{\"result\":\"sample paragraph\",\"outputType\":\"MARKDOWN\"," +
"\"execution_time\":\"0 ms\"}],\"input\":{\"inputText\":\"%md sample paragraph\",\"inputType\":\"MARKDOWN\"}," +
"\"dateCreated\":\"2021-12-01T18:33:40.017Z\",\"dateModified\":\"2021-12-01T18:33:40.017Z\"," +
"\"id\":\"paragraph_bcd3c65c-91db-489d-b667-496fd378714e\"}],\"another\":\"field\"}"
val recreatedObject = createObjectFromJsonString(jsonString) { Notebook.parse(it) }
assertEquals(sampleNotebook, recreatedObject)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ internal class ObservabilityObjectDocTests {
@Test
fun `ObservabilityObjectDoc should deserialize json object using parser`() {
val jsonString =
"{\"objectId\":\"test-id\",\"lastUpdatedTimeMs\":1638482208790,\"createdTimeMs\":1638482208790,\"tenant\":\"test-tenant\",\"access\":[\"test-access\"],\"timestamp\":{\"name\":\"test object\",\"index\":\"opensearch_dashboards_sample_data_logs\",\"type\":\"timestamp\",\"dsl_type\":\"date\"}}"
"{\"objectId\":\"test-id\",\"lastUpdatedTimeMs\":1638482208790,\"createdTimeMs\":1638482208790,\"tenant\":" +
"\"test-tenant\",\"access\":[\"test-access\"],\"timestamp\":{\"name\":\"test object\"," +
"\"index\":\"opensearch_dashboards_sample_data_logs\",\"type\":\"timestamp\",\"dsl_type\":\"date\"}}"
val recreatedObject = createObjectFromJsonString(jsonString) { ObservabilityObjectDoc.parse(it) }
assertEquals(sampleObservabilityObjectDoc, recreatedObject)
}
Expand All @@ -49,7 +51,9 @@ internal class ObservabilityObjectDocTests {
@Test
fun `ObservabilityObjectDoc should safely ignore extra field in json object`() {
val jsonString =
"{\"objectId\":\"test-id\",\"lastUpdatedTimeMs\":1638482208790,\"createdTimeMs\":1638482208790,\"tenant\":\"test-tenant\",\"access\":[\"test-access\"],\"timestamp\":{\"name\":\"test object\",\"index\":\"opensearch_dashboards_sample_data_logs\",\"type\":\"timestamp\",\"dsl_type\":\"date\"},\"another\":\"field\"}"
"{\"objectId\":\"test-id\",\"lastUpdatedTimeMs\":1638482208790,\"createdTimeMs\":1638482208790,\"tenant\":" +
"\"test-tenant\",\"access\":[\"test-access\"],\"timestamp\":{\"name\":\"test object\",\"index\":" +
"\"opensearch_dashboards_sample_data_logs\",\"type\":\"timestamp\",\"dsl_type\":\"date\"},\"another\":\"field\"}"
val recreatedObject = createObjectFromJsonString(jsonString) { ObservabilityObjectDoc.parse(it) }
assertEquals(sampleObservabilityObjectDoc, recreatedObject)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ internal class OperationalPanelTests {
@Test
fun `OperationalPanel should deserialize json object using parser`() {
val jsonString =
"{\"name\":\"test-operational-panel\",\"visualizations\":[{\"id\":\"panelViz_7ba28e34-6fd8-489d-9b9f-1f83e006fb17\",\"savedVisualizationId\":\"oyuecXwBYVazWqOOde0o\",\"x\":0,\"y\":0,\"w\":10,\"h\":10}],\"timeRange\":{\"to\":\"now\",\"from\":\"now-1d\"},\"queryFilter\":{\"query\":\"| where Carrier='OpenSearch-Air'\",\"language\":\"ppl\"}}"
"{\"name\":\"test-operational-panel\",\"visualizations\":[{\"id\":\"panelViz_7ba28e34-6fd8-489d-9b9f-1f83e006fb17\"," +
"\"savedVisualizationId\":\"oyuecXwBYVazWqOOde0o\",\"x\":0,\"y\":0,\"w\":10,\"h\":10}],\"timeRange\":{\"to\":" +
"\"now\",\"from\":\"now-1d\"},\"queryFilter\":{\"query\":\"| where Carrier='OpenSearch-Air'\",\"language\":\"ppl\"}}"
val recreatedObject = createObjectFromJsonString(jsonString) { OperationalPanel.parse(it) }
assertEquals(sampleOperationalPanel, recreatedObject)
}
Expand All @@ -62,7 +64,9 @@ internal class OperationalPanelTests {
@Test
fun `OperationalPanel should safely ignore extra field in json object`() {
val jsonString =
"{\"name\":\"test-operational-panel\",\"visualizations\":[{\"id\":\"panelViz_7ba28e34-6fd8-489d-9b9f-1f83e006fb17\",\"savedVisualizationId\":\"oyuecXwBYVazWqOOde0o\",\"x\":0,\"y\":0,\"w\":10,\"h\":10}],\"timeRange\":{\"to\":\"now\",\"from\":\"now-1d\"},\"queryFilter\":{\"query\":\"| where Carrier='OpenSearch-Air'\",\"language\":\"ppl\"},\"another\":\"field\"}"
"{\"name\":\"test-operational-panel\",\"visualizations\":[{\"id\":\"panelViz_7ba28e34-6fd8-489d-9b9f-1f83e006fb17\",\"" +
"savedVisualizationId\":\"oyuecXwBYVazWqOOde0o\",\"x\":0,\"y\":0,\"w\":10,\"h\":10}],\"timeRange\":{\"to\":\"now\"," +
"\"from\":\"now-1d\"},\"queryFilter\":{\"query\":\"| where Carrier='OpenSearch-Air'\",\"language\":\"ppl\"},\"another\":\"field\"}"
val recreatedObject = createObjectFromJsonString(jsonString) { OperationalPanel.parse(it) }
assertEquals(sampleOperationalPanel, recreatedObject)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ internal class SavedQueryTests {
@Test
fun `SavedQuery should deserialize json object using parser`() {
val jsonString =
"{\"name\":\"test-saved-query\",\"description\":\"test description\",\"query\":\"source=index | where utc_time > timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\",\"selected_date_range\":{\"start\":\"now/15m\",\"end\":\"now\",\"text\":\"utc_time > timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\"},\"selected_timestamp\":{\"name\":\"utc_time\",\"type\":\"timestamp\"},\"selected_fields\":{\"text\":\"| fields clientip, bytes, memory, host\",\"tokens\":[{\"name\":\"utc_time\",\"type\":\"timestamp\"}]}}"
"{\"name\":\"test-saved-query\",\"description\":\"test description\",\"query\":\"source=index | " +
"where utc_time > timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\"," +
"\"selected_date_range\":{\"start\":\"now/15m\",\"end\":\"now\",\"text\":\"utc_time > " +
"timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\"}," +
"\"selected_timestamp\":{\"name\":\"utc_time\",\"type\":\"timestamp\"},\"selected_fields\":{\"text\":" +
"\"| fields clientip, bytes, memory, host\",\"tokens\":[{\"name\":\"utc_time\",\"type\":\"timestamp\"}]}}"
val recreatedObject = createObjectFromJsonString(jsonString) { SavedQuery.parse(it) }
assertEquals(sampleSavedQuery, recreatedObject)
}
Expand All @@ -62,7 +67,12 @@ internal class SavedQueryTests {
@Test
fun `SavedQuery should safely ignore extra field in json object`() {
val jsonString =
"{\"name\":\"test-saved-query\",\"description\":\"test description\",\"query\":\"source=index | where utc_time > timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\",\"selected_date_range\":{\"start\":\"now/15m\",\"end\":\"now\",\"text\":\"utc_time > timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\"},\"selected_timestamp\":{\"name\":\"utc_time\",\"type\":\"timestamp\"},\"selected_fields\":{\"text\":\"| fields clientip, bytes, memory, host\",\"tokens\":[{\"name\":\"utc_time\",\"type\":\"timestamp\"}]},\"another\":\"field\"}"
"{\"name\":\"test-saved-query\",\"description\":\"test description\",\"query\":\"source=index | where" +
" utc_time > timestamp('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\"," +
"\"selected_date_range\":{\"start\":\"now/15m\",\"end\":\"now\",\"text\":\"utc_time > timestamp" +
"('2021-07-01 00:00:00') and utc_time < timestamp('2021-07-02 00:00:00')\"},\"selected_timestamp\"" +
":{\"name\":\"utc_time\",\"type\":\"timestamp\"},\"selected_fields\":{\"text\":\"| fields clientip, " +
"bytes, memory, host\",\"tokens\":[{\"name\":\"utc_time\",\"type\":\"timestamp\"}]},\"another\":\"field\"}"
val recreatedObject = createObjectFromJsonString(jsonString) { SavedQuery.parse(it) }
assertEquals(sampleSavedQuery, recreatedObject)
}
Expand Down
Loading

0 comments on commit 03b62c2

Please sign in to comment.