()
| 197 | |
| 198 | |
| 199 | def main() -> int: |
| 200 | parser = argparse.ArgumentParser( |
| 201 | prog="mz-workload-capture", |
| 202 | formatter_class=argparse.RawDescriptionHelpFormatter, |
| 203 | description="Records a workload profile from a running Materialize instance (without actual data)", |
| 204 | ) |
| 205 | |
| 206 | parser.add_argument("mz_url", type=str) |
| 207 | # Default cluster to use |
| 208 | parser.add_argument("--cluster", type=str, default="quickstart") |
| 209 | parser.add_argument( |
| 210 | "-o", |
| 211 | "--output", |
| 212 | type=str, |
| 213 | help="Path to write the workload.yml, - for stdout", |
| 214 | default=f"workload_{datetime.now(timezone.utc).strftime('%Y-%m-%dT%H-%M-%S')}.yml", |
| 215 | ) |
| 216 | parser.add_argument( |
| 217 | "--time", |
| 218 | type=int, |
| 219 | help="How long of a query/data ingestion history to capture, in seconds", |
| 220 | default=360, |
| 221 | ) |
| 222 | # Currently too slow to always enable, not used yet. |
| 223 | parser.add_argument("--avg-column-size", action=argparse.BooleanOptionalAction) |
| 224 | parser.add_argument("-v", "--verbose", action=argparse.BooleanOptionalAction) |
| 225 | |
| 226 | args = parser.parse_args() |
| 227 | |
| 228 | global VERBOSE |
| 229 | VERBOSE = args.verbose |
| 230 | |
| 231 | conn = psycopg.connect(args.mz_url) |
| 232 | conn.autocommit = True |
| 233 | with conn.cursor() as cur: |
| 234 | cur.execute(SQL("SET CLUSTER = {}").format(Identifier(args.cluster))) |
| 235 | |
| 236 | workload = { |
| 237 | "databases": {}, |
| 238 | "clusters": {}, |
| 239 | "queries": [], |
| 240 | "mz_workload_version": "1.0.0", |
| 241 | } |
| 242 | |
| 243 | with timed("Fetching clusters"): |
| 244 | for cluster, managed in query( |
| 245 | conn, "SELECT name, managed FROM mz_clusters WHERE id LIKE 'u%'" |
| 246 | ): |
| 247 | workload["clusters"][cluster] = {"managed": managed} |
| 248 | if managed: |
| 249 | workload["clusters"][cluster]["create_sql"] = query( |
| 250 | conn, |
| 251 | SQL("SELECT create_sql FROM (SHOW CREATE CLUSTER {})").format( |
| 252 | Identifier(cluster) |
| 253 | ), |
| 254 | )[0][0] |
| 255 | |
| 256 | with timed("Fetching databases"): |
no test coverage detected