Repository navigation
Add local aws credential renewal integration test. - #1123
Conversation
702967c to
3ed6d6f
Compare
|
The failed test info is here: |
| return new ManualClock(now); | ||
| } | ||
|
|
||
| Map<String, Clock> globalManualClocks = new ConcurrentHashMap<>(); |
There was a problem hiding this comment.
Yes, better to be private. The problem is: for the variable defined in java interface, all will be applied the same accessibilty via public static final, so we cannot add private` modifier for the interface's level variables.
But I think I can move the globalManualClock inside the class ManualClock, since it should be manual clock specified. That make more sense.
|
|
||
| verifiedTs.add(ts); | ||
| } | ||
| } |
There was a problem hiding this comment.
if the host is not what is expected in a test .. will the checkCredential implicitly pass?
if yes, then that is wrong as some test may accidentally pass if someone changes the bucket name in the test and not know this internal detail.
There was a problem hiding this comment.
It won't success, because another host won't trigger the verfiedTs updating, which will finally fail the renewalCount assertion. The verifiedTs (exposing as renewalCount is one of the intentionally designed assertion for addressing the accurate credential renewal times ).
| "spark.sql.catalog.spark_catalog", "org.apache.spark.sql.delta.catalog.DeltaCatalog") | ||
| .config("spark.hadoop." + UCHadoopConf.UC_TEST_CLOCK_NAME, CLOCK_NAME) | ||
| .config("spark.hadoop." + UCHadoopConf.UC_RENEWAL_LEAD_TIME_KEY, 0L) | ||
| .config("spark.default.parallelism", "1") |
There was a problem hiding this comment.
isnt this achieved by local[1]?
There was a problem hiding this comment.
Yes, read the document, should be better to use the local[1] rather than setting this configure key. here is the explanation.
- Setting
spark.default.parallelism=1does not make Spark single-threaded — it just limits RDD parallelism by default. - Using
local[1]would make everything single-threaded, including I/O, scheduling, etc.
| && conf.get(UCHadoopConf.S3A_INIT_SECRET_KEY) != null | ||
| && conf.get(UCHadoopConf.S3A_INIT_SESSION_TOKEN) != null | ||
| && conf.get(UCHadoopConf.S3A_INIT_CRED_EXPIRED_TIME) != null) { | ||
| && conf.get(UCHadoopConf.S3A_INIT_SESSION_TOKEN) != null) { |
There was a problem hiding this comment.
&& conf.get(UCHadoopConf.S3A_INIT_CRED_EXPIRED_TIME) != null) {
why is this removed?
There was a problem hiding this comment.
Because the expiredTime is allowed to be null. When I design this PR, and the original code did not set any expiration time when generating the credential from the UC server, Please see: https://github.com/unitycatalog/unitycatalog/pull/1123/files#diff-5084dc98e0f29a934bf2486de5be2667d7c6d375beb3e23add41a3bbd42554fbR72-R74
And I found we won't correctly initialize the GenericCredentials because of the conf.get(UCHadoopConf.S3A_INIT_CRED_EXPIRED_TIME) != null checking, since it's always null. (The UC server does not set it ).
The above is the code investigation. From another side, if the temporaryCredentialsApi just did not get the expiration time for credential, but actually the credentials is generated, then actually we will never use it a the initial GenericCredentials.
| .config("spark.hadoop." + UCHadoopConf.UC_RENEWAL_LEAD_TIME_KEY, 0L) | ||
| .config("spark.default.parallelism", "1") | ||
| .config("spark.sql.shuffle.partitions", "1") | ||
| .config("spark.sql.catalog.renewal", UCSingleCatalog.class.getName()) |
There was a problem hiding this comment.
i was stupidly a bit confused by this. renewal is a scope that you have introduced as part of public static final String UC_RENEWAL_LEAD_TIME_KEY = "fs.unitycatalog.renewal.leadTimeMillis" ... and i was confused why renewal is being used here.
can you name is something more unique.. like the name of the test.
also the name is being used in multiple places here and beforeEach .. can you just define a const?
There was a problem hiding this comment.
Sorry for the confusion, let me make this more clear. .Thanks for sharing your feeling !
| } | ||
|
|
||
| @Test | ||
| public void testRenewal() throws Exception { |
There was a problem hiding this comment.
how long does this test take to run?
| new SerializableConfiguration( | ||
| DeltaTable.forName(session, TABLE_NAME).deltaLog().newDeltaHadoopConf()); | ||
|
|
||
| JavaRDD<Row> rdd = |
There was a problem hiding this comment.
this is a fairly complicated code.. please add comments explaining what is happening in this code.. how is it testing stuff with manual clock such that credential renew is actually tested.
There was a problem hiding this comment.
Updated the code and comment, please see if it make more clear for you.
|
|
||
| // Advance the clock to trigger the 1st renewal. | ||
| CLOCK.advance(Duration.ofMillis(DEFAULT_INTERVAL_MILLIS)); | ||
| fs.getFileStatus(locPath); |
There was a problem hiding this comment.
you are doing fs operations yourself? then you are not testing that the Delta table read is actually doing file operations with proper credential renewal isnt it??
There was a problem hiding this comment.
Add the explanation for it here, https://github.com/unitycatalog/unitycatalog/pull/1123/files#diff-fae53ed54b97a94aa0f26b1720e854c670cc4e6738641f242b981915f065c0a2R159-R179
Please see if it make sense now, thanks for the comment !
| catalogOperations.createCatalog(new CreateCatalog().name("renewal").comment("Spark catalog")); | ||
|
|
||
| SdkSchemaOperations schemaOperations = new SdkSchemaOperations(createApiClient(serverConfig)); | ||
| schemaOperations.createSchema(new CreateSchema().name("default").catalogName("renewal")); |
There was a problem hiding this comment.
do you need to do this set up before every test.. or just once in the testsuite.
There was a problem hiding this comment.
I assume we may add more cases for it, so I init them in the beforeEach. I agree we should make all those operations more aligned. I just updated this.
0b8e6dc to
b1af64b
Compare
| && conf.get(UCHadoopConf.S3A_INIT_SECRET_KEY) != null | ||
| && conf.get(UCHadoopConf.S3A_INIT_SESSION_TOKEN) != null | ||
| && conf.get(UCHadoopConf.S3A_INIT_CRED_EXPIRED_TIME) != null) { | ||
| && conf.get(UCHadoopConf.S3A_INIT_SESSION_TOKEN) != null) { |
There was a problem hiding this comment.
Because the expiredTime is allowed to be null. When I design this PR, and the original code did not set any expiration time when generating the credential from the UC server, Please see: https://github.com/unitycatalog/unitycatalog/pull/1123/files#diff-5084dc98e0f29a934bf2486de5be2667d7c6d375beb3e23add41a3bbd42554fbR72-R74
And I found we won't correctly initialize the GenericCredentials because of the conf.get(UCHadoopConf.S3A_INIT_CRED_EXPIRED_TIME) != null checking, since it's always null. (The UC server does not set it ).
The above is the code investigation. From another side, if the temporaryCredentialsApi just did not get the expiration time for credential, but actually the credentials is generated, then actually we will never use it a the initial GenericCredentials.
|
|
||
| public abstract class GenericCredentialProvider { | ||
| // The remaining time before expiration, used to trigger renewal in advance. | ||
| private static final long DEFAULT_RENEWAL_LEAD_TIME_MILLIS = 30 * 1000; |
There was a problem hiding this comment.
This can be removed, because we just introduced a hadoop configuration key, so that we can also set it the test suites. That will be more convinient to do the integration testing, since for the IT, we don't have API to explicitly use the GenericCredentialsProvider's constructor to pass renewalLeadTime to construct --- All the providers are initialized via the java reflection.
The only approach is using the hadoop configuration setting.
| this.conf = conf; | ||
|
|
||
| // Use the test clock if one is intentionally configured for testing. | ||
| String clockName = conf.get(UCHadoopConf.UC_TEST_CLOCK_NAME); |
There was a problem hiding this comment.
Use the intentionally configured clockName to access the manualClock from the globalManualClock, so that all of those infra can share the same manualClock, then we can use this shared manualClock to control all the infra's time.
- OSS UC server: Need this
clockto generate credentials. AwsVendedTokenProvider: Need thisclockto determine if it's time to renew.- IntegrationTest: Need this
clockto advance the time step by step.
And considering we cannot pass the clock instance and make it go-through all the stack, so introducing a configure key to selectively access the clock from global should be the correct approach. --- But we need to remember to clean the newly allocated clock if we created one in the test. Otherwise, no big impact just accumulating some tesing clocks in the testing process.
| return new ManualClock(now); | ||
| } | ||
|
|
||
| Map<String, Clock> globalManualClocks = new ConcurrentHashMap<>(); |
There was a problem hiding this comment.
Yes, better to be private. The problem is: for the variable defined in java interface, all will be applied the same accessibilty via public static final, so we cannot add private` modifier for the interface's level variables.
But I think I can move the globalManualClock inside the class ManualClock, since it should be manual clock specified. That make more sense.
| ), | ||
| schema = StructType(fields), | ||
| provider = Some(t.getDataSourceFormat.getValue), | ||
| provider = Some(t.getDataSourceFormat.getValue.toLowerCase()), |
There was a problem hiding this comment.
If we don't lower case here, then we will encounter another problem: #1121 (comment)
| @Override | ||
| protected AbfsVendedTokenProvider createTestProvider( | ||
| Clock clock, | ||
| long renewalLeadTimeMillis, |
There was a problem hiding this comment.
we just changed to set configuration keys in the hadoop configuration (for both clock and renewLeadTimeMillis ). So we don't need those contructors any more.
As I saide above here: https://github.com/unitycatalog/unitycatalog/pull/1123/files#r2461390293
| "spark.sql.catalog.spark_catalog", "org.apache.spark.sql.delta.catalog.DeltaCatalog") | ||
| .config("spark.hadoop." + UCHadoopConf.UC_TEST_CLOCK_NAME, CLOCK_NAME) | ||
| .config("spark.hadoop." + UCHadoopConf.UC_RENEWAL_LEAD_TIME_KEY, 0L) | ||
| .config("spark.default.parallelism", "1") |
There was a problem hiding this comment.
Yes, read the document, should be better to use the local[1] rather than setting this configure key. here is the explanation.
- Setting
spark.default.parallelism=1does not make Spark single-threaded — it just limits RDD parallelism by default. - Using
local[1]would make everything single-threaded, including I/O, scheduling, etc.
| .config("spark.hadoop." + UCHadoopConf.UC_RENEWAL_LEAD_TIME_KEY, 0L) | ||
| .config("spark.default.parallelism", "1") | ||
| .config("spark.sql.shuffle.partitions", "1") | ||
| .config("spark.sql.catalog.renewal", UCSingleCatalog.class.getName()) |
There was a problem hiding this comment.
Sorry for the confusion, let me make this more clear. .Thanks for sharing your feeling !
| } | ||
|
|
||
| @Test | ||
| public void testRenewal() throws Exception { |
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]>
| catalogOperations.createCatalog( | ||
| new CreateCatalog().name(CATALOG_NAME).comment("Spark catalog")); | ||
|
|
||
| // Initialize the schema in unity catalog server. | ||
| schemaOperations = new SdkSchemaOperations(createApiClient(serverConfig)); | ||
| schemaOperations.createSchema(new CreateSchema().name(SCHEMA_NAME).catalogName(CATALOG_NAME)); |
There was a problem hiding this comment.
cant you reuse the catalog + schema across tests with beforeAll? this is adding latency unnecessarily
There was a problem hiding this comment.
then you can avoid deleting the schema as well.
There was a problem hiding this comment.
Hi @tdas , what you said should be right. I think the constrait is: currently the catalog creation and schema creation depends on the OSS UC Server's BaseCRUDITest, however this test will intial the catalogOperations in the BeforeEach method, then we cannot make it to be part of the beforeAll ( which requires to be a static method ).
There was a problem hiding this comment.
There are other test cases which depend on this BaseCRUDTest feature ( I mean the beforeEach level catalog & schema initialization and destory ) , if we plan to change then maybe we should change those test cases firstly.
| Path locPath = new Path(location); | ||
|
|
||
| // Create the external delta path-based table. | ||
| S3CredFileSystem.credentialCheckEnabled = false; |
There was a problem hiding this comment.
why do you need to disable this?
There was a problem hiding this comment.
and why do you need to create the path-based table separately and than again calling create to define the catalog table? what are you achieving with this two step instead of one step?
There was a problem hiding this comment.
Because currently we are not supporting creating UC managed table direclty. So we have to create the path-based external table in the first step, and then connect it to the catalog ( let the UC catalog know there is a table in this catalog ).
There was a problem hiding this comment.
Disabling the credentialCheckEnabled for the first step is because the path-based table creation won't go through the Catalog#createTable or Catalog#loadTable, then we have no chance to inject the cred props , which will fail the S3CredFileSytem's credential verification.
there are similar flag set you can see here, which I think we may need to look for a better way for this also.
Ideally, the correct approach should be: supporting the credentials properties injection also for path-based table, not only catalog-based table.
There was a problem hiding this comment.
Oh, sorry. we currently only not support the path-based table creation without specified location.
The SQL CREATE TABLE %s (id INT) USING delta LOCATION '%s' should be fine. Thanks for the reminder.
| S3CredFileSystem.credentialCheckEnabled = false; | ||
| sql("CREATE TABLE delta.`%s` (id INT) USING delta PARTITIONED BY (partition INT)", location); | ||
| S3CredFileSystem.credentialCheckEnabled = true; | ||
|
|
||
| // Create the catalog table referring to external table. | ||
| sql("CREATE TABLE %s USING delta LOCATION '%s'", TABLE_NAME, location); |
There was a problem hiding this comment.
same comment as above test. why are you doing this into steps? why not just the second CREATE statement as CREATE TABLE %s (id INT, partition INT) USING delta LOCATION %s PARTITIONED BY partition
There was a problem hiding this comment.
Thanks for the reminder, Done !
| // Create the catalog table referring to external table. | ||
| sql("CREATE TABLE %s USING delta LOCATION '%s'", TABLE_NAME, location); | ||
|
|
||
| // Insert 4 rows into each partition where (id % 3) equals the partition key. |
There was a problem hiding this comment.
why three INSERT with INSERT INTO ... VALUES (1, 1), (1, 2), (1,3)
that will create 3 files with 1 row each because partition column has 3 values.
There was a problem hiding this comment.
Em, let me simply this test. Done !
| testClock().advance(Duration.ofMillis(DEFAULT_INTERVAL_MILLIS)); | ||
| return input; | ||
| }, | ||
| Encoders.row(schema)) |
There was a problem hiding this comment.
minor: probably will be simpler code to that defining schema and stuff if you use Java UDFs
There was a problem hiding this comment.
if there are only 3 rows, 1 in each file as i suggested above ... and selected only the id, then you can just use mapFunction and Encoders.INT
| serverProperties.put("s3.accessKey.0", "accessKey0"); | ||
| serverProperties.put("s3.secretKey.0", "secretKey0"); | ||
| serverProperties.put("s3.sessionToken.0", "sessionToken0"); | ||
| serverProperties.put("s3.credentialsGenerator.0", CREDENTIALS_GENERATOR); |
There was a problem hiding this comment.
can you leave a comment here explaining what this will do?
There was a problem hiding this comment.
Done, thanks for sharing !
| .secretAccessKey(awsSessionCredentials.secretAccessKey()) | ||
| .sessionToken(awsSessionCredentials.sessionToken())); | ||
|
|
||
| // Set the expiration time. |
There was a problem hiding this comment.
add comment why this special condition is needed
| IntStream.concat(IntStream.rangeClosed(1, 12), IntStream.rangeClosed(1, 12)) | ||
| .boxed() | ||
| .sorted() | ||
| .collect(Collectors.toList())); |
There was a problem hiding this comment.
general question: which test in the set of tests we have written till now ensures that the credentials are not accidentally used across queries even if they are for the same table?
| .write() | ||
| .format("delta") | ||
| .mode("append") | ||
| .saveAsTable(TABLE_NAME); |
There was a problem hiding this comment.
shouldnt we test writing a to a different table to make sure that multiple tables in the same query work together?
| assertThat(rows.stream().map(r -> r.getInt(0)).collect(Collectors.toList())) | ||
| .isEqualTo( | ||
| IntStream.concat(IntStream.rangeClosed(1, 12), IntStream.rangeClosed(1, 12)) | ||
| .boxed() | ||
| .sorted() |
There was a problem hiding this comment.
this seems very verbose! is this the best way to do this in java?
There was a problem hiding this comment.
i think if you have just 3 rows... this becomes much simpler to write this as 1, 2, 3, 1, 2, 3?
Signed-off-by: Zheng Hu <[email protected]>
tdas
left a comment
There was a problem hiding this comment.
thank you for this very very critical test. now we have the framework to test more table operations locally as well.
do we need to have the same test azure and gcs as well?
**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** The related issue is : #1175, this PR achieved the similar local integration tests that we've did in aws s3. #1123 --------- 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** The related issue is : unitycatalog#1175, this PR achieved the similar local integration tests that we've did in aws s3. unitycatalog#1123 --------- 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** The related issue is : unitycatalog#1175, this PR achieved the similar local integration tests that we've did in aws s3. unitycatalog#1123 --------- Signed-off-by: Zheng Hu <[email protected]>

PR Checklist
docsis updatedDescription of changes
Related issue is: #1121