Commit graph

1,133 commits

Author SHA1 Message Date
Anthony Alaribe
2b9fc97683 Fix drawer causing white page background
Override --page-scroll-bg-on to use --color-bgBase so the drawer
toggle doesn't override the page background with DaisyUI's default.
2026-01-08 00:46:24 +01:00
Anthony Alaribe
7bd351203a
Add widget-integrated alerts feature (#272)
* Add widget-integrated alerts feature

Enable creating and managing alerts directly from dashboard widget details:
- Add widget_id, dashboard_id, and recovery threshold columns to query_monitors
- Add Alerts tab to widget expand view with full configuration form
- Render threshold marklines on charts (configurable: always/on_breach/never)
- Show alert status indicator on widget headers (bell icon with colors)
- Add source column to Alerts page showing Widget vs Log Explorer origin
- Sync widget query changes to linked alerts automatically
- Delete alerts when widgets are removed from dashboards
- Support recovery thresholds (hysteresis) to prevent alert flapping
- Populate widget alert status at render time for real-time indicators

* Auto-format code with fourmolu

* Fix widget alerts: clone on duplicate, sync queries, persist status

- Clone alerts when duplicating widgets with new alert ID tied to new widget
- Sync widget query changes to associated alert's logQuery and logQueryAsSql
- Prevent direct query modification for widget-tied alerts
- Add current_status column to track alert state (migration 0026)
- Extract normalizeWidgetId, alertActiveWindow, mkMarkLine helpers
- Use stored current_status in getWidgetAlertStatuses instead of computing

* Auto-format code with fourmolu

* Fix widget alerts: add missing current_status field and lowercase status values

- Add current_status to SQL queries in getAlertsByTeamHandle, getActiveQueryMonitors,
  queryMonitorByWidgetId, queryMonitorsByDashboardId
- Fix case sensitivity: use lowercase status values to match SQL constraint
- Remove redundant pass statement, simplify wasAlerting/wasWarning with helper

* Cache current_value to avoid eval() on every dashboard load

- Add current_value column to query_monitors table
- Store evaluated value during background job instead of computing on read
- Replace eval(log_query_as_sql) with cached current_value in getWidgetAlertStatuses
- Remove unnecessary null guard from deleteMonitorsByWidgetIds
- Use foldMap for statusMap construction

* Simplify monitor status logic and extract updateTabBySlug helper

- Refactor monitorStatus to use breached/recovered predicates instead of
  duplicated comparison logic for triggerLessThan
- Use currentStatus field directly instead of time-based alerting checks
- Extract updateTabBySlug helper in Dashboards to reduce code duplication

* Auto-format code with fourmolu

* Consolidate widget alert migrations into single file

* Move showThresholdLines from monitor to widget configuration

showThresholdLines is a display setting that belongs in the widget JSON,
not the monitor database table. This change:
- Removes show_threshold_lines column from query_monitors table
- Updates widgetAlertUpsertH to save showThresholdLines to the widget
- Widget already has this field in its JSON schema

* Use DOUBLE PRECISION for threshold and metric values

Support decimal values (e.g., 0.5, 32.5°C) in monitor thresholds:
- Migration: Convert alert_threshold, warning_threshold to DOUBLE PRECISION
- Migration: New columns use DOUBLE PRECISION (recovery thresholds, current_value)
- Haskell: Update all threshold/value fields from Int to Double
- Remove fromIntegral conversions in BackgroundJobs

* Code cleanup: simplify BackgroundJobs and add NOT NULL constraints

- Simplify sum/map to list comprehension: sum [v | Only v <- results]
- Inline wasAlerting/wasWarning in monitorStatus call
- Use void consistently instead of _ <- pattern
- Simplify breached/recovered predicates in monitorStatus
- Use && instead of , in guards for clarity
- Add NOT NULL to current_status and current_value columns

* Auto-format code with fourmolu

* Fix: remove stale show_threshold_lines from SELECT queries

* Fix: rename 'first' variable to avoid shadowing Bifunctor.first

* Refactor: use _select from pg-entity instead of manual column lists

* Refactor: address code review feedback for alerts-in-widgets

- Add MonitorStatus ADT (MSNormal/MSWarning/MSAlerting) replacing string literals
- Simplify applyAlertStatus using fromMaybe/do pattern
- Add warning log when widget alert query parsing fails
- Fix race condition by deleting monitors before dashboard update
- Normalize widgetId once at function entry in dashboardWidgetPutH

* Auto-format code with fourmolu

* Fix: format threshold values with thousand separators

* Refactor: extract formatWithCommas to Utils.hs

* Refactor: extract shared alert UI helpers to Pages/Monitors.hs

- Add thresholdInput_, recoveryInput_, directionSelect_, frequencySelect_, collapsibleSection_
- Update Dashboards.hs widgetAlertConfig_ to use shared helpers
- Update Log.hs alertConfigurationForm_ to use shared helpers
- Net reduction of ~37 lines through DRY refactoring

* Auto-format code with fourmolu

* Style: use surface-raised for alert form in Log.hs

* Add integration tests and doctests for alert monitoring

- Add doctests to monitorStatus for hysteresis logic validation
- Add widget alert cascade deletion test
- Add widget alert query sync test
- Add monitor with recovery thresholds integration test
- Export checkTriggeredQueryMonitors and monitorStatus from BackgroundJobs
- Fix missing AlertUpsertForm fields in MonitorsSpec

* Refactor: extract functions and fix hlint warnings

- Extract syncWidgetAlert, normalizeWidget, updateDashboardWidgets from dashboardWidgetPutH
- Extract evaluateQueryMonitor with error handling for SQL failures
- Fix hlint warnings: use toText, one, and function composition

* Auto-format code with fourmolu

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-07 18:13:18 +01:00
Anthony Alaribe
5f95c341dc Fix Tagify dropdown hover styles and positioning
- Add !important to hover/active styles to override library defaults
- Change dropdown position from 'text' to 'input' for proper alignment
- Consolidate hover and active selectors
2026-01-06 23:58:56 +01:00
Anthony Alaribe
e6b4af2a66 Refactor Tagify initialization and add dropdown styling
- Use createTagify helper instead of inline Tagify instantiation
- Add CSS styles for Tagify dropdown with dark mode support
2026-01-06 23:54:49 +01:00
Anthony Alaribe
7fe1dce991
System logs support. IE logs about actions monoscope performs onbehalf of the user (#270)
* system logs

* Auto-format code with fourmolu

* Simplify SystemLogs to use existing SeverityLevel type

Remove redundant SystemLogSeverity type and use SeverityLevel
(SLInfo, SLWarn, SLError) from Telemetry module directly.

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-06 21:20:56 +01:00
Anthony Alaribe
fdd5682a5a Fix log-list column header dropdowns
- Fix chevron-down SVG icon color in dark mode by using fill instead of stroke
- Replace tabindex-based dropdown with popover API to fix click-through bug
- Add cursor-pointer to dropdown trigger button

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-01-06 20:32:38 +01:00
Anthony Alaribe
e68776ccb6
Use htmx for dashboard widget reorders and new widgets (#268)
* Add tab-aware widget management with HTMX reordering

- Add tab slug parameter to widget put/reorder endpoints for tabbed dashboards
- Replace JS fetch with HTMX trigger for widget order updates
- Move response-targets HTMX extension from CDN to local assets
- Remove updateWidgetOrder JS function (now handled via HTMX)

* Auto-format code with fourmolu

* Add GitHub icon to SVG sprites

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-05 23:00:30 +01:00
Anthony Alaribe
fe8f0123ed Move highlight.js from CDN to local assets
- Download highlight.js v11.11.1 (CSS + core + 11 language packs) to
  static/public/assets/deps/highlightjs/
- Update Onboarding.hs to use hashAssetFile for cache-busted local files
- Regenerate workbox service worker to precache highlight.js assets
- Update workbox-cli to v7.0.0
2026-01-05 20:08:38 +01:00
Anthony Alaribe
c05de0450d
Implement lazy-loaded tabs with htmx (#264)
* feat(dashboard): implement htmx lazy-loading for dashboard tabs

- Add path-based tab navigation (/p/{pid}/dashboards/{did}/tab/{slug})
- Only process widgets for the active tab (lazy loading)
- Use htmx to fetch tab content dynamically on tab switch
- Update URL in browser when switching tabs (linkable tab URLs)
- Re-initialize GridStack after htmx swaps new tab content
- Active tab indicator updates via hyperscript on htmx:afterOnLoad
- Redirect legacy query-param based URLs to path-based format

* Auto-format code with fourmolu

* feat(dashboard): add active tab name to page breadcrumbs

- Add pageTitleSuffix field to BWConfig for breadcrumb extensions
- Show current tab name in breadcrumbs (Dashboards > Dashboard Title > Tab Name)
- Use htmx out-of-band swap to update breadcrumb when switching tabs
- Breadcrumb updates automatically when navigating between tabs via htmx

* Auto-format code with fourmolu

* feat(dashboard): add ability to rename tabs via breadcrumb click

- Add pageTitleSuffixModalId to BWConfig for tab rename modals
- Make tab name in breadcrumb clickable to open rename modal
- Add TabRenameForm and TabRenameRes types for form handling
- Add dashboardTabRenamePatchH handler to update tab names
- Add tab rename modal to dashboard page
- Redirect to new tab slug URL after rename
- Add "Rename tab" option to context menu dropdown

* refactor(dashboard): extract common processing logic and address code review

- Extract processConstantsAndExtendParams helper to reduce duplication
- Extract mkWidgetProcessor helper for widget processing with dashboard ID
- Add activeTabSlugKey constant to replace magic string "activeTabSlug"
- Fix potential race condition: use requestAnimationFrame instead of setTimeout
- Mark unused dashVM as _dashVM in dashboardTabContentGetH

* Auto-format code with fourmolu

* refactor(dashboard): simplify code and remove redundancy

- Remove redundant tabNameToSlug wrapper, use slugify directly
- Simplify getDefaultTabSlug using fmap and viaNonEmpty
- Extract breadcrumbSuffixOob_ helper for OOB breadcrumb swaps
- Remove unnecessary main widgets processing in dashboardTabGetH
  (tab-based dashboards don't need dash.widgets processed)

* fix(dashboard): remove redundant lambda in mkWidgetProcessor (hlint)

* refactor(dashboard): improve code succinctness per review

- Use point-free style in findTabBySlug
- Simplify processConstantsAndExtendParams with <&>
- Make mkWidgetProcessor point-free with fmap and lens
- Use lens ix for tab name update instead of zipWith
- Extract queryStringFrom helper for query string construction

* fix: resolve type errors and remove SET TRANSACTION warning

- Fix type signatures for processConstantsAndExtendParams and mkWidgetProcessor to use ATAuthCtx
- Fix ambiguous record update using lens syntax
- Make faSprite_ and breadcrumbSuffixOob_ polymorphic for ToHtml instance
- Remove unnecessary SET TRANSACTION READ ONLY that caused warnings

* parallel widget processing in dashboards. and adding consts to the query params

* Auto-format code with fourmolu

* fix(dashboard): add tab loading indicators and fix OOB breadcrumb on initial load

- Add per-tab loading spinner indicators
- Only include OOB breadcrumb swap for HTMX partial loads, not full page loads

* perf(dashboard): optimize tab switching performance

- Replace widget retry loops with widgetDepsReady flag pattern
- Remove duplicate tooltip initialization (afterSwap + afterSettle → afterSettle only)
- Add HTMX view transitions for smoother tab swaps
- Use htmx:afterSettle instead of afterSwap for GridStack init

* fix: address code review feedback

- Add READ ONLY transaction wrapper for user SQL queries (security)
- Fix tab rename to use OOB swap + history.replaceState instead of HX-Redirect

* revert: remove SQL transaction and tab rename changes

* fix: rename children to childWidgets to avoid shadowing lens import

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-03 21:55:15 +01:00
Anthony Alaribe
bf6faa8cd9
Improve anomaly detail page layout and add AI chat (#249)
* Improve anomaly detail page layout and add AI chat

- Move action buttons (acknowledge, archive) to navbar as page actions
- Remove surface-raised from header, add more breathing room
- Update button styles to match navbar patterns (btn-sm)
- Add time stat boxes showing first/last seen with compact formatting
- Add AI chat functionality for investigating anomalies
- Add side-chevron-left icon (without box) for collapse toggle
- Use new icon for trace panel collapse button

* Auto-format code with fourmolu

* Refactor AI chat to use agentic tools and DB-persisted history

- Extend AgenticConfig with conversationId and conversationType fields
- Add runAgenticChatWithHistory for DB-backed conversations
- Refactor Anomalies.hs to use agentic query system (access to 8 tools)
- Add Slack/Discord thread persistence in DB instead of repeated API calls
- Add deterministic UUID5 helpers for thread conversation IDs
- One-time migration pattern: first thread access migrates from external API
- Log Explorer remains stateless for low latency

* Auto-format code with fourmolu

* Fix security issues and improve AI chat persistence

Security fixes:
- Use executeSecuredQuery for dashboard constants/variables SQL
- Add project_id filtering to prevent cross-project data access

AI chat improvements:
- Save user message before AI call for complete history
- Persist assistant response on error and parse failure paths
- Fix race condition in getOrCreateConversation (use listToMaybe)

Code style (CLAUDE.md):
- Remove unnecessary $ before lambdas in Anomalies.hs
- Clean up unused imports in Dashboards.hs

* Auto-format code with fourmolu

* Refactor time display and error handling for cleaner code

- Add abbreviateUnit helper with LambdaCase for cleaner word mapping
- Simplify compactTimeAgo using word-based abbreviation
- Refactor timeStatBox_ to use pattern matching on T.words
- Replace fromMaybe.error with explicit pattern match in getOrCreateConversation

* Auto-format code with fourmolu

* Fix hlint warnings in Anomalies and AI modules

- Replace T.unwords/T.words/T.unlines with Relude equivalents
- Simplify lambdas to operator sections
- Replace pure () with pass

* Optimize AI and anomaly code with better data structures

- Use Map for O(1) time unit abbreviation lookup in Anomalies.hs
- Extract dangerous SQL patterns to top-level constant with additional
  security patterns (copy, execute, explain, set)
- Replace V.toList conversions with pure Vector operations using vIntercalate
- Use V.take instead of take after V.toList for efficiency
- Reorder migration files for correct dependency order

* Auto-format code with fourmolu

* Optimize AI and anomaly code with better data structures

- Use Map for O(1) time unit abbreviation lookup in Anomalies.hs
- Extract dangerous SQL patterns to top-level constant with additional
  security patterns (copy, execute, explain, set)
- Replace V.toList conversions with pure Vector operations using vIntercalate
- Use V.take instead of take after V.toList for efficiency
- Reorder migration files for correct dependency order

* Auto-format code with fourmolu

* Use chunksOf and parseMaybe for cleaner code in Anomalies.hs

- Replace manual groupMessages recursion with chunksOf from extra
- Use parseMaybe from aeson instead of case on fromJSON result

* Fix security and code quality issues

- Fix SQL injection risk: wrap query in transaction with READ ONLY mode,
  add comment markers (--,/*,*/) to dangerous patterns validation
- Replace unsafe error call with safe fromMaybe in getOrCreateConversation
- Extract textToConversationId helper for cleaner UUID V5 generation
- Remove Control.Lens import, use record update syntax instead
- Add manage_updated_at trigger migration for ai_conversations table
- Update parser test expectations to match current output format

* Auto-format code with fourmolu

* Fix bugs and improve code quality in anomaly/issues modules

- Fix race condition in getOrCreateConversation: fail explicitly if
  RETURNING clause doesn't return a row instead of silent fallback
- Replace Map lookup with pattern matching for time unit abbreviation
- Fix V.take order: take before map for better performance
- Make chat history pairing more robust with explicit recursion
- Add doctests for abbreviateUnit function
- Remove obvious comments, keep only meaningful ones
- Add updated_at trigger for ai_conversations table

* Auto-format code with fourmolu

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-03 18:32:18 +01:00
Anthony Alaribe
7b95bf2d53
Restore custom gridstack resize icon lost in v12.4.1 update (#263)
The gridstack library update to v12.4.1 replaced the custom APItoolkit
resize icon (dotted grid pattern) with the default arrow icon. This adds
CSS overrides in tailwind.css to restore:
- Custom dotted grid SVG resize handle (#94A3B8 color)
- Smaller handle size (14x14 vs 20x20)
- Custom placeholder styling with "drop here" text

Co-authored-by: Claude <noreply@anthropic.com>
2026-01-02 15:01:38 +01:00
Anthony Alaribe
3f385043ef
Support more KQL operators and functions (#259)
* Add KQL functions for _overview.yaml SQL migration

Implement P0 and P1 KQL features needed to migrate _overview.yaml dashboard
queries from SQL to KQL:

P0 Features:
- countif(condition): COUNT(*) FILTER (WHERE condition) for error rate calculations
- dcount(field): COUNT(DISTINCT field) for service/resource counts

P1 Features:
- coalesce(field, default): COALESCE for null handling
- strcat(field1, separator, field2): CONCAT for string concatenation
- iff(condition, then, else): CASE WHEN for simple conditionals
- case(cond1, val1, ..., default): Multi-branch CASE for categorization

SQL generation for each function:
- countif(status == "ERROR") → COUNT(*) FILTER (WHERE status = 'ERROR')
- dcount(service_name) → COUNT(DISTINCT service_name)
- coalesce(method, "unknown") → COALESCE(method, 'unknown')
- strcat(method, " ", path) → CONCAT(method, ' ', path)
- iff(x > 0, a, b) → CASE WHEN x > 0 THEN a ELSE b END
- case(x >= 500, e, x >= 400, w, s) → CASE WHEN x >= 500 THEN e WHEN x >= 400 THEN w ELSE s END

Example target KQL for _overview.yaml:
  kind == "server" AND duration != null
  | summarize
      error_rate = countif(status_code == "ERROR") * 100.0 / count(),
      p95_latency = percentile(duration / 1e6, 95)
    by resource.service.name

* Auto-format code with fourmolu

* Refactor KQL parsers to use applicative style

- Add pSimpleAgg helper for common function(subject) pattern
- Convert pCountIf, pCoalesce, pStrcat, pIff to applicative style
- Simplify pCase with inline tuple construction
- Remove redundant pDCount (now handled by pSimpleAgg)
- Net reduction of ~50 lines while maintaining same functionality

* Auto-format code with fourmolu

* Align KQL functions with Microsoft KQL dialect

Update function signatures to match official Microsoft KQL syntax:

- dcount(expr [, accuracy]): Add optional accuracy parameter (0-4)
  for HyperLogLog estimation precision

- coalesce(arg1, arg2, [arg3,...]): Now variadic (2-64 args)
  Returns first non-null expression

- strcat(arg1, arg2, [arg3,...]): Now variadic (1-64 args)
  Concatenates any scalar expressions

- iff(condition, then, else): Now accepts any Values for then/else
  Not limited to just field references

- case(pred1, val1, [pred2, val2, ...] else): Values are now any scalar
  Matches Microsoft KQL multi-branch conditional syntax

Added pScalarExpr helper to parse either literal values or field
references, enabling flexible value parsing in scalar functions.

Sources:
- https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/dcount-aggfunction
- https://learn.microsoft.com/en-us/kusto/query/coalesce-function
- https://learn.microsoft.com/en-us/kusto/query/strcat-function
- https://learn.microsoft.com/en-us/kusto/query/iff-function
- https://learn.microsoft.com/en-us/kusto/query/case-function

* Auto-format code with fourmolu

* Refactor KQL parsers for DRY and fix backtracking

Parser improvements:
- Extract `comma` helper for repeated `string "," *> space` pattern
- Add `pVariadicAgg` helper for variadic functions (coalesce, strcat)
- Convert pDCount to applicative style (7 lines -> 5 lines)
- Simplify pCoalesce and pStrcat to one-liners using pVariadicAgg
- Use `comma` consistently across all parsers

Bug fix:
- Add `try` to Count parser to prevent partial consumption breaking
  backtracking to countif/dcount parsers
- Reorder dcount before count in parser choice list

Code reduction: ~30 lines eliminated while improving consistency

* Auto-format code with fourmolu

* Refactor KQL parser for succinctness and convert percentile queries to KQL

Parser improvements:
- Add withoutAlias helper to eliminate repetitive <*> pure Nothing
- Add commaSep/commaSep1 for cleaner comma-separated parsing
- Refactor pPercentilesMulti/pPercentileSingle to applicative style
- Fix pScalarExpr to use toQText instead of display (preserves KQL notation)
- Extract pCount parser with cleaner parentheses handling
- Use foldMap for CASE WHEN display, simplify Plain display

Dashboard improvements:
- Convert Request Latency Percentiles widget to KQL (was 25 lines SQL)
- Convert Service Latency Percentiles widget to KQL (was 25 lines SQL)
- Both now use: summarize percentiles(duration, 50, 75, 90, 95, 99) by bin_auto(timestamp)

* Auto-format code with fourmolu

* Improve tests with full SQL assertions and fix KQL dot notation

Tests:
- Update countif, dcount, coalesce, strcat, iff, case tests to assert
  full generated SQL queries instead of partial string checks
- Add full SQL assertion for percentiles LATERAL unnest query
- Update where clause combination test with full SQL assertion

Dashboard KQL:
- Fix KQL queries to use "." separator (resource.service.name)
  instead of "___" which is only for raw SQL
- Add order by timestamp desc for proper ordering

* Fix ambiguous 'many' import and apply HLint suggestion

- Hide 'many' from Relude to resolve ambiguity with Text.Megaparsec
- Replace case with maybe in extractPercentilesInfo per HLint

* Refactor KQL parser and add dcount accuracy validation

- Remove redundant commaSep/commaSep1 wrappers, use sepBy directly
- Use ViewPatterns for cleaner extractPercentilesInfo pattern matching
- Add validation for dcount accuracy bounds (0-4 per KQL spec)
- Add comment explaining dcount accuracy is ignored in PostgreSQL
- Add edge case tests for variadic functions, nested calls, field paths

* Fix UnexpectedNull error for hashes field in OtelLogsAndSpans

Use COALESCE(hashes, '{}') in SQL queries to handle NULL values
in the hashes column, preventing PGArray parsing failures.

* Fix UnexpectedNull error for start_time field in OtelLogsAndSpans

Use COALESCE(start_time, timestamp) in SQL queries to handle NULL values
in start_time column. Logs may not have start_time set, falling back to
the main timestamp field.

* Fix field references in coalesce/strcat SQL generation

- Add Field constructor to Values type for unquoted field references
- Update pScalarExpr to use Field for subject references
- Remove catch-all from pValues that was consuming commas
- Add coalesce validation requiring 2+ arguments
- Clean up Stats.hs exports
- Update test expectations for correct SQL output

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-02 15:00:39 +01:00
Anthony Alaribe
a673acf757
Add query-based constants to dashboard configuration (#262)
* feat(dashboards): add query constants for reusable SQL/KQL results

Add dashboard constants feature that allows defining SQL/KQL queries
whose results are executed once and made available to all widgets as
{{const-<key>}} placeholders that expand to subqueries.

This improves:
- Performance: CTEs like top_resources are executed once per dashboard load
  instead of duplicated in every widget query
- Maintainability: Query logic is defined once in the constants section
  and referenced wherever needed

Changes:
- Add Constant type with key, sql, query, description, and result fields
- Add constants field to Dashboard type
- Add processConstant function to execute constant queries
- Add constantToCTE helper to convert results to VALUES subquery
- Update _overview.yaml with top_resources constant example

* refactor(dashboards): use simple list format for constants instead of CTEs

Change constantToCTE to constantToList to produce a simpler format:
- Before: (SELECT * FROM (VALUES ('a'), ('b')) AS t(name))
- After: ('a', 'b')

This is:
- Simpler to implement and understand
- Better performance (no subquery parsing)
- Works better with KQL queries
- Queries use IN clauses instead of JOINs

* feat(dashboards): add KQL query support for constants

Constants can now use either SQL or KQL queries:
- sql: Direct SQL query (takes precedence)
- query: KQL query (parsed and executed via Charts.queryMetrics)

Example YAML:
  constants:
    - key: top_services
      query: summarize count() by resource.service.name | top 10 by count_

* Auto-format code with fourmolu

* refactor(dashboards): address code review feedback

- Replace fold with fromMaybe [] for clarity
- Fix unsafe head with pattern matching: [escapeValue v | (v : _) <- rows]
- Rename constantToList to constantToSQLList for clarity

* fix(dashboards): correct Constant type JSON deriving clause

Wrap DAE.CamelToSnake in DAE.FieldLabelModifier to match the pattern
used by other types like Variable.

* fix(dashboards): address code review feedback for constants

- Fix NULL issue in constantToSQLList: use empty subquery
  (SELECT NULL::text WHERE FALSE) instead of (NULL) to avoid
  SQL three-valued logic issues with IN clauses
- Add logging for failed constant SQL/KQL queries to aid debugging

* Auto-format code with fourmolu

* refactor(dashboards): improve constants code quality

- Add execution timing with Log.timeAction for constant queries
- Log debug message on successful query completion with duration
- Use LambdaCase for cleaner constantToSQLList pattern matching
- Use bimap composition for more idiomatic constantsToMap
- Document that empty inner lists are intentionally skipped

* refactor(dashboards): simplify constants implementation

- Extract runQuery helper to deduplicate SQL/KQL error handling
- Use where clause instead of let...in for constantToSQLList
- Eliminate intermediate constantsMap allocation by building
  allParamsWithConstants directly from processedConstants
- Remove unused constantsToMap function
- Use traverse instead of forM for more idiomatic style

Reduces code by 18 lines while improving clarity.

* refactor(dashboards): extract common logic and use functional patterns

- Extract replaceVariableFields using HasField' constraint from
  generic-lens to deduplicate replaceQueryVariables/replaceConstantVariables
- Simplify runQuery helper using either with $> operator
- Both changes improve code reuse and reduce duplication

* Auto-format code with fourmolu

* fix(dashboards): resolve ambiguous id reference

Use identity instead of id to avoid conflict with User.id field.

* fix(dashboards): use explicit functions to avoid overlapping instances

Revert generic HasField' approach - explicit functions are simpler
and avoid type class resolution issues.

* Auto-format code with fourmolu

* fix(dashboards): substitute constant placeholders in widget queries

Replace {{const-*}} placeholders in widget sql and query fields during
server-side processing. Previously, constants were processed but not
substituted into widget queries before rendering, causing the frontend
to send raw placeholders to /chart_data which resulted in SQL syntax
errors like "WHEN name IN  THEN".

* fix(dashboards): rename shadowed variables to avoid -Werror

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-02 13:37:06 +01:00
Anthony Alaribe
4af007eb65
Add KQL support for latency percentile queries (#255)
* Add KQL percentiles() function for latency percentile queries

- Add Percentiles aggregation function to Stats.hs that generates
  p50, p75, p90, p95, p99 percentiles with optional divisor for
  unit conversion (e.g., percentiles(duration, 1e6) for ns to ms)
- Update Parser.hs to generate LATERAL unnest SQL pattern when
  percentiles() is used in summarize queries
- Update Log.hs to use KQL query instead of raw SQL for latency
  percentiles widget
- Update dashboard YAML files to use KQL percentile queries:
  - opentelemetry-tracing.yaml
  - endpoint-stats.yaml
  - mysql.yaml
  - postgresql.yaml
  - apache.yaml
  - cloudflare.yaml

This reduces SQL boilerplate significantly and makes percentile
queries much more readable and maintainable.

* Auto-format code with fourmolu

* Update KQL percentile/percentiles to match Microsoft KQL syntax

Update the implementation to match Microsoft KQL semantics:
- percentile(expr, percentile) - single percentile value
- percentiles(expr, p1, p2, p3, ...) - multiple custom percentile values

Key changes:
- Parser now accepts explicit percentile values (e.g., 50, 75, 90, 95)
- If last value > 100, it's treated as a divisor for unit conversion
- SQL generation dynamically builds ARRAY based on specified percentiles
- Dashboard queries now use explicit percentile values

Examples:
  percentile(duration, 95) - single 95th percentile
  percentiles(duration, 50, 75, 90, 95) - multiple percentiles
  percentiles(duration, 50, 75, 90, 95, 1e6) - with divisor for ns->ms

* Match Microsoft KQL syntax for percentile/percentiles functions

Update the implementation to exactly match Microsoft KQL semantics:
- percentile(expr, percentile) - single percentile value
- percentiles(expr, p1, p2, ...) - multiple percentile values

Now supports expressions in the first argument for unit conversion:
  percentiles(duration / 1e6, 50, 75, 90, 95)

Key changes:
- Add SubjectExpr type to support field / number and field * number
- Parser accepts expression as first arg, then percentile values
- No more magic divisor detection - use explicit expressions
- Dashboard queries updated to use proper expression syntax

Examples matching Microsoft KQL:
  percentile(duration, 95)
  percentiles(duration, 50, 75, 90, 95)
  percentiles(duration / 1e6, 50, 75, 90, 95, 99)

* Auto-format code with fourmolu

* Fix chart widget query updates and combine where clauses

- Fix event dispatch in query-editor.ts: dispatch update-query to window
  so chart widgets receive query change events
- Fix Parser.hs: combine multiple where clauses with AND instead of
  replacing them, so filters like "service == X | duration != null"
  correctly apply both conditions
- Add combineWhereClause helper function
- Add unit test for combined where clause behavior
- Refactor Stats.hs: extract setAlias helper for namedAggregation

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-01 18:24:49 +01:00
Anthony Alaribe
924e8e4002
Query cache (#252)
* add intelligent query cache for KQL timeseries queries

- Cache summarize queries with bin/bin_auto time binning
- Store results in UNLOGGED PostgreSQL table for performance
- Delta fetch on partial cache hits (only query new time range)
- Merge cached + new data, deduplicate by timestamp
- 24h sliding window eviction via scheduled cleanup job
- Per-project cache namespace with query hash + bin interval key

* Auto-format code with fourmolu

* fix query cache issues and improve code quality

- Fix race condition: use LEAST/GREATEST for cache time range merging
- Fix partial hit logic: handle requests extending both directions
- Add LIMIT 1 to cache lookup query
- Use existing toXXHash from Utils instead of manual xxHash call
- Single-pass stats calculation with foldl'
- Use liftA2 for Maybe operations, comparing for point-free style
- Use viaNonEmpty from Relude instead of Safe package

* add hourly cache eviction to prevent unbounded growth

- Add cleanupExpiredCache function to remove stale entries
- Evict entries where cached_to > 24h ago or last_accessed_at > 1h ago
- Integrate with HourlyJob in BackgroundJobs
- Log cleanup count when entries are deleted

* Auto-format code with fourmolu

* refactor query cache for conciseness and correctness

- Use <&> and LambdaCase for cleaner lookupCache
- Extract toPosix helper for time conversions
- Use groupBy for declarative deduplication
- Remove redundant index (UNIQUE constraint creates it)
- Increase LRU threshold to 4h (from 1h)
- Remove redundant Parser qualified import in Charts.hs

* Auto-format code with fourmolu

* fix query cache stats calculation for multi-column data

- recalculateStats now processes all value columns, not just the first
- maxGroupSum correctly sums all values per row (timestamp)
- filterByTimestamp recalculates stats after filtering
- add integration tests for cache hit, partial hit, and multi-column stats

* Auto-format code with fourmolu

* fix cache metadata mismatch and backward-extending request handling

- Use slidingWindowStart instead of entry.cachedFrom when updating cache
  after trimming, ensuring metadata matches actual data range
- Remove PartialHit case for requests extending both directions, as only
  forward delta was fetched leaving backward data missing

* optimize query cache table for performance

- Use composite primary key instead of UUID PK + unique constraint
- Remove FK constraint (orphans cleaned by LRU eviction)
- Use JSON instead of JSONB (faster writes, always read whole blob)
- Add fillfactor=70 for HOT updates on hit_count/last_accessed_at
- Add aggressive autovacuum settings for high-update table
- Simplify eviction to just LRU (remove redundant cached_to check)
- Remove unnecessary indexes (table is small, hourly eviction)

* fix query cache correctness and performance issues

- Replace LEAST/GREATEST with direct replacement in updateCache to fix
  metadata mismatch after trimOldData removes old entries
- Make sliding window configurable based on bin interval (48 points or 24h min)
- Cap mode frequency map to 1000 entries for high-cardinality data
- Use vector ifilter for deduplication instead of list groupBy conversion

* Auto-format code with fourmolu

* use Relude words and one instead of qualified imports

* refactor: simplify QueryCache code

- Simplify parseBinIntervalToSeconds using unitToSeconds helper
- Extract rowTimestamp helper to dedupe join . V.headM usage
- Replace case () with multi-way if in lookupCache

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2026-01-01 14:51:17 +01:00
Yussif Mohammed
cc73abfc7e move query monitors to Haskell implementation 2025-12-27 22:31:07 +00:00
Anthony Alaribe
9c6131a186 chore: update gridstack.js to v12.4.1 2025-12-26 21:49:26 +01:00
Anthony Alaribe
7b4a0eaffb dashboard sync fixes 2025-12-26 17:42:16 +01:00
Anthony Alaribe
bccc1bbacd
Github 2-way sync with a repo (#244)
* add git sync for dashboards

* fix: improve git sync reliability and code quality

- Fix race condition: store root tree SHA instead of file entry SHA

- Fix empty token handling: preserve existing token when form empty

- Improve decryption: return Nothing on failure

- Replace inefficient JSON parsing with parseMaybe

- Replace manual toHex with base16-bytestring

- Add uuid-quasi for compile-time UUID validation in tests

* refactor: consolidate git sync helpers and reduce code duplication

* Auto-format code with fourmolu

* refactor: improve git sync code quality

- Webhook validation now returns Either for better error messages
- Add SQL column constant to reduce duplication
- Simplify Map construction with inline lambda
- Improve pattern matching exhaustiveness in gitSyncPushDashboard
- PackageImports kept for explicit crypto package disambiguation

* Auto-format code with fourmolu

* refactor: improve code quality and fix SQL injection risk

- Use pg-entity _selectWhere/_delete instead of manual column lists
- Fix SQL injection in selectDashboardsSortedBy with whitelist approach
- Add Entity instance for GitHubSync for type-safe queries
- Replace two-pass partition with single-pass foldl' in git sync
- Parallelize file fetching during git sync using Ki.scoped
- Qualify SqlQQ import to avoid collision with Variable.sql field
- Rename key params to encKey to avoid shadowing Data.Aeson.Lens.key

* Auto-format code with fourmolu

* feat: add comprehensive GitHub sync setup instructions

- Show full webhook URL with copy button
- Add step-by-step guide for creating GitHub personal access token
- Document expected repository structure (dashboards/*.yaml)
- Show example dashboard YAML format
- Include webhook setup instructions for auto-sync

* refactor: use markdown for git sync setup instructions

- Replace verbose HTML with markdown quasi-quotes
- Use MMark to render markdown to HTML
- Much cleaner and easier to maintain documentation
- Removes mmark from unused packages warning

* refactor: improve code quality and add decryption logging

- Add logging when GitHub sync token decryption fails to aid debugging
- Replace foldl' partition with idiomatic list comprehensions
- DRY duplicated SQL queries in selectDashboardsSortedBy
- Use pg-entity _selectWhere for type-safe query building
- Use RecordDot syntax instead of fromOnly in getDashboardByBaseTemplate

* Auto-format code with fourmolu

* refactor: improve code quality and security

- Add warning log when webhook accepted without secret validation
- Extract withDecryption helper to DRY decrypted getter functions
- Use foldMap for efficient buildSyncPlan implementation
- Extract delete fields in list comprehension to avoid pattern warnings
- Remove unused imports (foldl', Data.Map.Strict)

* style: fix hlint suggestions

- Use point-free style for Ki.fork composition
- Remove redundant toStrict call
- Parenthesize unary negation for clarity
- Remove redundant brackets around V.fromList

* style: remove unnecessary package qualification for base16-bytestring

* Auto-format code with fourmolu

* fix: resolve CI warnings and errors

- Add fromJust import to GitSyncSpec.hs
- Remove unused Job parameter from processBackgroundJob
- Fix ambiguous record fields in DashboardsSpec.hs using lens syntax
- Remove undefined usage in BusinessFlowsSpec.hs

* refactor: simplify withDecryption using maybe and either

* Auto-format code with fourmolu

* refactor: simplify git sync error handling and use pg-entity

* fix: resolve CI compile errors in tests

* fix: resolve DashboardVM field access ambiguity in tests

* fix: use record dot syntax for DashboardVM, qualified for DashboardForm

* security: use constant-time comparison for HMAC validation

* refactor: use point-free style for encryptToken

* refactor: flatten nested case with tuple pattern matching

* refactor: use lens for decryptSync, fix constEq type ambiguity

* refactor: use bimap for base64 errors, Ki.awaitAll for parallel exec

* Auto-format code with fourmolu

* refactor: simplify sort field handling with lookup table

* perf: fix N+1 query by pre-fetching teams before parallel sync

* fix: use mkDashboard helper to avoid ambiguous record update

* perf: use T.filter instead of T.replace for newline removal

* refactor: use point-free style for titleToFilePath

* feat: add GitHub sync E2E tests and fix empty repo handling

- Add comprehensive E2E integration tests for GitHub sync

- Handle 404 from GitHub tree API as empty tree (for repos with all files deleted)

- Add updateTags function to update dashboard tags during sync

- Fix SyncUpdate to also update tags when pulling from GitHub

- Add Default instance for GitHubSync

- Add detectDefaultBranch function for auto-detecting repo branch

* Auto-format code with fourmolu

* Github.hs

* Auto-format code with fourmolu

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-12-26 01:19:12 +01:00
Yussif Mohammed
cc51fda8a6
Alerts view & Error details page (#225)
* towards supporting teams in projects.

* Auto-format code with fourmolu

* improve team list

team view side page, alerts and dashbaord next

yeah well

validation checks and fixes

tiny details improvments

prepare endpoints for testing

Auto-format code with fourmolu

towards tests

Auto-format code with fourmolu

rm monoscope-test

more tests cases

Auto-format code with fourmolu

alerts page improvements bug fixes and teams link

Auto-format code with fourmolu

feat: alerts section, teams.

send notifications

Auto-format code with fourmolu

fix errs and slack install

Auto-format code with fourmolu

towards table component

Auto-format code with fourmolu

dashbaord bulk actions delete

dashboards with teams

team dashboard

Auto-format code with fourmolu

feat: teams bulk actions delete

Auto-format code with fourmolu

feat: add title field & teams to dashboard modal

Auto-format code with fourmolu

* remove stack files and configure hie.yaml for better IDE support

Auto-format code with fourmolu

fix and passing tests

Auto-format code with fourmolu

add dashboards spec

Auto-format code with fourmolu

notifications templates

query viz and alert notifications

Auto-format code with fourmolu

alert config stuff

fixes and towards issue detail page

Auto-format code with fourmolu

Reorganize project structure

Move config files to config/ directory (tailwind.config.js, workbox-config.js, weeder.toml). Move documentation to docs/ (DEVELOPMENT.md, DOCKER_COMPOSE_README.md). Update all references in Dockerfile, Makefile, tailwind.css, and documentation.

Fix CI disk space exhaustion by cleaning up unnecessary files and build artifacts

Optimize CI caching strategy to reduce disk usage

Use separate caches per test suite and cache only essential build
artifacts instead of entire dist-newstyle directory. This reduces
disk usage while maintaining fast compilation through effective caching.

Fix CSS build in deployment by using correct Tailwind v4 CLI

The project uses Tailwind CSS v4 syntax (@import, @source, @plugin
directives) but the build commands were using the old v3 CLI which
doesn't process v4 syntax correctly, causing CSS changes to not appear
in deployed builds.

Updated Dockerfile and CI workflows to use @tailwindcss/cli instead of
the legacy tailwindcss command, and removed the obsolete -c config flag
since v4 uses @config directive in the CSS file.

Use npx tailwindcss instead of @tailwindcss/cli for v4 compatibility

The tailwindcss package (v4.1.13) in devDependencies is the correct CLI
for Tailwind v4. Using @tailwindcss/cli was unnecessarily specific and
may have caused issues in the Docker build environment.

This ensures the CSS with all custom utilities (surface-raised, etc.)
builds correctly in production.

Cherry pick files (#232)

* cherry pick files

* Auto-format code with fourmolu

* add more files

* Auto-format code with fourmolu

* finx undefined var

* review changes

* Auto-format code with fourmolu

* discord channel' type rename

* Auto-format code with fourmolu

* claude rec fixes

* Auto-format code with fourmolu

* fix notification typo

* Auto-format code with fourmolu

* discord get channel log error

* fix typo

* rm reswap related code from System.Types.hs

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com>

Teams rebased (#233)

* towards supporting teams in projects.

* Auto-format code with fourmolu

* fix htmx json encoder extension

* improve team list

* team view side page, alerts and dashbaord next

* yeah well

* validation checks and fixes

* tiny details improvments

* prepare endpoints for testing

* Auto-format code with fourmolu

* towards tests

* Auto-format code with fourmolu

* rm monoscope-test

* fix alert creation

* more tests cases

* Auto-format code with fourmolu

* alerts page improvements bug fixes and teams link

* Auto-format code with fourmolu

* feat: alerts section, teams.

* send notifications

* Auto-format code with fourmolu

* fix errs and slack install

* Auto-format code with fourmolu

* add teams column to dashboards table

* towards table component

* Auto-format code with fourmolu

* dashbaord bulk actions delete

* dashboards with teams

* team dashboard

* Auto-format code with fourmolu

* fix table

* feat: teams bulk actions delete

* Auto-format code with fourmolu

* feat: add title field & teams to dashboard modal

* Auto-format code with fourmolu

* remove stack files and configure hie.yaml for better IDE support

* Auto-format code with fourmolu

* fix and passing tests

* Auto-format code with fourmolu

* add more tests

* add dashboards spec

* Auto-format code with fourmolu

* fix pull request workflow

* fix: review change requests

* Auto-format code with fourmolu

* feat: tagify consolidation

* Auto-format code with fourmolu

* updates

* simplifications and other changes

* background changes and fixes

* Auto-format code with fourmolu

* package yaml

* Auto-format code with fourmolu

* fix typo

* towards supporting teams in projects.

* Auto-format code with fourmolu

* improve team list

* team view side page, alerts and dashbaord next

* yeah well

* validation checks and fixes

* tiny details improvments

* prepare endpoints for testing

* Auto-format code with fourmolu

* towards tests

* Auto-format code with fourmolu

* rm monoscope-test

* more tests cases

* Auto-format code with fourmolu

* alerts page improvements bug fixes and teams link

* Auto-format code with fourmolu

* feat: alerts section, teams.

* send notifications

* Auto-format code with fourmolu

* fix errs and slack install

* Auto-format code with fourmolu

* add teams column to dashboards table

* towards table component

* Auto-format code with fourmolu

* dashbaord bulk actions delete

* dashboards with teams

* team dashboard

* Auto-format code with fourmolu

* feat: teams bulk actions delete

* Auto-format code with fourmolu

* feat: add title field & teams to dashboard modal

* Auto-format code with fourmolu

* remove stack files and configure hie.yaml for better IDE support

* Auto-format code with fourmolu

* fix and passing tests

* Auto-format code with fourmolu

* add more tests

* add dashboards spec

* Auto-format code with fourmolu

* fix: review change requests

* Auto-format code with fourmolu

* feat: tagify consolidation

* Auto-format code with fourmolu

* updates

* simplifications and other changes

* background changes and fixes

* Auto-format code with fourmolu

* package yaml

* Auto-format code with fourmolu

* Migrate to master's Table API

  - Update dashboards and teams tables to use new column-based API
  - Replace ItemsList.ItemsRows with Table.TableRows
  - Add missing validateTeamDetails function
  - Fix import conflicts

* Migrate to master's Table API and fix migration idempotency

- Update dashboards and teams tables to use new column-based API
- Replace ItemsList.ItemsRows with Table.TableRows
- Add missing validateTeamDetails function
- Fix import conflicts (Wreq.header ambiguity)
- Add IF NOT EXISTS to index creation in teams migration

* Add frosted glass backdrop to modals

- Add backdrop-filter blur effect to .modal-backdrop class
- Applies 8px blur for frosted glass effect
- Includes webkit prefix for browser compatibility

* Remove padding from table container

- Remove px-6, pt-4, and pb-16 from containerClasses
- Table now renders edge-to-edge without padding

* Add padding to non-settings page content

- Remove padding from Table component's default containerClasses
- Add px-6 pt-4 pb-16 wrapper for non-settings pages in BodyWrapper
- Settings pages (Teams, etc.) remain without extra padding

* Remove duplicate padding from dashboards list page

- Remove pb-2 px-6 pt-8 from itemsListPage div
- Padding now comes from BodyWrapper parent wrapper
- Avoids double padding on dashboards list

* Align dashboard button and table checkbox with page header

* Fix double padding issue with standardized table padding system

- Remove global padding wrapper from BodyWrapper to fix double padding
- Add addPadding config option to Table component
- Update table pages to use addPadding: Dashboards, API Catalog, Issues, Monitors
- Standardize all table padding to px-6 pt-4 pb-2
- Update Monitors page section padding to match standard

* fix tables and compilation

* Auto-format code with fourmolu

* fix dulicate line

* Auto-format code with fourmolu

* fix build

* Refactor FromJSON instances to use deriving strategies

- Use deriving via with DAE.Rename for field name transformations

- Use deriving via with DAE.StripSuffix for simple underscore removal

- Extract SlackEventPayload constructors into separate record types

- Simplify TeamForm to use deriving anyclass for internal API

- Remove unused imports

Code reduction: ~80 lines of manual JSON parsing boilerplate eliminated

* Auto-format code with fourmolu

* Add team validation and permission checks

- Add admin-only restriction for team create/update
- Validate team members are project members
- Add email format validation for notification emails
- Add length limits to team name and handle
- Verify teams exist before adding to dashboards
- Extract dispatchTeamNotifications helper in BackgroundJobs
- Use TeamDetails record to simplify createTeam/updateTeam APIs
- Handle duplicate team handles with ON CONFLICT DO NOTHING

* Auto-format code with fourmolu

* Refactor teams feature with comprehensive improvements

Code Quality & Type Safety:

- Refactor createTeam/updateTeam to use TeamDetails record type

- Add compile-time safety with NonEmpty for softDeleteProjectMembers

- Standardize SQL array syntax (lowercase uuid[], consistent spacing)

- Add phone_numbers support to all team types and queries

Performance Optimizations:

- Optimize getTeamsVM/getTeamByHandle with LEFT JOIN + array_agg

- Use for_ instead of explicit null checks

Error Handling & Observability:

- Add logging for missing/deleted teams in monitor notifications

- Improve error handling for addTeamsToDashboards

- Add graceful fallback when configured teams are deleted

Code Cleanup:

- Extract dispatchTeamNotifications helper function

- Remove redundant project query

- Use idiomatic Haskell patterns

* Auto-format code with fourmolu

* Fix variable shadowing in email validation

* Refactor for code succinctness

- Simplify NonEmpty to Vector conversion (remove redundant toList)

- Extract handleQueryMonitorThreshold into focused helper functions

- Add logMissingTeams for team logging

- Add createAndInsertIssue for issue creation

- Add calculateThreshold for threshold calculation

- Add buildMonitorAlert for alert construction

- Add sendNotifications for notification dispatch

- Add sendFallbackNotifications for fallback handling

* Auto-format code with fourmolu

---------

Co-authored-by: Yussif Mohammed <yousiph77@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

towards supporting teams in projects.

Auto-format code with fourmolu

improve team list

validation checks and fixes

tiny details improvments

Auto-format code with fourmolu

towards tests

Auto-format code with fourmolu

more tests cases

Auto-format code with fourmolu

* alerts page improvements bug fixes and teams link

Auto-format code with fourmolu

feat: alerts section, teams.

send notifications

Auto-format code with fourmolu

fix errs and slack install

Auto-format code with fourmolu

towards table component

Auto-format code with fourmolu

dashbaord bulk actions delete

dashboards with teams

Auto-format code with fourmolu

feat: teams bulk actions delete

Auto-format code with fourmolu

feat: add title field & teams to dashboard modal

Auto-format code with fourmolu

remove stack files and configure hie.yaml for better IDE support

Auto-format code with fourmolu

fix and passing tests

Auto-format code with fourmolu

add dashboards spec

Auto-format code with fourmolu

alert config stuff

fixes and towards issue detail page

rmv duplicate declarations

Auto-format code with fourmolu

fix resizer

Auto-format code with fourmolu

make project compile/fix errors

* Auto-format code with fourmolu

feat: use log-list virtual table for monitor history tab

Auto-format code with fourmolu

fix issue detail tabs

Auto-format code with fourmolu

clean up unused imports

Auto-format code with fourmolu

parameterized trace/span sql queries

fix unkwon stack typo

more unused imports cleanup

Auto-format code with fourmolu

remove commented logs

Rebase onto master, resolve conflicts with master changes

fix tests after recent changes to alerts view

fix tests after changing ManageMembers handlers to return ProjectId

remove monoscope-test

towards fixing tests

Auto-format code with fourmolu

fix: sort starred dashboards first and add chart padding

- Dashboard list now always shows starred/favorited items at the top regardless of the selected sort option (newest, oldest, A-Z, etc.)

- Added p-2 padding to widget chart container to prevent bleeding edges

fix: exclude p-2 padding for timeseries_stat widgets

fix: dashboard variable tagify inputs not initializing correctly

- Update createTagify to accept both selector strings and DOM elements

- Wrap dashboard variable tagify init in DOMContentLoaded event

- Remove overflow-hidden from variable fieldset to allow dropdown display

fix: remove unnecessary border wrapper from table component

Auto-format code with fourmolu

towards fixing integration tests

Auto-format code with fourmolu

* fix more errors

* Auto-format code with fourmolu

* claude req fixes

* Auto-format code with fourmolu

* fix table

* Auto-format code with fourmolu

* bring back removed page due to rebase

* Auto-format code with fourmolu

* rm unused imports

* fix failing delim queries in BackgroundJobs.hs

* Auto-format code with fourmolu

* fix build after rebase

* Auto-format code with fourmolu

* test final fix

* rm log attention

* add index for first_trace_id and recent_trace_id in errors table

* fix index creation in 0019_add_trace_id.sql

* remove concurrently index

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-12-23 17:54:20 +01:00
Anthony Alaribe
5cd948697f
Teams improvement v2 (#234)
* Improve dashboards and teams UI with star functionality

- Add star/unstar functionality for dashboards with persistent state
- Update dashboard sorting to prioritize starred items
- Improve table component styling and layout
- Add icons for dashboards and teams in list views
- Streamline table columns and remove unnecessary checkboxes
- Update bulk actions to use new table component features

* Auto-format code with fourmolu

* Fix teams bulk actions to use itemId field

Update TBulkActionForm to use itemId instead of teamId to match
the Table component's standardized field name for bulk actions.

* Improve settings navigation layout and styling

- Reduce navigation width for better space utilization
- Update font sizes and spacing for cleaner appearance
- Improve icon styling with background colors
- Enhance navigation item padding and layout

* Refactor API keys page to use Table component and add client-side tab support

- Enhanced TabFilter component to support both client-side and server-side tabs
- Added clientSide boolean field to TabFilter for tab switching mode
- Added targetId field to TabFilterOpt for custom element targeting
- Refactored API keys page to use reusable Table component
- Updated all existing TabFilter usage to include new fields
- Improved consistency across table implementations

* Auto-format code with fourmolu

* nitpicks on

* add test for starring and unstarring, and dashboard default sorting

* Fix tagify scope issue in dashboard creation modal

The tagify variable was scoped inside DOMContentLoaded event listener,
causing a reference error when getSelectedTeams() tried to access it
during form submission. Moved declaration to outer scope.

* Fix gridStackInstance null error when adding dashboard widgets

* Fix teams badge WCAG contrast by using badge-neutral

* Fix compilation errors

- Fix do-notation errors by adding proper do blocks instead of using >> after $
- Rename local section_ helper to teamSection_ to avoid shadowing
- Remove unused ProjectId parameter from renderMonitorContent

* Use brackets instead of do-blocks for single-line expressions

- Keep code on one line by using parentheses and >> operator
- Applied to card_, notifRow_, lazySection_, teamSection_, field_, fieldIcon_ helpers

* Apply code formatting updates

- Replace font-mono with monospace class
- Minor whitespace adjustments

* Fix duplicate html assignment bug and simplify code

* Auto-format code with fourmolu

* Refactor tables to use standardized Table component with sorting

- Add containerId to Table Config for HTMX targeting
- Add renderAsTable mode for proper table rendering
- Add rowId and rowAttrs to TableRows for load-more consistency
- Fix th elements to include column attrs for alignment
- Fix class concatenation spacing in table headers
- Fix scrolling in BodyWrapper (overflow-y-hidden to overflow-y-auto)
- Add sort parameter to Issues.selectIssues
- Refactor Anomalies and ApiCatalog to use TableHeaderActions
- Remove flex classes from table cells

* Auto-format code with fourmolu

* Fix table load more by moving pagination inside tbody

- Move pagination link inside tbody for table mode (as a <tr>)
- Add renderTablePaginationLink with hx-target='closest tr'
- Add id to tbody for targeting
- Pagination row gets replaced with new rows + new pagination row

* Refactor Anomalies table to use built-in checkbox

- Remove custom checkbox column (use table's rowId feature instead)
- Add status indicator dot to Issue column title row
- Update TableRows to use proper rowId for load more

* Auto-format code with fourmolu

* Fix Anomalies issue column layout structure

- Fix indentation so metadata, stats, actions are separate blocks
- Status indicator dot in title row
- Condense code using single-line patterns where appropriate

* Auto-format code with fourmolu

* Merge renderPaginationLink and renderTablePaginationLink into single function

* Auto-format code with fourmolu

* Align row checkboxes to top and add vertical padding to issue column

* Improve settings sidebar: larger text, neutral icons, stronger selection highlight

* Widen settings sidebar

* Fix hlint warnings

* Fix all hlint warnings across codebase

* Auto-format code with fourmolu

* Fix GHC warnings: dodgy import, name shadowing, unused do-bind

* Use foldMap and zipWithM_ for cleaner iteration patterns

* Extract columnCount helper and add error handling for processVariable

* Auto-format code with fourmolu

* Optimize URL construction and use single-pass fold for change counting

* Extract issueTypeBadge helper to reduce code duplication

* Fix SQL injection vulnerabilities and semantic error in change counting

* Auto-format code with fourmolu

* Simplify SQL validation and remove redundant variable

* Auto-format code with fourmolu

* Rename selectDashboardsSorted to selectDashboardsSortedBy for clarity

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-12-19 23:44:55 +01:00
Anthony Alaribe
9521695299
Teams rebased (#233)
* towards supporting teams in projects.

* Auto-format code with fourmolu

* fix htmx json encoder extension

* improve team list

* team view side page, alerts and dashbaord next

* yeah well

* validation checks and fixes

* tiny details improvments

* prepare endpoints for testing

* Auto-format code with fourmolu

* towards tests

* Auto-format code with fourmolu

* rm monoscope-test

* fix alert creation

* more tests cases

* Auto-format code with fourmolu

* alerts page improvements bug fixes and teams link

* Auto-format code with fourmolu

* feat: alerts section, teams.

* send notifications

* Auto-format code with fourmolu

* fix errs and slack install

* Auto-format code with fourmolu

* add teams column to dashboards table

* towards table component

* Auto-format code with fourmolu

* dashbaord bulk actions delete

* dashboards with teams

* team dashboard

* Auto-format code with fourmolu

* fix table

* feat: teams bulk actions delete

* Auto-format code with fourmolu

* feat: add title field & teams to dashboard modal

* Auto-format code with fourmolu

* remove stack files and configure hie.yaml for better IDE support

* Auto-format code with fourmolu

* fix and passing tests

* Auto-format code with fourmolu

* add more tests

* add dashboards spec

* Auto-format code with fourmolu

* fix pull request workflow

* fix: review change requests

* Auto-format code with fourmolu

* feat: tagify consolidation

* Auto-format code with fourmolu

* updates

* simplifications and other changes

* background changes and fixes

* Auto-format code with fourmolu

* package yaml

* Auto-format code with fourmolu

* fix typo

* towards supporting teams in projects.

* Auto-format code with fourmolu

* improve team list

* team view side page, alerts and dashbaord next

* yeah well

* validation checks and fixes

* tiny details improvments

* prepare endpoints for testing

* Auto-format code with fourmolu

* towards tests

* Auto-format code with fourmolu

* rm monoscope-test

* more tests cases

* Auto-format code with fourmolu

* alerts page improvements bug fixes and teams link

* Auto-format code with fourmolu

* feat: alerts section, teams.

* send notifications

* Auto-format code with fourmolu

* fix errs and slack install

* Auto-format code with fourmolu

* add teams column to dashboards table

* towards table component

* Auto-format code with fourmolu

* dashbaord bulk actions delete

* dashboards with teams

* team dashboard

* Auto-format code with fourmolu

* feat: teams bulk actions delete

* Auto-format code with fourmolu

* feat: add title field & teams to dashboard modal

* Auto-format code with fourmolu

* remove stack files and configure hie.yaml for better IDE support

* Auto-format code with fourmolu

* fix and passing tests

* Auto-format code with fourmolu

* add more tests

* add dashboards spec

* Auto-format code with fourmolu

* fix: review change requests

* Auto-format code with fourmolu

* feat: tagify consolidation

* Auto-format code with fourmolu

* updates

* simplifications and other changes

* background changes and fixes

* Auto-format code with fourmolu

* package yaml

* Auto-format code with fourmolu

* Migrate to master's Table API

  - Update dashboards and teams tables to use new column-based API
  - Replace ItemsList.ItemsRows with Table.TableRows
  - Add missing validateTeamDetails function
  - Fix import conflicts

* Migrate to master's Table API and fix migration idempotency

- Update dashboards and teams tables to use new column-based API
- Replace ItemsList.ItemsRows with Table.TableRows
- Add missing validateTeamDetails function
- Fix import conflicts (Wreq.header ambiguity)
- Add IF NOT EXISTS to index creation in teams migration

* Add frosted glass backdrop to modals

- Add backdrop-filter blur effect to .modal-backdrop class
- Applies 8px blur for frosted glass effect
- Includes webkit prefix for browser compatibility

* Remove padding from table container

- Remove px-6, pt-4, and pb-16 from containerClasses
- Table now renders edge-to-edge without padding

* Add padding to non-settings page content

- Remove padding from Table component's default containerClasses
- Add px-6 pt-4 pb-16 wrapper for non-settings pages in BodyWrapper
- Settings pages (Teams, etc.) remain without extra padding

* Remove duplicate padding from dashboards list page

- Remove pb-2 px-6 pt-8 from itemsListPage div
- Padding now comes from BodyWrapper parent wrapper
- Avoids double padding on dashboards list

* Align dashboard button and table checkbox with page header

* Fix double padding issue with standardized table padding system

- Remove global padding wrapper from BodyWrapper to fix double padding
- Add addPadding config option to Table component
- Update table pages to use addPadding: Dashboards, API Catalog, Issues, Monitors
- Standardize all table padding to px-6 pt-4 pb-2
- Update Monitors page section padding to match standard

* fix tables and compilation

* Auto-format code with fourmolu

* fix dulicate line

* Auto-format code with fourmolu

* fix build

* Refactor FromJSON instances to use deriving strategies

- Use deriving via with DAE.Rename for field name transformations

- Use deriving via with DAE.StripSuffix for simple underscore removal

- Extract SlackEventPayload constructors into separate record types

- Simplify TeamForm to use deriving anyclass for internal API

- Remove unused imports

Code reduction: ~80 lines of manual JSON parsing boilerplate eliminated

* Auto-format code with fourmolu

* Add team validation and permission checks

- Add admin-only restriction for team create/update
- Validate team members are project members
- Add email format validation for notification emails
- Add length limits to team name and handle
- Verify teams exist before adding to dashboards
- Extract dispatchTeamNotifications helper in BackgroundJobs
- Use TeamDetails record to simplify createTeam/updateTeam APIs
- Handle duplicate team handles with ON CONFLICT DO NOTHING

* Auto-format code with fourmolu

* Refactor teams feature with comprehensive improvements

Code Quality & Type Safety:

- Refactor createTeam/updateTeam to use TeamDetails record type

- Add compile-time safety with NonEmpty for softDeleteProjectMembers

- Standardize SQL array syntax (lowercase uuid[], consistent spacing)

- Add phone_numbers support to all team types and queries

Performance Optimizations:

- Optimize getTeamsVM/getTeamByHandle with LEFT JOIN + array_agg

- Use for_ instead of explicit null checks

Error Handling & Observability:

- Add logging for missing/deleted teams in monitor notifications

- Improve error handling for addTeamsToDashboards

- Add graceful fallback when configured teams are deleted

Code Cleanup:

- Extract dispatchTeamNotifications helper function

- Remove redundant project query

- Use idiomatic Haskell patterns

* Auto-format code with fourmolu

* Fix variable shadowing in email validation

* Refactor for code succinctness

- Simplify NonEmpty to Vector conversion (remove redundant toList)

- Extract handleQueryMonitorThreshold into focused helper functions

- Add logMissingTeams for team logging

- Add createAndInsertIssue for issue creation

- Add calculateThreshold for threshold calculation

- Add buildMonitorAlert for alert construction

- Add sendNotifications for notification dispatch

- Add sendFallbackNotifications for fallback handling

* Auto-format code with fourmolu

---------

Co-authored-by: Yussif Mohammed <yousiph77@gmail.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2025-12-18 23:38:00 +01:00
Yussif Mohammed
a85be17184
Cherry pick files (#232)
* cherry pick files

* Auto-format code with fourmolu

* add more files

* Auto-format code with fourmolu

* finx undefined var

* review changes

* Auto-format code with fourmolu

* discord channel' type rename

* Auto-format code with fourmolu

* claude rec fixes

* Auto-format code with fourmolu

* fix notification typo

* Auto-format code with fourmolu

* discord get channel log error

* fix typo

* rm reswap related code from System.Types.hs

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Anthony Alaribe <anthonyalaribe@gmail.com>
2025-12-18 12:13:39 +01:00
Anthony Alaribe
2d893b8520
Fix Platform colors to reduce eye strain (#231)
* Fix badge-neutral contrast for better readability

* Remove unused CSS utilities and variables

* Adjust dark mode to premium blue aesthetic

- Darker backgrounds (15-18% vs 18-22%) for high-quality look
- Maintains visible blue tint with 0.020 chroma
- Improved text contrast ratios (textStrong: 14.58:1)
- All combinations pass WCAG AA standards

* Add surface-raised utility class for elevated surfaces

- Created .surface-raised class with bgRaised, border, and shadow
- Applied to project cards for better contrast against background
- Applied to all tables (API Catalog, Issues, etc.) via Table component
- Fixed monitor alert icons padding for uniform appearance
- Provides consistent raised platform aesthetic across the app

* revert color

* Enhance surface-raised with dimensional lighting effects

Add subtle gradient and inset shadows for 3D depth, update background
to use fillWeaker color, and apply surface-raised utility to widgets.

* Replace card-round with surface-raised for consistency

Apply surface-raised styling to all cards including stat boxes, list items,
and anomalies widget. Remove unused card-round CSS class.
2025-12-17 11:51:37 +01:00
Anthony Alaribe
9527fa7571 Reorganize project structure
Move config files to config/ directory (tailwind.config.js, workbox-config.js, weeder.toml). Move documentation to docs/ (DEVELOPMENT.md, DOCKER_COMPOSE_README.md). Update all references in Dockerfile, Makefile, tailwind.css, and documentation.
2025-12-17 00:49:42 +01:00
Anthony Alaribe
638df4392b Add visualization type support for alerts
- Add visualization_type column to query_monitors table

- Store and load visualization type when creating/editing alerts

- Update alert edit links to include query and viz_type parameters

- Fix alert form POST endpoint path (/p/<pid>/monitors/alerts)

- Fix visualizationTabs_ to respect vizTypeM when in alert mode

- Add getVizType() JS helper function
2025-11-27 23:29:55 +01:00
Anthony Alaribe
229f0d7e2d Use CSS @apply for badge classes instead of Haskell helpers
- Add .badge and .badge-outline CSS classes with @apply in tailwind.css
- Remove badge_, badgeOutline_, badgeClass from Utils.hs (-19 lines)
- Update AnomalyList.hs to use CSS classes directly
2025-11-26 22:39:13 +01:00
Anthony Alaribe
2b61520857 service worker regeneration 2025-11-25 23:45:12 +01:00
Anthony Alaribe
ffed69147d sprite changes 2025-11-23 19:52:40 +01:00
Anthony Alaribe
0e08e7fea7 Simplify telemetrygen banner by removing icon 2025-11-23 19:52:40 +01:00
Anthony Alaribe
6a9ec7dcc8
Support the has_all and has_any operators, then Remove flamegraph widget and increase recent traces height (#209)
* Support the has_all and has_any operators

* Remove flamegraph widget and increase recent traces height in overview dashboard
2025-11-23 14:25:27 +01:00
Yussif Mohammed
9ec59274f4 minor fixes 2025-11-21 19:43:34 +00:00
Anthony Alaribe
d024a55a2d Improve dark mode consistency and fix UI elements
- Convert all text colors to oklch with blue saturation for consistent theming
- Update DaisyUI theme colors to use solid oklch values for better visibility
- Fix progress bar transparency issues in both light and dark modes
- Add missing SVG sprite icons: alert-circle, activity, route, routes
- Update base colors to use oklch with proper blue tint
2025-11-18 22:40:41 +01:00
Anthony Alaribe
a1a9f8a371 Adjust dark mode background colors for better contrast
Update dark mode background to 14% lightness with increased blue saturation for improved visual comfort and brand consistency.
2025-11-18 22:40:41 +01:00
Yussif Mohammed
6034559e31 towards trace shape flame graph 2025-11-17 18:58:24 +00:00
Anthony Alaribe
ad12dbf927 Fix issues table constraint to allow multiple query alerts
The previous unique constraint was too restrictive, preventing multiple
query alert issues for the same project and preventing new api_change
issues after acknowledging old ones.

Changes:
- Add migration to drop overly restrictive table-level constraint
- Update insertIssue to use partial unique index instead
- Partial index only applies to open api_change issues per endpoint

The partial unique index unique_open_api_change_issue_per_endpoint
already enforces the correct business logic: only one open (unacknowledged,
unarchived) api_change issue per (project_id, endpoint_hash).
2025-11-15 05:59:08 +00:00
Yussif Mohammed
60aa4ae653
New Reports UI (#207)
* checkpoint

* span overview checkpoint

* reports checkpoint, slow queries

* empty state

* auto load first report

* format

* fetch and save neccesary chart data for report

* feat: issues breakdown

* touches

* issues id

* format
2025-11-13 07:45:20 +00:00
Yussif Mohammed
2b129af05e towards traces widget 2025-11-04 21:18:20 +00:00
Anthony Alaribe
7d4d27e15c reduce the paddings of the tabs 2025-11-02 13:57:50 +01:00
Anthony Alaribe
42a7a30261 fix the cursor handling logic for query logs. And add performance logic and checks so we can find out whats making the query-editor sluggish 2025-10-31 18:11:11 +01:00
Anthony Alaribe
5b8c6ca5b0 fix rendering of the latency charts to calculate units. also fix select dropdowns which were transparent across the app. etc 2025-10-26 23:45:16 +01:00
Anthony Alaribe
614715b313 fix tests and reduce default limit to 500 for weaker conections 2025-10-26 23:10:32 +01:00
Anthony Alaribe
b774d51c69 fix chart and timepicker dropdown behavior to collapse after use. 2025-10-26 00:43:15 +02:00
Anthony Alaribe
a3b60fa71b increatse the query limits on the overview dashboard chart queries 2025-10-26 00:43:15 +02:00
Anthony Alaribe
ed97da7594 fixes for integration tests 2025-10-18 02:17:33 +02:00
Anthony Alaribe
e4bec5a3c3 checkpoint to tables where you can select a row variable 2025-10-12 15:34:58 +02:00
Yussif Mohammed
49c6e6f9aa generate patterns for summary 2025-10-12 05:58:08 +00:00
Anthony Alaribe
3e6e79d97d improve queries for the databases tab 2025-10-11 22:53:44 +02:00
Anthony Alaribe
8c9fd7ed12 pretty render column calues and progress in table widgets 2025-10-11 21:53:01 +02:00
Anthony Alaribe
4eaa7eceb1 introduce progress column in tables, with column variant 2025-10-11 16:47:38 +02:00