Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Commit

Permalink
feat: Add activity columns to list_debuggees. (#94)
Browse files Browse the repository at this point in the history
This is in further support of #76
  • Loading branch information
jasonborg authored Dec 19, 2022
1 parent 6926d2e commit d99f0ba
Show file tree
Hide file tree
Showing 25 changed files with 377 additions and 207 deletions.
39 changes: 19 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -501,20 +501,19 @@ on a debuggee will be installed on all running instances of it.
Run the following command
```
snapshot-dbg-cli list_debuggees
snapshot-dbg-cli list_debuggees --include-inactive
```
The output resembles the following:
```
Name ID Description
------------- ---------- ----------------------------------------
test-app - v1 d-24abc4f1 node index.js module:test-app version:v1
test-app - v2 d-8dd7f149 node index.js module:test-app version:v2
Name ID Description Last Active Status
------------- ---------- ---------------------------------------- -------------------- --------
test-app - v2 d-8dd7f149 node index.js module:test-app version:v2 2022-12-16T21:45:07Z ACTIVE
test-app - v1 d-24abc4f1 node index.js module:test-app version:v1 2022-10-16T21:45:07Z INACTIVE
```
### Set Snapshots
Snapshots capture local variables and the call stack at a specific line location
Expand Down Expand Up @@ -636,12 +635,12 @@ Where:
The output resembles the following:
```
Status Location Condition CompletedTime ID
--------- ----------- ----------- --------------------------- ------------
ACTIVE index.js:21 b-1648008775
ACTIVE index.js:21 b-1648044994
ACTIVE index.js:21 b-1648045010
COMPLETED index.js:21 2022-03-23T02:52:23.558000Z b-1648003845
Status Location Condition CompletedTime ID
--------- ----------- ----------- -------------------- ------------
ACTIVE index.js:21 b-1648008775
ACTIVE index.js:21 b-1648044994
ACTIVE index.js:21 b-1648045010
COMPLETED index.js:21 2022-03-23T02:52:23Z b-1648003845
```
### Get snapshot
Expand All @@ -667,8 +666,8 @@ Location: index.js:30
Condition: No condition set.
Expressions: No expressions set.
Status: Complete
Create Time: 2022-05-13T14:14:01.444000Z
Final Time: 2022-05-13T14:14:02.516000Z
Create Time: 2022-05-13T14:14:01Z
Final Time: 2022-05-13T14:14:02Z

-------------------------------------------------------------------------------
| Evaluated Expressions
Expand Down Expand Up @@ -802,8 +801,8 @@ Log Message Format: a == 3
Location: Main.java:23
Condition: No condition set
Status: EXPIRED
Create Time: 2022-08-19T18:14:38.240000Z
Final Time: 2022-08-20T18:14:39.618000Z
Create Time: 2022-08-19T18:14:38Z
Final Time: 2022-08-20T18:14:39Z
User Email: [email protected]
```
Expand All @@ -825,10 +824,10 @@ The output resembles the following:
```
This command will delete the following debuggees:

Name ID Last Active Status
------------------------- ---------- --------------------------- ------
default - 20221125t224954 d-39f7082e 2022-12-05T03:13:42.166000Z STALE
default - 20221125t154414 d-dba89292 2022-12-04T03:02:48.780000Z STALE
Name ID Last Active Status
------------------------- ---------- -------------------- ------
default - 20221125t224954 d-39f7082e 2022-12-05T03:13:42Z STALE
default - 20221125t154414 d-dba89292 2022-12-04T03:02:48Z STALE



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ The output will resemble the following. The first column will contain an entry
`<service> - <version>`, which in this case is `default - 20221125t224954`.

```
Name ID Description
-------------------------- ---------- ------------------------------------------------
default - 20221125t224954 d-62259477 my-project-id-20221125t224954-448130606220701265
Name ID Description Last Active Status
------------------------- ---------- ------------------------------------------------ -------------------- ------
default - 20221125t224954 d-62259477 my-project-id-20221125t224954-448130606220701265 2022-11-25T22:50:00Z ACTIVE
```

The debuggee ID in this case is `d-62259477`. Using this ID you may now run
Expand Down
6 changes: 3 additions & 3 deletions samples/java/appengine-flexible/helloworld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ The output will resemble the following. The first column will contain an entry
`<service> - <version>`, which in this case is `default - 20221125t154414`.

```
Name ID Description
-------------------------- ---------- ------------------------------------------------
default - 20221125t154414 d-85ad2c65 my-project-id-20221125t154414-448123750866017122
Name ID Description Last Active Status
-------------------------- --------- ------------------------------------------------ -------------------- ------
default - 20221125t154414 d-85ad2c65 my-project-id-20221125t154414-448123750866017122 2022-11-25T15:45:00Z ACTIVE
```

The debuggee ID in this case is `d-85ad2c65`. Using this ID you may now run
Expand Down
6 changes: 3 additions & 3 deletions samples/java/appengine-java11/helloworld-servlet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ The output will resemble the following. The first column will contain an entry
`<service> - <version>`, which in this case is `default - 20221122t182924`.

```
Name ID Description
------------------------- ---------- ------------------------------------------------
default - 20221122t182924 d-7f891f30 my-project-id-20221122t182924-448056845967981019
Name ID Description Last Active Status
------------------------- ---------- ------------------------------------------------ -------------------- ------
default - 20221122t182924 d-7f891f30 my-project-id-20221122t182924-448056845967981019 2022-11-22T18:30:00Z ACTIVE
```

The debuggee ID in this case is `d-7f891f30`. Using this ID you may now run
Expand Down
6 changes: 3 additions & 3 deletions samples/java/appengine-java11/simple-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ The output will resemble the following. The first column will contain an entry
`<service> - <version>`, which in this case is `default - 20221117t213436`.

```
Name ID Description
-------------------------- ---------- ------------------------------------------------
default - 20221122t161333 d-ad4829f7 my-project-id-20221122t161333-448054658875855015
Name ID Description Last Active Status
------------------------- ---------- ------------------------------------------------ -------------------- ------
default - 20221122t161333 d-ad4829f7 my-project-id-20221122t161333-448054658875855015 2022-11-22T16:14:00Z ACTIVE
```

The debuggee ID in this case is `d-ad4829f7`. Using this ID you may now run
Expand Down
6 changes: 3 additions & 3 deletions samples/node-js/appengine-flexible/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ The output will resemble the following. The first column will contain an entry
`<service> - <version>`, which in this case is `default - 20221117t213436`.

```
Name ID Description
-------------------------- ---------- ------------------------------------------------
default - 20221122t161333 d-ad4829f7 node app.js version:20221122t161333
Name ID Description Last Active Status
------------------------- ---------- ----------------------------------- -------------------- ------
default - 20221122t161333 d-ad4829f7 node app.js version:20221122t161333 2022-11-22T16:15:00Z ACTIVE
```

The debuggee ID in this case is `d-ad4829f7`. Using this ID you may now run
Expand Down
6 changes: 3 additions & 3 deletions samples/node-js/appengine-standard/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ The output will resemble the following. The first column will contain an entry
`<service> - <version>`, which in this case is `default - 20221117t213436`.

```
Name ID Description
-------------------------- ---------- ------------------------------------------------
default - 20221122t161333 d-ad4829f7 node app.js version:20221122t161333
Name ID Description Last Active Status
------------------------- ---------- ----------------------------------- -------------------- ------
default - 20221122t161333 d-ad4829f7 node app.js version:20221122t161333 2022-11-22T16:15:00Z ACTIVE
```

The debuggee ID in this case is `d-ad4829f7`. Using this ID you may now run
Expand Down
13 changes: 13 additions & 0 deletions snapshot_dbg_cli/debuggee_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ def set_converted_timestamps(debuggee):
debuggee, field_mappings)


