Skip to content

Commit

Permalink
Adds debug console cli command
Browse files Browse the repository at this point in the history
Why are these changes being introduced:

* tim_os will never have all of the features of the opensearch client
  library
* accessing opensearch in aws is a pain due to the v4 signing without
  using a client

How does this address that need:

* Create a CLI option that drops you into a debugger with a client
  preconfigured for your connection

Document any side effects to this change:

* this loads the pdb debugger into production code which is not ideal
  • Loading branch information
JPrevost committed Feb 17, 2023
1 parent 7b9826e commit f88e69f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tim/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,20 @@ def bulk_delete(
results["deleted"],
results["total"],
)


@main.command()
@click.pass_context
def console(ctx: click.Context) -> None:
"""Open a debug console where you can run arbitrary commands.
You will have a `client` and can run commands such as dir(client) to
understand what methods are available. Another example is to list all
shards via `client.cat.shards('all-current')`.
This is meant for interactive development and debugging work, not as a
replacement for building out essential tim_os features.
"""
client = ctx.obj["CLIENT"]
click.echo("Entering debug console. Exit by typing `c` then `enter`")
tim_os.console(client)
16 changes: 16 additions & 0 deletions tim/opensearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,3 +407,19 @@ def bulk_index(
)
logger.debug(response)
return result

# Debug Console functions


def console(client: OpenSearch) -> None:
"""Open a debug console where you can run arbitrary commands.
This is useful as tim_os handles the aws connection information to simplify
the process of credentialling in the event we need to use features not yet
built into tim_os.
"""
logger.debug("Entering debug mode with client '%s'", client)

import pdb

pdb.set_trace()

0 comments on commit f88e69f

Please sign in to comment.