From 74791eb94ddf22ad5fc5ce39232005e7e574e064 Mon Sep 17 00:00:00 2001 From: Michal Krzyz Date: Wed, 13 Nov 2024 14:56:54 +0100 Subject: [PATCH] Rebase --- go.mod | 2 +- internal/api/graphql/graph/model/models.go | 2 +- ...ithMetadata.graphql => withIssueMetadata.graphql} | 2 +- ...hMetadata.graphql => withServiceMetadata.graphql} | 4 ++-- internal/database/mariadb/entity.go | 12 ++++++++---- internal/database/mariadb/init/schema.sql | 2 +- internal/e2e/issue_query_test.go | 12 ++++++------ internal/e2e/service_query_test.go | 6 +++--- internal/entity/common.go | 1 - internal/entity/component.go | 2 -- internal/entity/service.go | 2 -- internal/entity/support_group.go | 2 -- 12 files changed, 23 insertions(+), 26 deletions(-) rename internal/api/graphql/graph/queryCollection/issue/{withMetadata.graphql => withIssueMetadata.graphql} (97%) rename internal/api/graphql/graph/queryCollection/service/{withMetadata.graphql => withServiceMetadata.graphql} (95%) diff --git a/go.mod b/go.mod index 3dd6a656..03f36829 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,7 @@ require ( github.com/samber/lo v1.47.0 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.9.0 + github.com/vektah/gqlparser/v2 v2.5.19 golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 ) @@ -85,7 +86,6 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect github.com/urfave/cli/v2 v2.27.5 // indirect - github.com/vektah/gqlparser/v2 v2.5.19 // indirect github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect go.opentelemetry.io/otel v1.24.0 // indirect diff --git a/internal/api/graphql/graph/model/models.go b/internal/api/graphql/graph/model/models.go index 08f9553e..a36158c6 100644 --- a/internal/api/graphql/graph/model/models.go +++ b/internal/api/graphql/graph/model/models.go @@ -383,7 +383,7 @@ func NewServiceWithAggregations(service *entity.ServiceResult) Service { ID: fmt.Sprintf("%d", service.Id), Ccrn: &service.CCRN, ServiceMetadata: &serviceMetadata, - Metadata: getModelMetadata(s.BaseService.Metadata), + Metadata: getModelMetadata(service.BaseService.Metadata), } } diff --git a/internal/api/graphql/graph/queryCollection/issue/withMetadata.graphql b/internal/api/graphql/graph/queryCollection/issue/withIssueMetadata.graphql similarity index 97% rename from internal/api/graphql/graph/queryCollection/issue/withMetadata.graphql rename to internal/api/graphql/graph/queryCollection/issue/withIssueMetadata.graphql index 669a1022..0d992ffe 100644 --- a/internal/api/graphql/graph/queryCollection/issue/withMetadata.graphql +++ b/internal/api/graphql/graph/queryCollection/issue/withIssueMetadata.graphql @@ -12,7 +12,7 @@ query ($filter: IssueFilter, $first: Int, $after: String) { node { id lastModified - metadata { + issueMetadata { serviceCount activityCount issueMatchCount diff --git a/internal/api/graphql/graph/queryCollection/service/withMetadata.graphql b/internal/api/graphql/graph/queryCollection/service/withServiceMetadata.graphql similarity index 95% rename from internal/api/graphql/graph/queryCollection/service/withMetadata.graphql rename to internal/api/graphql/graph/queryCollection/service/withServiceMetadata.graphql index ae54a716..642ed7cc 100644 --- a/internal/api/graphql/graph/queryCollection/service/withMetadata.graphql +++ b/internal/api/graphql/graph/queryCollection/service/withServiceMetadata.graphql @@ -22,7 +22,7 @@ query ($filter: ServiceFilter, $first: Int, $after: String) { } } } - metadata { + serviceMetadata { issueMatchCount componentInstanceCount } @@ -30,4 +30,4 @@ query ($filter: ServiceFilter, $first: Int, $after: String) { cursor } } -} \ No newline at end of file +} diff --git a/internal/database/mariadb/entity.go b/internal/database/mariadb/entity.go index b7b04e2c..6ac82558 100644 --- a/internal/database/mariadb/entity.go +++ b/internal/database/mariadb/entity.go @@ -414,8 +414,10 @@ func (ivwr *IssueVariantWithRepository) AsIssueVariantEntry() entity.IssueVarian Description: GetStringValue(ivwr.Description), Metadata: entity.Metadata{ CreatedAt: GetTimeValue(ivwr.IssueVariantRow.CreatedAt), + CreatedBy: GetInt64Value(ivwr.CreatedBy), DeletedAt: GetTimeValue(ivwr.IssueVariantRow.DeletedAt), UpdatedAt: GetTimeValue(ivwr.IssueVariantRow.UpdatedAt), + UpdatedBy: GetInt64Value(ivwr.UpdatedBy), }, } } @@ -437,10 +439,12 @@ func (siv *ServiceIssueVariantRow) AsServiceIssueVariantEntry() entity.ServiceIs Issue: nil, Severity: entity.NewSeverity(GetStringValue(siv.Vector)), Description: GetStringValue(siv.Description), - Info: entity.Info{ - CreatedAt: GetTimeValue(siv.IssueVariantRow.CreatedAt), - DeletedAt: GetTimeValue(siv.IssueVariantRow.DeletedAt), - UpdatedAt: GetTimeValue(siv.IssueVariantRow.UpdatedAt), + Metadata: entity.Metadata{ + CreatedAt: GetTimeValue(siv.IssueVariantRow.CreatedAt), + CreatedBy: GetInt64Value(siv.CreatedBy), + DeletedAt: GetTimeValue(siv.IssueVariantRow.DeletedAt), + UpdatedAt: GetTimeValue(siv.IssueVariantRow.UpdatedAt), + UpdatedBy: GetInt64Value(siv.UpdatedBy), }, }, ServiceId: GetInt64Value(siv.IssueRepositoryServiceRow.ServiceId), diff --git a/internal/database/mariadb/init/schema.sql b/internal/database/mariadb/init/schema.sql index dc4e189e..995d1fbe 100644 --- a/internal/database/mariadb/init/schema.sql +++ b/internal/database/mariadb/init/schema.sql @@ -49,7 +49,7 @@ create table if not exists Component constraint id_UNIQUE unique (component_id), constraint component_ccrn_UNIQUE - unique (component_ccrn) + unique (component_ccrn), constraint fk_component_created_by foreign key (component_created_by) references User (user_id), constraint fk_component_updated_by diff --git a/internal/e2e/issue_query_test.go b/internal/e2e/issue_query_test.go index 31f2e2d6..479c2487 100644 --- a/internal/e2e/issue_query_test.go +++ b/internal/e2e/issue_query_test.go @@ -199,13 +199,13 @@ var _ = Describe("Getting Issues via API", Label("e2e", "Issues"), func() { Expect(*respData.Issues.PageInfo.PageNumber).To(Equal(1), "Correct page number") }) }) - Context("and we request metadata", Label("withMetadata.graphql"), func() { + Context("and we request metadata", Label("withIssueMetadata.graphql"), func() { It("returns correct metadata counts", func() { // create a queryCollection (safe to share across requests) client := graphql.NewClient(fmt.Sprintf("http://localhost:%s/query", cfg.Port)) //@todo may need to make this more fault proof?! What if the test is executed from the root dir? does it still work? - b, err := os.ReadFile("../api/graphql/graph/queryCollection/issue/withMetadata.graphql") + b, err := os.ReadFile("../api/graphql/graph/queryCollection/issue/withIssueMetadata.graphql") Expect(err).To(BeNil()) str := string(b) @@ -232,10 +232,10 @@ var _ = Describe("Getting Issues via API", Label("e2e", "Issues"), func() { ciCount += *imEdge.Node.ComponentInstance.Count serviceIdSet[imEdge.Node.ComponentInstance.Service.ID] = true } - Expect(issueEdge.Node.Metadata.IssueMatchCount).To(Equal(issueEdge.Node.IssueMatches.TotalCount), "IssueMatchCount is correct") - Expect(issueEdge.Node.Metadata.ComponentInstanceCount).To(Equal(ciCount), "ComponentInstanceCount is correct") - Expect(issueEdge.Node.Metadata.ActivityCount).To(Equal(issueEdge.Node.Activities.TotalCount), "ActivityCount is correct") - Expect(issueEdge.Node.Metadata.ServiceCount).To(Equal(len(serviceIdSet)), "ServiceCount is correct") + Expect(issueEdge.Node.IssueMetadata.IssueMatchCount).To(Equal(issueEdge.Node.IssueMatches.TotalCount), "IssueMatchCount is correct") + Expect(issueEdge.Node.IssueMetadata.ComponentInstanceCount).To(Equal(ciCount), "ComponentInstanceCount is correct") + Expect(issueEdge.Node.IssueMetadata.ActivityCount).To(Equal(issueEdge.Node.Activities.TotalCount), "ActivityCount is correct") + Expect(issueEdge.Node.IssueMetadata.ServiceCount).To(Equal(len(serviceIdSet)), "ServiceCount is correct") } }) }) diff --git a/internal/e2e/service_query_test.go b/internal/e2e/service_query_test.go index b7b46656..01f0a608 100644 --- a/internal/e2e/service_query_test.go +++ b/internal/e2e/service_query_test.go @@ -119,7 +119,7 @@ var _ = Describe("Getting Services via API", Label("e2e", "Services"), func() { client := graphql.NewClient(fmt.Sprintf("http://localhost:%s/query", cfg.Port)) //@todo may need to make this more fault proof?! What if the test is executed from the root dir? does it still work? - b, err := os.ReadFile("../api/graphql/graph/queryCollection/service/withMetadata.graphql") + b, err := os.ReadFile("../api/graphql/graph/queryCollection/service/withServiceMetadata.graphql") Expect(err).To(BeNil()) str := string(b) @@ -146,8 +146,8 @@ var _ = Describe("Getting Services via API", Label("e2e", "Services"), func() { imCount += ciEdge.Node.IssueMatches.TotalCount ciCount += *ciEdge.Node.Count } - Expect(serviceEdge.Node.Metadata.IssueMatchCount).To(Equal(imCount)) - Expect(serviceEdge.Node.Metadata.ComponentInstanceCount).To(Equal(ciCount)) + Expect(serviceEdge.Node.ServiceMetadata.IssueMatchCount).To(Equal(imCount)) + Expect(serviceEdge.Node.ServiceMetadata.ComponentInstanceCount).To(Equal(ciCount)) } }) diff --git a/internal/entity/common.go b/internal/entity/common.go index ffa06728..f0d26d0f 100644 --- a/internal/entity/common.go +++ b/internal/entity/common.go @@ -34,7 +34,6 @@ type HeurekaEntity interface { ComponentAggregations | ComponentInstance | ComponentInstanceAggregations | - ComponentInstance | ComponentVersion | ComponentVersionAggregations | Evidence | diff --git a/internal/entity/component.go b/internal/entity/component.go index a5d36fcc..24346f01 100644 --- a/internal/entity/component.go +++ b/internal/entity/component.go @@ -3,8 +3,6 @@ package entity -import "time" - type Component struct { Metadata Id int64 `json:"id"` diff --git a/internal/entity/service.go b/internal/entity/service.go index 6143396d..2c96629e 100644 --- a/internal/entity/service.go +++ b/internal/entity/service.go @@ -3,8 +3,6 @@ package entity -import "time" - type BaseService struct { Metadata Id int64 `json:"id"` diff --git a/internal/entity/support_group.go b/internal/entity/support_group.go index 75382eb3..c38f24c9 100644 --- a/internal/entity/support_group.go +++ b/internal/entity/support_group.go @@ -3,8 +3,6 @@ package entity -import "time" - type SupportGroup struct { Metadata Id int64 `json:"id"`