def get_debuggee_status(debuggee):
if not debuggee['activeDebuggeeEnabled']:
return 'UNKNOWN'

if debuggee['isActive']:
return 'ACTIVE'

if not debuggee['isStale']:
return 'INACTIVE'

return 'STALE'


def normalize_debuggee(debuggee, current_time_unix_msec):
"""Validates and normalizes a debuggee.
Expand Down
18 changes: 3 additions & 15 deletions snapshot_dbg_cli/delete_debuggees_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""

from snapshot_dbg_cli.exceptions import SilentlyExitError
from snapshot_dbg_cli.debuggee_utils import get_debuggee_status
from snapshot_dbg_cli.debuggee_utils import sort_debuggees
from snapshot_dbg_cli.time_utils import get_current_time_unix_msec

Expand Down Expand Up @@ -50,8 +51,6 @@

QUIET_HELP = 'If set, suppresses user confirmation of the command.'

SUMMARY_HEADERS = ['Name', 'ID', 'Last Active', 'Status']

DELETE_ABORTED_QUIET_NOT_ALLOWED_MSG = """
Delete aborted. Run the command again without the --quiet option specified, it
cannot be used due to the unknown status of one or more debuggees.
Expand All @@ -63,6 +62,8 @@
future install the latest available version of the agent.
"""

SUMMARY_HEADERS = ['Name', 'ID', 'Last Active', 'Status']


def transform_to_debuggee_summary(debuggee):
# Match the fields from SUMMARY_HEADERS
Expand All @@ -74,19 +75,6 @@ def transform_to_debuggee_summary(debuggee):
]


def get_debuggee_status(debuggee):
if not debuggee['activeDebuggeeEnabled']:
return 'UNKNOWN'

if debuggee['isActive']:
return 'ACTIVE'

if not debuggee['isStale']:
return 'INACTIVE'

return 'STALE'


def should_delete_debuggee_check(debuggee, args):
if args.include_all:
return True
Expand Down
24 changes: 18 additions & 6 deletions snapshot_dbg_cli/list_debuggees_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
(debuggees) registered with the Snapshot Debugger.
"""

