Skip to content

Commit aec958b

Browse files
authored
App Canary: always display app description (#199)
* Implement posit-sdk * Provide better formatted instructions, and display the CANARY_GUIDS as text * Always display app description * When available use the content_url to monitor the app * Update .gitignore
1 parent 6e50acb commit aec958b

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

extensions/app-canary/.gitignore

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1+
# Quarto
12
/.quarto/
23
*.quarto_ipynb
3-
44
/_*.local
5-
65
app-canary.html
7-
86
/email-preview
9-
107
.output_metadata.json
11-
128
preview.html
9+
*.quarto_ipynb
1310

11+
# Local dev
1412
/.posit/
15-
1613
.envrc
14+
.python-version

extensions/app-canary/app-canary.qmd

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ gt_tbl = None
2727
connect_server = os.environ.get("CONNECT_SERVER", "")
2828
if not connect_server:
2929
show_instructions = True
30-
instructions.append("Please set the CONNECT_SERVER environment variable.")
30+
instructions.append("Please set the <b>CONNECT_SERVER</b> environment variable.")
3131
3232
# Read CONNECT_API_KEY from environment, this is automatically configured on Connect, set manually for local dev
3333
api_key = os.environ.get("CONNECT_API_KEY", "")
3434
if not api_key:
3535
show_instructions = True
36-
instructions.append("Please set the CONNECT_API_KEY environment variable.")
36+
instructions.append("Please set the <b>CONNECT_API_KEY</b> environment variable.")
3737
3838
# Read CANARY_GUIDS from environment, needs to be manually configured on Connect and for local dev
3939
canary_guids_str = os.environ.get("CANARY_GUIDS", "")
4040
if not canary_guids_str:
4141
show_instructions = True
42-
instructions.append("Please set the CANARY_GUIDS environment variable. It should be a comma separated list of GUID you wish to monitor.")
42+
instructions.append("Please set the <b>CANARY_GUIDS</b> environment variable. It should be a comma separated list of GUID you wish to monitor.")
4343
canary_guids = []
4444
else:
4545
# Clean up the GUIDs
@@ -120,13 +120,15 @@ if not show_instructions:
120120
def validate_app(guid):
121121
# Get app details
122122
content = get_content(guid)
123+
123124
app_name = content.get("title", "")
124125
# Title is optional, if not set use name
125126
if not app_name:
126127
app_name = content.get("name", "")
127128
128129
# Ensure we have a valid URL
129130
dashboard_url = content.get("dashboard_url", "")
131+
content_url = content.get("content_url", "")
130132
content_guid = content.get("guid", guid) # Use the passed guid if not in content
131133
132134
# Initialize default owner information
@@ -158,7 +160,12 @@ if not show_instructions:
158160
logs_url = ""
159161
160162
try:
161-
app_url = f"{connect_server}/content/{guid}"
163+
# Use the content_url if available, otherwise construct one so we get a proper status code
164+
if content_url:
165+
app_url = content_url
166+
else:
167+
# Likely hit error condition in get_content() thus no content_url available
168+
app_url = f"{connect_server}/content/{guid}"
162169
app_response = requests.get(
163170
app_url,
164171
headers=headers,
@@ -212,7 +219,12 @@ if not show_instructions:
212219
#| echo: false
213220
#| label: display
214221
215-
# Create a table with basic styling
222+
about = """<div style="margin-bottom: 10px;">
223+
This report uses the publisher's API key to monitor a list of application GUIDs, verifies each of the monitored apps are
224+
reachable at their content URL, and reports the results. If run on a schedule, reports will be emailed when any monitored
225+
application reports a failure.
226+
</div>"""
227+
216228
if not show_instructions and not df.empty:
217229
218230
# Format the canary_guids as a string for display
@@ -221,11 +233,13 @@ if not show_instructions and not df.empty:
221233
# Use HTML to create a callout box
222234
display(HTML(f"""
223235
<div style="border: 1px solid #ccc; border-radius: 8px; padding: 10px; margin-bottom: 15px; background-color: #f8f9fa;">
224-
<div style="margin-top: 0; padding-bottom: 8px; border-bottom: 1px solid #eaecef; font-weight: bold; font-size: 1.2em;">Monitored GUIDs</div>
236+
<div style="margin-top: 0; padding-bottom: 8px; border-bottom: 1px solid #eaecef; font-weight: bold; font-size: 1.2em;">App Canary Monitor</div>
237+
<div style="padding: 5px 0;">{about}</div>
238+
<div style="margin-top: 10px; padding-top: 8px; border-top: 1px solid #eaecef; font-weight: bold;">Monitored GUIDs:</div>
225239
<div style="padding: 5px 0;">{canary_guids_str}</div>
226240
</div>
227241
"""))
228-
242+
229243
# First create links for name and guid columns
230244
df_display = df.copy()
231245
@@ -315,7 +329,8 @@ if not show_instructions and not df.empty:
315329
316330
elif show_instructions:
317331
# Create a callout box for instructions
318-
instructions_html = ""
332+
instructions_html = about # Start with the about message
333+
319334
for instruction in instructions:
320335
instructions_html += f"<div style='margin-bottom: 10px;'>{instruction}</div>"
321336

0 commit comments

Comments
 (0)