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

Implement Components Availability API Endpoint #22

Merged
merged 10 commits into from
Dec 9, 2024
Merged

Conversation

bakhterets
Copy link
Contributor

Description:

This PR introduces the implementation of an API endpoint to retrieve the availability of components, calculated monthly for the last 12 months. Below is a summary of the changes:

Added:

Data Structures:
ComponentAvailability and MonthlyAvailability structs to encapsulate data about component availability.

Handler Function:

GetComponentsAvailabilityHandler to process HTTP GET requests and return availability data for components.

Calculation Logic:

calculateAvailability function to compute the monthly availability of components based on incident data, considering:
Only incidents with a specific impact level.
Accurate handling of incident periods that span multiple months or fall partially outside the calculation period.

Helper Functions:

minTime and maxTime for date range calculations.
hoursInMonth to calculate the total hours in a specific month.

Enhanced Functionality:

Sorting: Availability data is sorted by year and month in descending order.
Edge Case Handling: Incidents overlapping the calculation window are adjusted to fit within the period.

TODO for the next Issue:

Add filters for the GET request to allow querying specific components or timeframes.

Impact:

This feature provides critical insight into the performance and reliability of components over time, aiding in monitoring and reporting efforts.

Tests:

`status-dashboard-v3$ go test ./internal/api/v2/... -v
=== RUN TestGetIncidentsHandler
v2_test.go:22: start initialisation
2024-11-26T12:59:12.619+0100 DEBUG v2/v2.go:44 retrieve incidents

2024/11/26 12:59:12 status-dashboard-v3/internal/db/db.go:64
[0.048ms] [rows:2] SELECT * FROM "incident_component_relation" WHERE "incident_component_relation"."incident_id" IN (1,2)

2024/11/26 12:59:12 status-dashboard-v3/internal/db/db.go:64
[0.026ms] [rows:2] SELECT "id" FROM "component" WHERE "component"."id" IN (150,151)

2024/11/26 12:59:12 status-dashboard-v3/internal/db/db.go:64
[0.015ms] [rows:2] SELECT * FROM "incident_status" WHERE "incident_status"."incident_id" IN (1,2)

2024/11/26 12:59:12 status-dashboard-v3/internal/db/db.go:64
[0.662ms] [rows:2] SELECT * FROM "incident"
[GIN] 2024/11/26 - 12:59:12 | 200 | 775.692µs | | GET "/v2/incidents"
--- PASS: TestGetIncidentsHandler (0.00s)
=== RUN TestReturn404Handler
v2_test.go:44: start initialisation
[GIN] 2024/11/26 - 12:59:12 | 404 | 4.491µs | | GET "/anyendpoint"
--- PASS: TestReturn404Handler (0.00s)
=== RUN TestGetComponentsAvailabilityHandler
v2_test.go:57: start initialisation
2024-11-26T12:59:12.620+0100 DEBUG v2/v2.go:390 retrieve availability of components
[GIN] 2024/11/26 - 12:59:12 | 200 | 520.714µs | | GET "/v2/availability"
--- PASS: TestGetComponentsAvailabilityHandler (0.00s)
=== RUN TestCalculateAvailability
v2_test.go:162: Test 'Test case: September (66.66667%)- October (94.08602%)': Calculated availability: [{Year:2023 Month:12 Percentage:100} {Year:2024 Month:1 Percentage:100} {Year:2024 Month:2 Percentage:100} {Year:2024 Month:3 Percentage:100} {Year:2024 Month:4 Percentage:100} {Year:2024 Month:5 Percentage:100} {Year:2024 Month:6 Percentage:100} {Year:2024 Month:7 Percentage:100} {Year:2024 Month:8 Percentage:100} {Year:2024 Month:9 Percentage:66.66667} {Year:2024 Month:10 Percentage:94.08602} {Year:2024 Month:11 Percentage:100}]
--- PASS: TestCalculateAvailability (0.00s)
PASS
ok github.com/stackmon/otc-status-dashboard/internal/api/v2 0.005s`

@bakhterets bakhterets requested a review from sgmv November 26, 2024 12:01
@bakhterets bakhterets self-assigned this Nov 26, 2024
@sgmv sgmv added the gate Gate PR with Zuul label Dec 9, 2024
@otc-zuul otc-zuul bot merged commit 889c6a1 into main Dec 9, 2024
8 checks passed
@otc-zuul otc-zuul bot deleted the feature/availability branch December 9, 2024 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gate Gate PR with Zuul
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants