From db5bdbc3324dc4c625c527ce7ce1151e1a3a8232 Mon Sep 17 00:00:00 2001 From: Ilia Bakhterev Date: Tue, 8 Apr 2025 14:05:19 +0200 Subject: [PATCH 1/3] availability impact filter added "2" nanoseconds in the tsts truncated to microseconds --- internal/api/v2/v2.go | 2 +- tests/v2_test.go | 47 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/internal/api/v2/v2.go b/internal/api/v2/v2.go index 17f838d..324cfa6 100644 --- a/internal/api/v2/v2.go +++ b/internal/api/v2/v2.go @@ -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 } diff --git a/tests/v2_test.go b/tests/v2_test.go index dbe8219..4f9fbe1 100644 --- a/tests/v2_test.go +++ b/tests/v2_test.go @@ -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) @@ -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) @@ -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() @@ -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") @@ -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, @@ -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() @@ -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 { From f4a99a75b5b4507b1d14c0a403669d63e03b8fd1 Mon Sep 17 00:00:00 2001 From: Sergei Martynov Date: Wed, 9 Apr 2025 13:27:05 +0200 Subject: [PATCH 2/3] fix manual job --- .../workflows/docker-build-push-on-draft.yaml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker-build-push-on-draft.yaml b/.github/workflows/docker-build-push-on-draft.yaml index 95c210f..9519544 100644 --- a/.github/workflows/docker-build-push-on-draft.yaml +++ b/.github/workflows/docker-build-push-on-draft.yaml @@ -1,8 +1,13 @@ name: Docker Image Build on manual trigger on: - release: - types: [published] + pull_request: + types: + - opened + - edited + - reopened + - synchronize + workflow_dispatch: env: @@ -10,12 +15,13 @@ env: PROJECT: status-dashboard-v3-api jobs: - push_if_tag: + push_manual: + # if: github.event.pull_request.merged == true runs-on: ubuntu-latest - + steps: - uses: actions/checkout@v4 - + - name: Docker meta id: meta uses: docker/metadata-action@v5 @@ -48,6 +54,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 }} From 4a84e5ae96fd9373de7be0346f943bbddaaa78bf Mon Sep 17 00:00:00 2001 From: Sergei Martynov Date: Wed, 9 Apr 2025 13:36:55 +0200 Subject: [PATCH 3/3] fix manual job --- .../workflows/docker-build-push-on-draft.yaml | 46 +++++++++++++++---- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/.github/workflows/docker-build-push-on-draft.yaml b/.github/workflows/docker-build-push-on-draft.yaml index 9519544..a877305 100644 --- a/.github/workflows/docker-build-push-on-draft.yaml +++ b/.github/workflows/docker-build-push-on-draft.yaml @@ -1,22 +1,48 @@ name: Docker Image Build on manual trigger on: - pull_request: - types: - - opened - - edited - - reopened - - synchronize - workflow_dispatch: env: - ORG: opentelekomcloud - PROJECT: status-dashboard-v3-api + ORG: stackmon + PROJECT: status-dashboard-v3 jobs: + + 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: - # if: github.event.pull_request.merged == true runs-on: ubuntu-latest steps: