Compare commits
No commits in common. "ee51c82145ba3e835a4cf304286c8fc3af127d45" and "d7f2e59f9451789f0339b67a2d49d5f7d1356600" have entirely different histories.
ee51c82145
...
d7f2e59f94
9 changed files with 43 additions and 84 deletions
11
cli.py
11
cli.py
|
|
@ -3,12 +3,9 @@ import json
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from query_performance_gauge import run_measuring_session
|
from query_performance_gauge import run_measuring_session
|
||||||
from utils import compose_config
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
@click.option("--credentials", type=click.File())
|
@click.option("--config", required=True, type=click.File())
|
||||||
@click.option("--queries", type=click.File())
|
def measure_performance(config):
|
||||||
@click.option("--config", type=click.File())
|
run_measuring_session(json.load(config))
|
||||||
def measure_performance(credentials, queries, config):
|
|
||||||
config = compose_config(config, credentials, queries)
|
|
||||||
run_measuring_session(config)
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
{
|
|
||||||
"connection_details": {
|
|
||||||
"engine": "mysql",
|
|
||||||
"host": "the-sql-host",
|
|
||||||
"port": 3306,
|
|
||||||
"user": "your_user",
|
|
||||||
"password": "your_password",
|
|
||||||
"schema": "comprea"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -14,5 +14,15 @@
|
||||||
"path_to_key": "G:\\path\\to\\ssh\\key.pem",
|
"path_to_key": "G:\\path\\to\\ssh\\key.pem",
|
||||||
"ssh_private_key_password": "my_keys_password"
|
"ssh_private_key_password": "my_keys_password"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"queries_to_measure": [
|
||||||
|
{
|
||||||
|
"name": "Fast Smoke Test",
|
||||||
|
"query_string": "SELECT 1"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Delivered carts on a day",
|
||||||
|
"query_string": "select * from comprea.cart c where c.status = 'delivered' and c.date_delivered >= UNIX_TIMESTAMP(date('2022-05-24'))"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
"queries_to_measure": [
|
|
||||||
{
|
|
||||||
"name": "Fast Smoke Test",
|
|
||||||
"query_string": "SELECT 1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Delivered carts on a day",
|
|
||||||
"query_string": "select * from comprea.cart c where c.status = 'delivered' and c.date_delivered >= UNIX_TIMESTAMP(date('2022-05-24'))"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
22
config_examples/trino_config.json
Normal file
22
config_examples/trino_config.json
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"connection_details": {
|
||||||
|
"engine": "trino",
|
||||||
|
"host": "the_trino_host",
|
||||||
|
"port": "443",
|
||||||
|
"user": "your_user",
|
||||||
|
"password": "your_password",
|
||||||
|
"http_scheme": "https",
|
||||||
|
"catalog": "app_lm_mysql",
|
||||||
|
"schema": "comprea"
|
||||||
|
},
|
||||||
|
"queries_to_measure": [
|
||||||
|
{
|
||||||
|
"name": "Fast Smoke Test",
|
||||||
|
"query_string": "SELECT * FROM system.runtime.nodes"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Delivered carts on a day",
|
||||||
|
"query_string": "select * from app_lm_mysql.comprea.cart c where c.status = 'delivered' and c.date_delivered >= to_unixtime(date('2022-05-24'))"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
{
|
|
||||||
"connection_details": {
|
|
||||||
"engine": "trino",
|
|
||||||
"host": "the_trino_host",
|
|
||||||
"port": "443",
|
|
||||||
"user": "your_user",
|
|
||||||
"password": "your_password",
|
|
||||||
"http_scheme": "https",
|
|
||||||
"catalog": "app_lm_mysql",
|
|
||||||
"schema": "comprea"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
16
readme.md
16
readme.md
|
|
@ -16,32 +16,28 @@ You will install whatever version is in the shared drive at that point. Dependin
|
||||||
might want to instead make a copy of the repository in your own local machine and install from there. That way, you
|
might want to instead make a copy of the repository in your own local machine and install from there. That way, you
|
||||||
won't be affected by someone making `git checkout` in the shared drive.
|
won't be affected by someone making `git checkout` in the shared drive.
|
||||||
|
|
||||||
2. Afterwards, you need to make a credentials and a query config file. See below details on how to compose one.
|
2. Afterwards, you need to make a config file. See below details on how to compose one.
|
||||||
|
|
||||||
3. Once you have your config file ready, run the following command from the terminal.
|
3. Once you have your config file ready, run the following command from the terminal.
|
||||||
|
|
||||||
```commandline
|
```commandline
|
||||||
measure_query_performance --credentials my_credentials.json --queries my_queries.json
|
measure_query_performance --config my_config_file.json
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Results will be printed in your console as they are available. If instead you would like to store them in a file, a
|
4. Results will be printed in your console as they are available. If instead you would like to store them in a file, a
|
||||||
quick and easy hack is to redirect output in Powershell to a file. You can do it like this:
|
quick and easy hack is to redirect output in Powershell to a file. You can do it like this:
|
||||||
|
|
||||||
```commandline
|
```commandline
|
||||||
measure_query_performance --credentials my_credentials.json --queries my_queries.json | Out-File -FilePath my_results.txt
|
measure_query_performance --config my_config_file.json | Out-File -FilePath my_results.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
## Composing config files
|
## Composing a config file
|
||||||
|
|
||||||
The application takes two config files: one for the credentials and connection details, one for the queries to run.
|
|
||||||
You can mix and match several of both (as in, you can run the same query set at different dbs, or you can have
|
|
||||||
multiple query sets run on the same database).
|
|
||||||
|
|
||||||
You can take a look at examples for different setups in `config_examples`. If you want to make a new config file, it
|
You can take a look at examples for different setups in `config_examples`. If you want to make a new config file, it
|
||||||
will probably be easier for you to start from one of those templates. The legacy examples should be ignored unless
|
will probably be easier for you to start from one of those templates.
|
||||||
you want to understand outdated config files.
|
|
||||||
|
|
||||||
A few notes:
|
A few notes:
|
||||||
|
|
||||||
- The valid engines are `"trino"` and `"mysql"`.
|
- The valid engines are `"trino"` and `"mysql"`.
|
||||||
- You can place as many queries as you would like in the `queries_to_measure` list.
|
- You can place as many queries as you would like in the `queries_to_measure` list.
|
||||||
- I advice you to make the first query a silly, fast query such as `SELECT 1` to validate your connection and
|
- I advice you to make the first query a silly, fast query such as `SELECT 1` to validate your connection and
|
||||||
|
|
|
||||||
32
utils.py
32
utils.py
|
|
@ -1,32 +0,0 @@
|
||||||
from typing import Union
|
|
||||||
from io import TextIOWrapper
|
|
||||||
import json
|
|
||||||
|
|
||||||
|
|
||||||
def compose_config(
|
|
||||||
config: Union[TextIOWrapper, None],
|
|
||||||
credentials: Union[TextIOWrapper, None],
|
|
||||||
queries: Union[TextIOWrapper, None],
|
|
||||||
) -> dict:
|
|
||||||
"""
|
|
||||||
Receive the CLI arguments and compose a session config.
|
|
||||||
|
|
||||||
:param config: file pointer to a full config file.
|
|
||||||
:param credentials: file pointer to a credentials file.
|
|
||||||
:param queries: file pointer to a queries file.
|
|
||||||
:return: a dict with the composed configuration.
|
|
||||||
"""
|
|
||||||
|
|
||||||
if config is not None:
|
|
||||||
DeprecationWarning(
|
|
||||||
"Usage of a full config file will be deprecated. Instead, use the credentials and queries arguments."
|
|
||||||
)
|
|
||||||
return json.load(config)
|
|
||||||
|
|
||||||
if credentials is None or queries is None:
|
|
||||||
raise ValueError(
|
|
||||||
"You need to provide both --credentials and --queries arguments."
|
|
||||||
)
|
|
||||||
|
|
||||||
# Merge both into one dict so it follows the same structure as a full config file
|
|
||||||
return {**json.load(credentials), **json.load(queries)}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue