Skip to content

Prepared the availability calculation to calculate with impact 2 #59

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions .github/workflows/docker-build-push-on-draft.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,53 @@
name: Docker Image Build on manual trigger

on:
release:
types: [published]
workflow_dispatch:

env:
ORG: opentelekomcloud
PROJECT: status-dashboard-v3-api
ORG: stackmon
PROJECT: status-dashboard-v3

jobs:
push_if_tag:

build:
if: github.event.pull_request.merged == false
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
"${{ secrets.REGISTRY }}/${{ env.ORG }}/${{ env.PROJECT }}"
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: false

push_manual:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Docker meta
id: meta
uses: docker/metadata-action@v5
Expand Down Expand Up @@ -48,6 +80,3 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
push: true
build-args: |
BASE_URL=${{ secrets.BASE_URL }}
AUTH_TOKEN=${{ secrets.AUTH_TOKEN }}
2 changes: 1 addition & 1 deletion internal/api/v2/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ func calculateAvailability(component *db.Component) ([]MonthlyAvailability, erro
monthlyDowntime := make([]float64, monthsInYear) // 12 months

for _, inc := range component.Incidents {
if inc.EndDate == nil || *inc.Impact != 3 {
if inc.EndDate == nil || (*inc.Impact != 3 && *inc.Impact != 2) {
continue
}

Expand Down
47 changes: 39 additions & 8 deletions tests/v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func TestV2PostIncidentsHandler(t *testing.T) {
assert.Equal(t, len(incidents)+1, result.Result[1].IncidentID)

incident := v2GetIncident(t, r, result.Result[0].IncidentID)
assert.Equal(t, incidentCreateData.StartDate, incident.StartDate)
assert.Equal(t, incidentCreateData.StartDate.Truncate(time.Microsecond), incident.StartDate)
assert.Equal(t, title, incident.Title)
assert.Equal(t, impact, *incident.Impact)
assert.Equal(t, system, *incident.System)
Expand Down Expand Up @@ -239,8 +239,10 @@ func TestV2PostIncidentsHandler(t *testing.T) {
assert.Equal(t, len(incidents)+3, result.Result[1].IncidentID)

maintenanceIncident := v2GetIncident(t, r, result.Result[0].IncidentID)
assert.Equal(t, incidentCreateData.StartDate, maintenanceIncident.StartDate)
assert.Equal(t, incidentCreateData.EndDate, maintenanceIncident.EndDate)
assert.Equal(t, incidentCreateData.StartDate.Truncate(time.Microsecond), maintenanceIncident.StartDate)
require.NotNil(t, incidentCreateData.EndDate)
require.NotNil(t, maintenanceIncident.EndDate)
assert.Equal(t, incidentCreateData.EndDate.Truncate(time.Microsecond), maintenanceIncident.EndDate.Truncate(time.Microsecond))
assert.Equal(t, title, maintenanceIncident.Title)
assert.Equal(t, impact, *maintenanceIncident.Impact)
assert.Equal(t, system, *maintenanceIncident.System)
Expand Down Expand Up @@ -431,7 +433,8 @@ func TestV2PatchIncidentHandler(t *testing.T) {
pData.UpdateDate = updateDate

inc = internalPatch(incID, &pData)
assert.Equal(t, updateDate, *inc.EndDate)
require.NotNil(t, inc.EndDate)
assert.Equal(t, updateDate.Truncate(time.Microsecond), inc.EndDate.Truncate(time.Microsecond))

t.Logf("patching closed incident, change start date and end date")
startDate = time.Now().AddDate(0, 0, -1).UTC()
Expand All @@ -442,8 +445,9 @@ func TestV2PatchIncidentHandler(t *testing.T) {
pData.EndDate = &endDate

inc = internalPatch(incID, &pData)
assert.Equal(t, startDate, inc.StartDate)
assert.Equal(t, endDate, *inc.EndDate)
assert.Equal(t, startDate.Truncate(time.Microsecond), inc.StartDate)
require.NotNil(t, inc.EndDate)
assert.Equal(t, endDate.Truncate(time.Microsecond), inc.EndDate.Truncate(time.Microsecond))

t.Logf("reopen closed incident")

Expand Down Expand Up @@ -663,7 +667,7 @@ func TestV2GetComponentsAvailability(t *testing.T) {

title = "Test incident for dns N2"
startDate = time.Date(2024, 10, 16, 12, 0, 0, 0, time.UTC)
endDate = time.Date(2024, 11, 16, 00, 00, 00, 0, time.UTC)
endDate = time.Date(2024, 11, 16, 0, 0, 0, 0, time.UTC)

incidentCreateDataN2 := v2.IncidentData{
Title: title,
Expand All @@ -686,6 +690,33 @@ func TestV2GetComponentsAvailability(t *testing.T) {

t.Logf("Incident patched: %+v", incidentN2)

// Incident N3

title = "Test incident for dns N3"
startDate = time.Date(2025, 3, 1, 0, 0, 0, 0, time.UTC)
endDate = time.Date(2025, 3, 16, 12, 0, 0, 0, time.UTC)
impact = 3 // Different impact for N3

incidentCreateDataN3 := v2.IncidentData{
Title: title,
Impact: &impact,
Components: components,
StartDate: startDate,
EndDate: nil,
System: &system,
}
resultN3 := v2CreateIncident(t, r, &incidentCreateDataN3)
assert.Len(t, resultN3.Result, len(incidentCreateDataN3.Components))

// Incident closing

incidentN3 := v2GetIncident(t, r, resultN3.Result[0].IncidentID)

incidentN3.EndDate = &endDate
v2PatchIncident(t, r, incidentN3)

t.Logf("Incident patched: %+v", incidentN3)

// Test case 1: Successful availability listing
t.Log("Test case 1: List availability successfully")
w := httptest.NewRecorder()
Expand All @@ -703,7 +734,7 @@ func TestV2GetComponentsAvailability(t *testing.T) {
assert.NotEmpty(t, availability)

// Test case 2: Check if the availability data is correct
targetMonths := map[int]bool{10: true, 11: true, 12: true}
targetMonths := map[int]bool{3: true, 10: true, 11: true, 12: true}

for _, compAvail := range availability.Data {
if compAvail.ComponentID.ID == 7 {
Expand Down