from snapshot_dbg_cli.debuggee_utils import get_debuggee_status
from snapshot_dbg_cli.debuggee_utils import sort_debuggees
from snapshot_dbg_cli.time_utils import get_current_time_unix_msec

Expand All @@ -30,6 +31,21 @@

INCLUDE_INACTIVE_HELP = 'Include inactive debuggees.'

SUMMARY_HEADERS = headers = [
'Name', 'ID', 'Description', 'Last Active', 'Status'
]


def transform_to_debuggee_summary(debuggee):
# Match the fields from SUMMARY_HEADERS
return [
debuggee['displayName'],
debuggee['id'],
debuggee['description'],
debuggee['lastUpdateTime'],
get_debuggee_status(debuggee),
]


class ListDebuggeesCommand:
"""This class implements the list_debuggees command.
Expand Down Expand Up @@ -72,9 +88,5 @@ def cmd(self, args, cli_services):
if args.format.is_a_json_value():
user_output.json_format(debuggees, pretty=args.format.is_pretty_json())
else:
headers = ['Name', 'ID', 'Description']

values = [[d['displayName'], d['id'], d['description']] for d in debuggees
]

user_output.tabular(headers, values)
values = list(map(transform_to_debuggee_summary, debuggees))
user_output.tabular(SUMMARY_HEADERS, values)
9 changes: 4 additions & 5 deletions snapshot_dbg_cli/time_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ def convert_unix_msec_to_rfc3339(unix_msec):
unix_msec: The Unix timestamp, represented in milliseconds since the epoch.
Returns:
An RFC3339 encoded timestamp string in format: "%Y-%m-%dT%H:%M:%S.%fZ".
An RFC3339 encoded timestamp string in format: "%Y-%m-%dT%H:%M:%SZ".
"""
try:
seconds = unix_msec / 1000
msec = unix_msec % 1000
timestamp = seconds
dt = datetime.datetime.fromtimestamp(timestamp, tz=datetime.timezone.utc)
return dt.strftime(f'%Y-%m-%dT%H:%M:%S.{msec:03}000') + 'Z'
return dt.strftime('%Y-%m-%dT%H:%M:%S') + 'Z'
except (OverflowError, OSError, TypeError, ValueError):
# By using 0, we'll still get the expected formatted string, and the value
# will be '1970-01-01...', which visually will be recognizable as beginning
Expand All @@ -65,9 +64,9 @@ def set_converted_timestamps(data, field_mappings):
set_converted_timestamps(data, field_mappings)
data = {
fooTimeUnixMsec: 1649962215000
fooTime: '2022-04-14T18:50:15.000000Z'
fooTime: '2022-04-14T18:50:15Z'
barTimeUnixMsec = 1649962216000
barTime: '2022-04-14T18:50:16.000000Z'
barTime: '2022-04-14T18:50:16Z'
}
Expand Down
32 changes: 16 additions & 16 deletions snapshot_dbg_cli_tests/test_breakpoint_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
'isFinalState': False,
'location': {'line': 26, 'path': 'index.js'},
'userEmail': '[email protected]',
'createTime': '2022-04-14T18:50:15.426000Z',
'createTime': '2022-04-14T18:50:15Z',
} # yapf: disable (Subjectively, more readable hand formatted)

