From 8c5caa4f2659436558cc766318e8faba3b69e6a0 Mon Sep 17 00:00:00 2001 From: Sam Lucidi Date: Mon, 9 Oct 2023 16:45:29 -0400 Subject: [PATCH] Inc assessment counter when a new one is created Fixes https://github.com/konveyor/tackle2-hub/issues/510 Signed-off-by: Sam Lucidi --- api/application.go | 6 ++++++ api/archetype.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/api/application.go b/api/application.go index c0e982347..2ef87ef0a 100644 --- a/api/application.go +++ b/api/application.go @@ -4,6 +4,7 @@ import ( "encoding/json" "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/assessment" + "github.com/konveyor/tackle2-hub/metrics" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm/clause" "net/http" @@ -1074,6 +1075,7 @@ func (h ApplicationHandler) AssessmentCreate(ctx *gin.Context) { m.CreateUser = h.CurrentUser(ctx) // if sections aren't empty that indicates that this assessment is being // created "as-is" and should not have its sections populated or autofilled. + newAssessment := false if len(m.Sections) == 0 { m.Sections = q.Sections resolver, rErr := assessment.NewTagResolver(h.DB(ctx)) @@ -1082,12 +1084,16 @@ func (h ApplicationHandler) AssessmentCreate(ctx *gin.Context) { return } assessment.PrepareForApplication(resolver, application, m) + newAssessment = true } result = h.DB(ctx).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } + if newAssessment { + metrics.AssessmentsInitiated.Inc() + } r.With(m) h.Respond(ctx, http.StatusCreated, r) diff --git a/api/archetype.go b/api/archetype.go index bb605a545..f15a7b68b 100644 --- a/api/archetype.go +++ b/api/archetype.go @@ -3,6 +3,7 @@ package api import ( "github.com/gin-gonic/gin" "github.com/konveyor/tackle2-hub/assessment" + "github.com/konveyor/tackle2-hub/metrics" "github.com/konveyor/tackle2-hub/model" "gorm.io/gorm/clause" "net/http" @@ -317,6 +318,7 @@ func (h ArchetypeHandler) AssessmentCreate(ctx *gin.Context) { m.CreateUser = h.CurrentUser(ctx) // if sections aren't empty that indicates that this assessment is being // created "as-is" and should not have its sections populated or autofilled. + newAssessment := false if len(m.Sections) == 0 { m.Sections = q.Sections resolver, rErr := assessment.NewTagResolver(h.DB(ctx)) @@ -325,12 +327,16 @@ func (h ArchetypeHandler) AssessmentCreate(ctx *gin.Context) { return } assessment.PrepareForArchetype(resolver, archetype, m) + newAssessment = true } result = h.DB(ctx).Create(m) if result.Error != nil { _ = ctx.Error(result.Error) return } + if newAssessment { + metrics.AssessmentsInitiated.Inc() + } r.With(m) h.Respond(ctx, http.StatusCreated, r)