Repository navigation
Add real production credential renwal integration test. - #1119
Conversation
5024288 to
e4b4df1
Compare
d34ac0a to
8bb0845
Compare
| * credential renewal mechanism works as expected, seamlessly refreshing credentials without | ||
| * interrupting the ongoing job. | ||
| */ | ||
| public class SparkCredentialRenewalTest { |
There was a problem hiding this comment.
This is the credential renewal long-running job. We can run this command to do the integrtation test.
env \
CATALOG_URI="$UC_URI" \
CATALOG_AUTH_TOKEN="$UC_TOKEN" \
CATALOG_NAME="main" \
S3_BASE_LOCATION="$UC_S3_LOCATION" \
SBT_OPTS="-Xmx8G -XX:+UseG1GC" \
"$PWD/build/sbt" "integrationTests/testOnly io.unitycatalog.integrationtests.SparkCredentialRenewalTest"There was a problem hiding this comment.
And if we set the CREDENTIAL_RENEWAL_TEST_RENEWAL_ENABLED=false in this test, then the job will be failure.
There was a problem hiding this comment.
thsi should be in the class docs as instructions on how to run this manually. not in comments.
There was a problem hiding this comment.
Yes, it's good to add in class docs. Done !
| private static final boolean RENEW_CRED_ENABLED = envBoolean(PREFIX + "RENEWAL_ENABLED", true); | ||
|
|
||
| // Define the CREDENTIAL_RENEWAL_TEST_ROW_COUNT environment variable. | ||
| private static final long ROW_COUNT = envLong(PREFIX + "ROW_COUNT", 10_000_000_000L); |
There was a problem hiding this comment.
Set this to 10^10, the test will be running for 1.5 hours, which trigger several rounds of the credential renewal.
| String testCatalogKey = String.format("spark.sql.catalog.%s", CATALOG_NAME); | ||
| spark = SparkSession.builder() | ||
| .appName("test-credential-renewal-in-long-running-job") | ||
| .master("local[1]") // Make it single-threaded explicitly. |
There was a problem hiding this comment.
single-thread, make it run slowly, without exhausting the host's CPU resources.
|
|
||
| @Test | ||
| public void testLongRunningJob() { | ||
| sql("INSERT INTO %s SELECT id, CONCAT('val_', id) AS val FROM range(0, %s)", |
There was a problem hiding this comment.
The whole job is a simple writing job.
There was a problem hiding this comment.
shouldnt we test both reads and writes?
basically.. why not follow the exactly strategy that you used in the earlier PR we merged?
you just have create multiple files in the same way, it will test both reads, writes, multiple tables, etcl.
the only thing you need to change is instead of manual clock advance.. you can simply Thread.sleep(1000).
by default it can be 1 files with 1 rows that runs in 1 second. then the setting simply becomes how many seconds do you want the code to run
| "io.delta" %% "delta-spark" % deltaVersion % Test, | ||
| "org.apache.hadoop" % "hadoop-aws" % "3.3.6" % Test, | ||
| "org.apache.hadoop" % "hadoop-azure" % "3.3.6" % Test, | ||
| "org.apache.hadoop" % "hadoop-aws" % hadoopVersion % Test, |
There was a problem hiding this comment.
Before this PR, we use the hadoop 3.3.6 to run the integration tests by default. while actually, I encountered a serious issue here #1092 (comment).
I think I will need a separate PR to address the cross-hadoop version issue.
| .config(testCatalogKey + ".renewCredential.enabled", String.valueOf(RENEW_CRED_ENABLED)) | ||
| .getOrCreate(); | ||
|
|
||
| sql("CREATE SCHEMA %s", SCHEMA_NAME); |
There was a problem hiding this comment.
this will fail if the schema exists.. right? might not be the behavior we want when we point to a different UC.
There was a problem hiding this comment.
Good point. Yes it will fail. I think it's better to use a random schema name, rather than the specified name via environment, otherwise it's hard for us to determine if we need to drop it or not.
By using the random schema, we can just create our own and after the test just drop it.
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Typically, cloud vendor credentials (used to access cloud storage) issued by the UC server |
There was a problem hiding this comment.
this test.. by default runs very fast (as it should as its always enabled) and so it really does not test anything by default... right?
only when you manually configure it to run for long it tests something.
There was a problem hiding this comment.
this is important context that needs to be written down.
There was a problem hiding this comment.
By default, we use the row count as 10^10 (https://github.com/unitycatalog/unitycatalog/pull/1119/files#diff-a961fbeeb181232588b1a8b7657dff464d114c46faf6b4fd355903115601efe5R54), so it will take roughly 2 hours to finish all the tests. While if people want to do some initial testing to be confident that everything for the testing environment and configuration is fine, then it will be better to specifty the environment variable CREDENTIAL_RENEWAL_TEST_ROW_COUNT to smaller number, such as 10.
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
1e5bc9a to
4f0c265
Compare
|
|
||
| lazy val integrationTests = (project in file("integration-tests")) | ||
| .enablePlugins(CheckstylePlugin) | ||
| .dependsOn(spark) |
There was a problem hiding this comment.
it will be better to use the cross module depending here than configured the static io.unitycatalog:unitycatalog-spark here. https://github.com/unitycatalog/unitycatalog/pull/1119/files#diff-5634c415cd8c8504fdb973a3ed092300b43c4b8fc1e184f7249eb29a55511f91L645
Since for the later one, we need to manually publish the unitycatalog-spark into local maven repo, which will makes the integrationTests more hard to run.
With the former one, if we make any changes in the unitycatalog-spark connector, then we can simply use the command ./build/sbt integrationTests/test to run the integrationTests without publishing.
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
Signed-off-by: Zheng Hu <[email protected]>
| * credential renewal mechanism works as expected, seamlessly refreshing credentials without | ||
| * interrupting the ongoing job. | ||
| */ | ||
| public class SparkCredentialRenewalTest { |
There was a problem hiding this comment.
Yes, it's good to add in class docs. Done !
| .config(testCatalogKey + ".renewCredential.enabled", String.valueOf(RENEW_CRED_ENABLED)) | ||
| .getOrCreate(); | ||
|
|
||
| sql("CREATE SCHEMA %s", SCHEMA_NAME); |
There was a problem hiding this comment.
Good point. Yes it will fail. I think it's better to use a random schema name, rather than the specified name via environment, otherwise it's hard for us to determine if we need to drop it or not.
By using the random schema, we can just create our own and after the test just drop it.
| @AfterAll | ||
| public static void afterAll() { | ||
| sql("DROP TABLE IF EXISTS %s", TABLE_NAME); | ||
| sql("DROP SCHEMA IF EXISTS %s", SCHEMA_NAME); |
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Typically, cloud vendor credentials (used to access cloud storage) issued by the UC server |
There was a problem hiding this comment.
By default, we use the row count as 10^10 (https://github.com/unitycatalog/unitycatalog/pull/1119/files#diff-a961fbeeb181232588b1a8b7657dff464d114c46faf6b4fd355903115601efe5R54), so it will take roughly 2 hours to finish all the tests. While if people want to do some initial testing to be confident that everything for the testing environment and configuration is fine, then it will be better to specifty the environment variable CREDENTIAL_RENEWAL_TEST_ROW_COUNT to smaller number, such as 10.
|
|
||
| @Test | ||
| public void testLongRunningJob() { | ||
| sql("INSERT INTO %s SELECT id, CONCAT('val_', id) AS val FROM range(0, %s)", |
…atalog#1119) **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [x] If there is a related issue, make sure it is linked to this PR. - [x] If you've fixed a bug or added code that should be tested, add tests! - [ ] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** For this issue, unitycatalog#1092. Since the credential may be expired for 30minutes, so in this PR, I designed a streaming job which will redirect the stream into the designated table in 40 min. And if all the rows are correct, and the streaming job is not been broken, then the credential renewal should be fine. --------- Signed-off-by: Zheng Hu <[email protected]>
**PR Checklist** - [x] A description of the changes is added to the description of this PR. - [x] If there is a related issue, make sure it is linked to this PR. - [x] If you've fixed a bug or added code that should be tested, add tests! - [ ] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** Backport the #1119 to the branch-0.3 . The whole backport progress is here: #1163 Signed-off-by: Zheng Hu <[email protected]>
PR Checklist
docsis updatedDescription of changes
For this issue, #1092. Since the credential may be expired for 30minutes, so in this PR, I designed a streaming job which will redirect the stream into the designated table in 40 min. And if all the rows are correct, and the streaming job is not been broken, then the credential renewal should be fine.