Skip to content
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

fix(SqlExecutionRepository): fixed bug in sql repository in orca-sql … #4697

Merged
merged 3 commits into from
Apr 15, 2024

Conversation

juangod-wise
Copy link
Contributor

This fixes two bugs in the selectExecutions method of the orca-sql/src/main/kotlin/com/netflix/spinnaker/orca/sql/pipeline/persistence/SqlExecutionRepository.kt file. These were probably never found because they are only used for some cleanup job: OldPipelineCleanupPollingNotificationAgent.

Comment on lines +1108 to +1112
if (where == null) {
it.where("1=1")
} else {
where(it)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the case in which the cursor is null (it always starts as null in the first iteration), the custom where statements that are passed to the function are not used on the query, effectively not filtering the first page.

Comment on lines +1115 to +1117
it.where(field("id").lt(cursor))
} else {
where(it).and(field("id").gt(cursor))
where(it).and(field("id").lt(cursor))
Copy link
Contributor Author

@juangod-wise juangod-wise Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pagination is broken, which makes it only show the first page, for example, in the unit tests on orca-sql/src/test/groovy/com/netflix/spinnaker/orca/sql/cleanup/OldPipelineCleanupPollingNotificationAgentSpec.groovy, we have a page size 10, and executions with id: 1, 2, 11, 12, ..., 20

Then, iteration 1 returns the first 10 elements in desc order:

--> 20, ..., 11 (10 elements)

And cursor = 11

Then the second page gets the elements greater than the cursor, which are

--> 20, ..., 12 (9 elements)

Then the stop condition in the PagedIterator is triggered:

isLastPage = currentPage.size < pageSize

Thus, the second page is never returned and only 10 elements are present, when there should be 12.

When we change greater than, for lesser than, we get:

Iteration 1:

--> 20, ..., 11 (10 elements)
Cursor = 11

Iteration 2, elements lesser than 11:

--> 1, 2

Then we get the correct response.

@dbyron-sf
Copy link
Contributor

Isn't SqlExecutionRepository.selectExecutions also called from TaskController.list via SqlExecutionRepository.retrieve ?

@dbyron-sf
Copy link
Contributor

dbyron-sf commented Apr 11, 2024

Thanks for this @juangod-wise! I tried reverting back to gt and happily see some test failures. With lt and reverting the first change that checks where for null, the tests still pass. Can you think of a test to add that fails without the where null check?

@dbyron-sf
Copy link
Contributor

I came up with one. OK if I push?

diff --git a/orca-sql/src/test/kotlin/com/netflix/spinnaker/orca/sql/pipeline/persistence/SqlExecutionRepositoryTest.kt b/orca-sql/src/test/kotlin/com/netflix/spinnaker/orca/sql/pipeline/persistence/SqlExecutionRepositoryTest.kt
index d0007e87d..e48209448 100644
--- a/orca-sql/src/test/kotlin/com/netflix/spinnaker/orca/sql/pipeline/persistence/SqlExecutionRepositoryTest.kt
+++ b/orca-sql/src/test/kotlin/com/netflix/spinnaker/orca/sql/pipeline/persistence/SqlExecutionRepositoryTest.kt
@@ -244,6 +244,21 @@ class SqlExecutionRepositoryTest : JUnit5Minutests {
         assertThat(actualPipelineExecution).isEqualTo(pipelineExecution)
       }
     }
