Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): add capability to compact identical probes #1337

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

syamsudotdev
Copy link
Contributor

Monika Pull Request (PR)

The main purpose of these changes is to optimize monitoring by reducing redundant identical probes while maintaining individual alert configurations. This PR will resolve #1285

What feature/issue does this PR add

  1. Added Probe Compaction Feature

How did you implement / how did you fix it

  1. Added Probe Compaction Feature:

    • New CLI flag --compact-probes introduced
    • When enabled, it combines probes with identical configurations to optimize execution
    • Compacted probes maintain their individual alert configurations
    • Probes with request chaining or multiple probe types are not compacted
  2. New Files Created:

    • compact-config.ts: Core implementation of probe compaction logic
    • compact-config.test.ts: Comprehensive test suite for the compaction feature
  3. Documentation Update:

    • Added new section in CLI options documentation explaining the probe compaction feature
  4. Implementation Details:

    • Probes are compared based on their configuration (excluding name and alerts)
    • Identical probes are merged while maintaining individual alert configurations
    • The system keeps track of original probe IDs for logging purposes
    • Compaction skips probes with chaining or multiple probe types
    • Alert deduplication is implemented to avoid duplicate alerts in compacted probes
  5. Interface Changes:

    • Added jointId field to Probe interface to track merged probe IDs
    • Modified logging system to handle compacted probes appropriately

How to test

  1. Given configuration
probes:
  - id: '1'
    name: HTTP Bin
    requests:
      - url: https://httpbin.org/status/200
        timeout: 7000
  - id: '2'
    name: HTTP Bin
    requests:
      - url: https://httpbin.org/status/200
        timeout: 7000

# limit log database size in bytes
db_limit:
  max_db_size: 1000000000
  deleted_data: 1
  cron_schedule: '*/1 * * * *'
  1. npm run start -- --config monika.yml --compact-probes
  2. Observe log INFO: Found identical probes, following probes IDs will be compacted on runtime: 1, 2
  3. Observe probing https://httpbin.org/status/200 happen only once per cycle

Screenshot

image

- Added 'src/components/config/identical-probes.ts' to identify identical probes.
- Updated 'src/components/config/index.ts' to utilize identical probe identification in config updates.
- Enhanced 'src/context/index.ts' with probe result caching capabilities.
Copy link

codecov bot commented Dec 15, 2024

Codecov Report

Attention: Patch coverage is 60.19417% with 82 lines in your changes missing coverage. Please review.

Project coverage is 62.99%. Comparing base (6a29470) to head (2af9c90).
Report is 33 commits behind head on main.

Files with missing lines Patch % Lines
src/components/config/compact-config.ts 62.30% 45 Missing and 27 partials ⚠️
src/components/logger/history.ts 11.11% 7 Missing and 1 partial ⚠️
src/components/config/index.ts 66.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1337      +/-   ##
==========================================
+ Coverage   62.51%   62.99%   +0.47%     
==========================================
  Files         112      111       -1     
  Lines        3391     3662     +271     
  Branches      591      638      +47     
==========================================
+ Hits         2120     2307     +187     
- Misses       1079     1134      +55     
- Partials      192      221      +29     

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cache the responses of identical requests to prevent multiple requests within a short time
1 participant