-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Merge three Prometheus integration tests into one #12458
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
.../trino-prometheus/src/test/java/io/trino/plugin/prometheus/TestPrometheusIntegration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.trino.plugin.prometheus; | ||
|
|
||
| import com.google.common.collect.ImmutableMap; | ||
| import io.airlift.units.Duration; | ||
| import io.trino.spi.connector.ConnectorSplitSource; | ||
| import io.trino.spi.connector.DynamicFilter; | ||
| import io.trino.testing.AbstractTestQueryFramework; | ||
| import io.trino.testing.MaterializedResult; | ||
| import io.trino.testing.QueryRunner; | ||
| import org.testng.annotations.Test; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import static io.trino.plugin.prometheus.PrometheusQueryRunner.createPrometheusClient; | ||
| import static io.trino.plugin.prometheus.PrometheusQueryRunner.createPrometheusQueryRunner; | ||
| import static io.trino.spi.connector.NotPartitionedPartitionHandle.NOT_PARTITIONED; | ||
| import static java.util.concurrent.TimeUnit.DAYS; | ||
| import static java.util.concurrent.TimeUnit.SECONDS; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.testng.Assert.assertEquals; | ||
|
|
||
| public class TestPrometheusIntegration | ||
| extends AbstractTestQueryFramework | ||
| { | ||
| private static final int NUMBER_MORE_THAN_EXPECTED_NUMBER_SPLITS = 100; | ||
|
|
||
| private PrometheusServer server; | ||
| private PrometheusClient client; | ||
|
|
||
| @Override | ||
| protected QueryRunner createQueryRunner() | ||
| throws Exception | ||
| { | ||
| this.server = closeAfterClass(new PrometheusServer()); | ||
| this.client = createPrometheusClient(server); | ||
| return createPrometheusQueryRunner(server, ImmutableMap.of(), ImmutableMap.of()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testSelectTable() | ||
| { | ||
| assertThat(query("SELECT labels FROM prometheus.default.up LIMIT 1")) | ||
| .matches("SELECT MAP(ARRAY[VARCHAR 'instance', '__name__', 'job'], ARRAY[VARCHAR 'localhost:9090', 'up', 'prometheus'])"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testPushDown() | ||
| { | ||
| // default interval on the `up` metric that Prometheus records on itself is about 15 seconds, so this should only yield one or two row | ||
| MaterializedResult results = computeActual("SELECT * FROM prometheus.default.up WHERE timestamp > (NOW() - INTERVAL '15' SECOND)"); | ||
| assertThat(results).hasSizeBetween(1, 2); | ||
| } | ||
|
|
||
| @Test | ||
| public void testShowTables() | ||
| { | ||
| assertQuery("SHOW TABLES IN default LIKE 'up'", "VALUES 'up'"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testShowCreateSchema() | ||
| { | ||
| assertQuery("SHOW CREATE SCHEMA default", "VALUES 'CREATE SCHEMA prometheus.default'"); | ||
| assertQueryFails("SHOW CREATE SCHEMA unknown", ".*Schema 'prometheus.unknown' does not exist"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testListSchemaNames() | ||
| { | ||
| assertQuery("SHOW SCHEMAS LIKE 'default'", "VALUES 'default'"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreateTable() | ||
| { | ||
| assertQueryFails("CREATE TABLE default.foo (text VARCHAR)", "This connector does not support creating tables"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDropTable() | ||
| { | ||
| assertQueryFails("DROP TABLE default.up", "This connector does not support dropping tables"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDescribeTable() | ||
| { | ||
| assertQuery("DESCRIBE default.up", | ||
| "VALUES " + | ||
| "('labels', 'map(varchar, varchar)', '', '')," + | ||
| "('timestamp', 'timestamp(3) with time zone', '', '')," + | ||
| "('value', 'double', '', '')"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCorrectNumberOfSplitsCreated() | ||
| { | ||
| PrometheusConnectorConfig config = new PrometheusConnectorConfig(); | ||
| config.setPrometheusURI(server.getUri()); | ||
| config.setMaxQueryRangeDuration(new Duration(21, DAYS)); | ||
| config.setQueryChunkSizeDuration(new Duration(1, DAYS)); | ||
| config.setCacheDuration(new Duration(30, SECONDS)); | ||
| PrometheusTable table = client.getTable("default", "up"); | ||
| PrometheusSplitManager splitManager = new PrometheusSplitManager(client, new PrometheusClock(), config); | ||
| ConnectorSplitSource splits = splitManager.getSplits( | ||
| null, | ||
| null, | ||
| new PrometheusTableHandle("default", table.getName()), | ||
| null, | ||
| (DynamicFilter) null); | ||
| int numSplits = splits.getNextBatch(NOT_PARTITIONED, NUMBER_MORE_THAN_EXPECTED_NUMBER_SPLITS).getNow(null).getSplits().size(); | ||
| assertEquals(numSplits, config.getMaxQueryRangeDuration().getValue(TimeUnit.SECONDS) / config.getQueryChunkSizeDuration().getValue(TimeUnit.SECONDS), | ||
| 0.001); | ||
| } | ||
| } |
74 changes: 0 additions & 74 deletions
74
...prometheus/src/test/java/io/trino/plugin/prometheus/TestPrometheusIntegrationMetrics.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.