+
+    context("retrievePipelinesForApplication") {
+      val pipelineExecution1 = PipelineExecutionImpl(ExecutionType.PIPELINE, "application-1")
+      val pipelineExecution2 = PipelineExecutionImpl(ExecutionType.PIPELINE, "application-2")
+
+      test("correctly use where clause") {
+        // Store pipelines in two different applications
+        sqlExecutionRepository.store(pipelineExecution1)
+        sqlExecutionRepository.store(pipelineExecution2)
+
+        val observable = sqlExecutionRepository.retrievePipelinesForApplication("application-2")
+        val executions = observable.toList().toBlocking().single()
+        assertThat(executions.map(PipelineExecution::getApplication).single()).isEqualTo("application-2")
+      }
+    }
   }
 
   private inner class Fixture {

@juangod-wise
Copy link
Contributor Author

I came up with one. OK if I push?

Good stuff! Please do!

@juangod-wise
Copy link
Contributor Author

Isn't SqlExecutionRepository.selectExecutions also called from TaskController.list via SqlExecutionRepository.retrieve ?

Yes it looks like it is also used in TaskController

which also verifies the behavior of selectExections when cursor is null
@dbyron-sf
Copy link
Contributor

I came up with one. OK if I push?

Good stuff! Please do!

42081af

@dbyron-sf dbyron-sf added the ready to merge Approved and ready for merge label Apr 15, 2024
@mergify mergify bot added the auto merged Merged automatically by a bot label Apr 15, 2024
@mergify mergify bot merged commit fc072b3 into spinnaker:master Apr 15, 2024
4 checks passed
@dbyron-sf
Copy link
Contributor

@Mergifyio backport release-1.32.x release-1.33.x

Copy link
Contributor

mergify bot commented Apr 15, 2024

backport release-1.32.x release-1.33.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Apr 15, 2024
#4697)

* fix(SqlExecutionRepository): fixed bug in sql repository in orca-sql module

* test(sql): demonstrate behavior of retrievePipelinesForApplication

which also verifies the behavior of selectExections when cursor is null

---------

Co-authored-by: David Byron <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit fc072b3)

# Conflicts:
#	orca-sql/src/test/kotlin/com/netflix/spinnaker/orca/sql/pipeline/persistence/SqlExecutionRepositoryTest.kt
mergify bot pushed a commit that referenced this pull request Apr 15, 2024
#4697)

* fix(SqlExecutionRepository): fixed bug in sql repository in orca-sql module

* test(sql): demonstrate behavior of retrievePipelinesForApplication

which also verifies the behavior of selectExections when cursor is null

---------

Co-authored-by: David Byron <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit fc072b3)

# Conflicts:
#	orca-sql/src/test/kotlin/com/netflix/spinnaker/orca/sql/pipeline/persistence/SqlExecutionRepositoryTest.kt
mergify bot added a commit that referenced this pull request Apr 15, 2024
…… (backport #4697) (#4701)

* fix(SqlExecutionRepository): fixed bug in sql repository in orca-sql … (#4697)

* fix(SqlExecutionRepository): fixed bug in sql repository in orca-sql module

* test(sql): demonstrate behavior of retrievePipelinesForApplication

which also verifies the behavior of selectExections when cursor is null

---------

Co-authored-by: David Byron <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit fc072b3)

# Conflicts:
#	orca-sql/src/test/kotlin/com/netflix/spinnaker/orca/sql/pipeline/persistence/SqlExecutionRepositoryTest.kt

* fix(sql/test): remove compression-related tests

since compression was added after cutting the release-1.32.x branch

---------

Co-authored-by: juangod-wise <[email protected]>
Co-authored-by: David Byron <[email protected]>
mergify bot added a commit that referenced this pull request Apr 15, 2024
…… (backport #4697) (#4702)

* fix(SqlExecutionRepository): fixed bug in sql repository in orca-sql … (#4697)

* fix(SqlExecutionRepository): fixed bug in sql repository in orca-sql module

* test(sql): demonstrate behavior of retrievePipelinesForApplication

which also verifies the behavior of selectExections when cursor is null

---------

Co-authored-by: David Byron <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
(cherry picked from commit fc072b3)

# Conflicts:
#	orca-sql/src/test/kotlin/com/netflix/spinnaker/orca/sql/pipeline/persistence/SqlExecutionRepositoryTest.kt

* fix(sql/test): remove compression-related tests

since compression was added after cutting the release-1.33.x branch

---------

Co-authored-by: juangod-wise <[email protected]>
Co-authored-by: David Byron <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto merged Merged automatically by a bot ready to merge Approved and ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants