-
Notifications
You must be signed in to change notification settings - Fork 5.5k
feat(connector): Enable case-sensitive identifier support for Prometheus connector #26260
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
base: master
Are you sure you want to change the base?
feat(connector): Enable case-sensitive identifier support for Prometheus connector #26260
Conversation
Reviewer's GuideIntroduce an optional case-sensitive identifier matching mode for Prometheus connector by extending configuration, updating metadata resolution logic to normalize and compare table names based on the mode, and enriching tests to cover both default and case-sensitive behaviors. Class diagram for updated PrometheusConnectorConfig and PrometheusMetadataclassDiagram
class PrometheusConnectorConfig {
URI prometheusURI
String trustStorePath
String truststorePassword
boolean verifyHostName
boolean caseSensitiveNameMatchingEnabled
+getPrometheusURI()
+setVerifyHostName(boolean)
+isCaseSensitiveNameMatchingEnabled()
+setCaseSensitiveNameMatchingEnabled(boolean)
}
class PrometheusMetadata {
PrometheusClient prometheusClient
boolean caseSensitiveNameMatchingEnabled
+normalizeIdentifier(ConnectorSession, String)
}
PrometheusMetadata --> PrometheusConnectorConfig : uses config
PrometheusConnectorConfig <|-- PrometheusConnectorConfig : config property added
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `presto-prometheus/src/test/java/com/facebook/presto/plugin/prometheus/TestPrometheusMixedCase.java:63-64` </location>
<code_context>
+ .setCaseSensitiveNameMatchingEnabled(false));
}
@Test
</code_context>
<issue_to_address>
**suggestion (testing):** Missing test for case-insensitive mode with mixed-case table names.
Please add a test for the default case-insensitive mode to confirm that queries with varying table name casing (e.g., 'UP', 'Up', 'up') all work as expected.
</issue_to_address>
### Comment 2
<location> `presto-prometheus/src/test/java/com/facebook/presto/plugin/prometheus/TestPrometheusRetrieveUpValueIntegrationTests.java:57` </location>
<code_context>
{
this.server = new PrometheusServer();
this.client = createPrometheusClient(server);
+ this.config = new PrometheusConnectorConfig();
}
</code_context>
<issue_to_address>
**suggestion (testing):** Missing explicit tests for case sensitivity in PrometheusMetadata unit tests.
Please add unit tests for PrometheusMetadata with caseSensitiveNameMatchingEnabled set to both true and false, ensuring correct table handle resolution and metadata retrieval for mixed-case table names.
Suggested implementation:
```java
private PrometheusServer server;
private PrometheusClient client;
private PrometheusConnectorConfig config;
@BeforeClass
protected void createQueryRunner()
{
this.server = new PrometheusServer();
this.client = createPrometheusClient(server);
this.config = new PrometheusConnectorConfig();
}
@Test
public void testCaseSensitiveTableHandleResolution()
{
PrometheusConnectorConfig caseSensitiveConfig = new PrometheusConnectorConfig(true); // true for case sensitivity
PrometheusMetadata metadata = new PrometheusMetadata(client, caseSensitiveConfig);
// Assume "MixedCaseTable" exists in Prometheus
SchemaTableName mixedCaseTable = new SchemaTableName("default", "MixedCaseTable");
ConnectorTableHandle handle = metadata.getTableHandle(mixedCaseTable);
assertNotNull(handle, "Table handle should be resolved for exact case match");
// Try with different case
SchemaTableName lowerCaseTable = new SchemaTableName("default", "mixedcasetable");
ConnectorTableHandle lowerHandle = metadata.getTableHandle(lowerCaseTable);
assertNull(lowerHandle, "Table handle should not be resolved for case mismatch when case sensitivity is enabled");
}
@Test
public void testCaseInsensitiveTableHandleResolution()
{
PrometheusConnectorConfig caseInsensitiveConfig = new PrometheusConnectorConfig(false); // false for case insensitivity
PrometheusMetadata metadata = new PrometheusMetadata(client, caseInsensitiveConfig);
// Assume "MixedCaseTable" exists in Prometheus
SchemaTableName mixedCaseTable = new SchemaTableName("default", "MixedCaseTable");
ConnectorTableHandle handle = metadata.getTableHandle(mixedCaseTable);
assertNotNull(handle, "Table handle should be resolved for exact case match");
// Try with different case
SchemaTableName lowerCaseTable = new SchemaTableName("default", "mixedcasetable");
ConnectorTableHandle lowerHandle = metadata.getTableHandle(lowerCaseTable);
assertNotNull(lowerHandle, "Table handle should be resolved for case mismatch when case sensitivity is disabled");
}
```
- Ensure that `PrometheusConnectorConfig` has a constructor that accepts a boolean for `caseSensitiveNameMatchingEnabled`.
- Make sure that the Prometheus test server contains a table named "MixedCaseTable" for these tests to pass.
- If `PrometheusMetadata` or `PrometheusConnectorConfig` do not support these options, you will need to add them.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
b5d3322
to
ef3ff6c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the doc! Only a few minor comments, overall it looks good.
Thanks for the release note! Nits:
|
5f71407
to
147b24e
Compare
Thanks for the review! I’ve addressed all the comments. |
ba85ae8
to
6ccf6bf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! (docs)
Pull updated branch, new local doc build, looks good. Thanks!
presto-prometheus/src/main/java/com/facebook/presto/plugin/prometheus/PrometheusMetadata.java
Outdated
Show resolved
Hide resolved
presto-prometheus/src/main/java/com/facebook/presto/plugin/prometheus/PrometheusMetadata.java
Outdated
Show resolved
Hide resolved
presto-prometheus/src/main/java/com/facebook/presto/plugin/prometheus/PrometheusMetadata.java
Outdated
Show resolved
Hide resolved
6ccf6bf
to
090d572
Compare
090d572
to
226f22a
Compare
8a43087
to
cac1576
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! (docs)
Pull branch, local doc build, looks good. Thanks!
.../src/test/java/com/facebook/presto/plugin/prometheus/TestPrometheusMixedCaseIntegration.java
Outdated
Show resolved
Hide resolved
.../src/test/java/com/facebook/presto/plugin/prometheus/TestPrometheusMixedCaseIntegration.java
Outdated
Show resolved
Hide resolved
f6449e4
to
d55d256
Compare
.../src/test/java/com/facebook/presto/plugin/prometheus/TestPrometheusMixedCaseIntegration.java
Outdated
Show resolved
Hide resolved
fail("Query should fail when using uppercase instead of lowercase with case sensitivity enabled"); | ||
} | ||
catch (RuntimeException e) { | ||
assertTrue(e.getMessage().contains("Table") || e.getMessage().contains("table") || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Dilli-Babu-Godari Can we assert against a common error message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Thanks!
"SELECT * FROM prometheus.default." + METRIC_UP + " LIMIT 1").toTestTypes(); | ||
assertEquals(upResult.getRowCount(), 1, "Query with exact case should return 1 row"); | ||
MaterializedResult goInfoResult = getQueryRunner().execute(session, | ||
"SELECT * FROM prometheus.default." + METRIC_GO_INFO + " LIMIT 1").toTestTypes(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the difference b/w this and earlier test case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this Tests case, we are checking whether the exact-case table is present. If no exact-case table exists, we assert a query failure, since that correctly enforces the mixed-case contract.
// 2. Verify that using a different case doesn't work | ||
try { | ||
getQueryRunner().execute(session, "SELECT * FROM prometheus.default." + METRIC_UP.toUpperCase() + " LIMIT 1"); | ||
fail("Query should fail when using uppercase instead of lowercase with case sensitivity enabled"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why aren't we using assertQueryFails
for failure tests, instead of catching it with exceptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uodated with assertQueryFails
Thanks!
assertTrue(tableNames.contains(METRIC_GO_INFO), | ||
METRIC_GO_INFO + " table not found"); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we use defined asserts for failure and success cases for the entire test case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used assertTrue
to check whether the value is present in a collection or not. I didn’t find any other method in QueryAssertions
for this case.
d55d256
to
bc0d1de
Compare
bc0d1de
to
9fb9eed
Compare
9fb9eed
to
daefbc0
Compare
f28cb0e
to
9240905
Compare
Description
Added catalog-level config to support case-sensitive-name-matching
This PR implements case sensitivity handling for Prometheus metric (table) names:
When case-sensitive-name-matching is set to true:
When case-sensitive-name-matching is set to false (default for backward compatibility):
Motivation and Context
Impact
Test Plan
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.