SNAPSHOT_COMPLETE = {
Expand All @@ -43,8 +43,8 @@
'isFinalState': True,
'location': {'line': 26, 'path': 'index.js'},
'userEmail': '[email protected]',
'createTime': '2022-04-14T18:50:15.426000Z',
'finalTime': '2022-04-14T18:50:30.637000Z',
'createTime': '2022-04-14T18:50:15Z',
'finalTime': '2022-04-14T18:50:30Z',
} # yapf: disable (Subjectively, more readable hand formatted)

class SnapshotDebuggerBreakpointUtilsTests(unittest.TestCase):
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_set_converted_timestamps(self):
},
{
'createTimeUnixMsec': 1649962215000,
'createTime': '2022-04-14T18:50:15.000000Z'
'createTime': '2022-04-14T18:50:15Z'
},
),
(
Expand All @@ -141,7 +141,7 @@ def test_set_converted_timestamps(self):
},
{
'finalTimeUnixMsec': 1649962215000,
'finalTime': '2022-04-14T18:50:15.000000Z'
'finalTime': '2022-04-14T18:50:15Z'
},
),
(
Expand All @@ -163,9 +163,9 @@ def test_set_converted_timestamps(self):
},
{
'createTimeUnixMsec': 1649962215000,
'createTime': '2022-04-14T18:50:15.000000Z',
'createTime': '2022-04-14T18:50:15Z',
'finalTimeUnixMsec': 1649962215001,
'finalTime': '2022-04-14T18:50:15.001000Z'
'finalTime': '2022-04-14T18:50:15Z'
},
),
]
Expand Down Expand Up @@ -363,7 +363,7 @@ def test_logpoint_get_short_status_active(self):
'isFinalState': False,
'location': {'line': 26, 'path': 'index.js'},
'userEmail': '[email protected]',
'createTime': '2022-04-14T18:50:15.852000Z',
'createTime': '2022-04-14T18:50:15Z',
} # yapf: disable (Subjectively, more readable hand formatted)

self.assertEqual(get_logpoint_short_status(logpoint), 'ACTIVE')
Expand All @@ -386,8 +386,8 @@ def test_logpoint_get_short_status_complete(self):
'isFinalState': True,
'location': {'line': 27, 'path': 'index.js'},
'userEmail': '[email protected]',
'createTime': '2022-04-14T18:50:16.852000Z',
'finalTime': '2022-04-14T18:50:31.274000Z',
'createTime': '2022-04-14T18:50:16Z',
'finalTime': '2022-04-14T18:50:31Z',
} # yapf: disable (Subjectively, more readable hand formatted)

self.assertEqual(get_logpoint_short_status(logpoint), 'COMPLETED')
Expand All @@ -404,8 +404,8 @@ def test_logpoint_get_short_status_expired(self):
'isFinalState': True,
'location': {'line': 28, 'path': 'index.js'},
'userEmail': '[email protected]',
'createTime': '2022-04-14T18:50:17.852000Z',
'finalTime': '2022-04-14T18:50:31.274000Z',
'createTime': '2022-04-14T18:50:17Z',
'finalTime': '2022-04-14T18:50:31Z',
'status': {
'description': {
'format': 'The logpoint has expired'
Expand All @@ -430,8 +430,8 @@ def test_logpoint_get_short_status_failed(self):
'isFinalState': True,
'location': {'line': 29, 'path': 'index.js'},
'userEmail': '[email protected]',
'createTime': '2022-04-14T18:50:18.852000Z',
'finalTime': '2022-04-14T18:50:31.274000Z',
'createTime': '2022-04-14T18:50:18Z',
'finalTime': '2022-04-14T18:50:31Z',
'status': {
'description': {
'format': 'No code found at line 29'
Expand All @@ -458,8 +458,8 @@ def test_logpoint_get_short_status_data_incomplete(self):
'isFinalState': True,
'location': {'line': 29, 'path': 'index.js'},
'userEmail': '[email protected]',
'createTime': '2022-04-14T18:50:18.852000Z',
'finalTime': '2022-04-14T18:50:31.274000Z',
'createTime': '2022-04-14T18:50:18Z',
'finalTime': '2022-04-14T18:50:31Z',
'status': {
'description': {
'format': 'No code found at line 29'
Expand Down
Loading

0 comments on commit d99f0ba

Please sign in to comment.