Skip to content

Monitor Utility and Tests#47

Closed
JohnBrennan95 wants to merge 7 commits intomasterfrom
monitor-stress-utility
Closed

Monitor Utility and Tests#47
JohnBrennan95 wants to merge 7 commits intomasterfrom
monitor-stress-utility

Conversation

@JohnBrennan95
Copy link
Collaborator

Addresses issue #29.

Tests are working locally and inside a Docker container using pytest with a mocked DynamoDB environment. Monitor creation and deletion are functioning as expected. Next steps will need to focus on integration testing against real AWS resources and ensuring attributes match the assigned architecture.

@JohnBrennan95 JohnBrennan95 self-assigned this Jan 10, 2026
@JohnBrennan95 JohnBrennan95 added the enhancement New feature or request label Jan 10, 2026
@codecov
Copy link

codecov bot commented Jan 10, 2026

Codecov Report

❌ Patch coverage is 49.15254% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.22%. Comparing base (7551e02) to head (27a122d).

Files with missing lines Patch % Lines
src/critic/monitor_utility.py 30.76% 18 Missing ⚠️
src/critic/app.py 66.66% 10 Missing ⚠️
src/critic/cli.py 33.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #47      +/-   ##
==========================================
- Coverage   83.87%   81.22%   -2.65%     
==========================================
  Files           9       10       +1     
  Lines         186      245      +59     
  Branches       14       17       +3     
==========================================
+ Hits          156      199      +43     
- Misses         26       41      +15     
- Partials        4        5       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Owner

@calebsyring calebsyring left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requested some changes.

A few of them will depend on a PR I should get out shortly.

with t.batch_writer() as bw:
for i in range(1, count + 1):
slug = f'{prefix}-{i:04d}'
bw.put_item(Item={'project_id': project_id, 'slug': slug})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Part of the point of this is to have operational monitors. So that we can actually run checks at scale.

These at least need a url (you can use google.com or something if you want) and probably some other fields. Maybe just make sure that your fake data passes the model validation.

@app.route('/monitors/create')
def create_monitors_route():
# SImple start to get monitor going
table_name = os.environ.get('MONITOR_TABLE_NAME', 'Critic-Monitors')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right that table names probably need to be defined via environment variables.

I'll take care of that in a pr I'm working on.

project_id=project_id,
prefix=prefix,
count=count,
ddb=None, # Uses a boto3 ddb resource
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll also have a universal ddb instance that can be accessed instead of passing it through all the time.

raise RuntimeError('Deliberate runtime error')


@app.route('/monitors/create')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be CLI commands and not routes. These are open to the public and anyone could hit them. It's also a somewhat clunky UX to have to go that url for your lambda instead of just calling it via CLI.

There's a example here in mu for exposing CLI commands: https://github.com/level12/mu/blob/master/examples/mu_hello/mu_hello.py

TABLE_NAME = 'UptimeMonitor'


def _create_test_table():
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't need this because of

create_tables()

Wait to fix until I get my PR out and you rebase. It'll be easier to use.

# Create 10 monitors
created = create_monitors(
table_name=TABLE_NAME,
project_id=project_id,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this assumes the existence of a project.

We'll need some way to create a project. Maybe you're just planning on that being done in the console manually?

@JohnBrennan95 JohnBrennan95 force-pushed the monitor-stress-utility branch from 7c53137 to 1461832 Compare January 16, 2026 23:49
@@ -1,2 +1,10 @@
from critic.app import cli
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this file is to have cli stuff in here. See https://github.com/level12/coppy/blob/main/src/coppy/cli.py

We should be able to just import it for the ActionHandler as needed.

with t.batch_writer() as bw:
for i in range(1, count + 1):
slug = f'{prefix}-{i:04d}'
bw.put_item(Item=_monitor_item(project_id=project_id, slug=slug))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the put method on the table. Should vastly simplify this file. The batch writer isn't that important here AFAIK

@@ -0,0 +1,80 @@
import boto3
from boto3.dynamodb.conditions import Key
from moto import mock_aws
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't need this. AWS should be mocked automatically for any test not marked an integration test.

from critic.tables import UptimeMonitorTable


def _create_test_table(ddb):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't need to create tables... If you have to, something is wrong with moto_for_unit_tests

calebsyring and others added 5 commits January 25, 2026 13:42
…s. No more manual monitor creations within the tests. Added new fixtures and conftest files to assist with testing, may not be needed but helped validate functionality.
@calebsyring
Copy link
Owner

Closing in favor of #59

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants