Skip to content

Commit

Permalink
Rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
michalkrzyz committed Nov 13, 2024
1 parent 5cf6406 commit 22d26ea
Show file tree
Hide file tree
Showing 16 changed files with 58 additions and 59 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions internal/api/graphql/graph/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ func NewUserEntity(user *UserInput) entity.User {

func NewService(s *entity.Service) Service {
return Service{
ID: fmt.Sprintf("%d", s.Id),
Ccrn: &s.CCRN,
ID: fmt.Sprintf("%d", s.Id),
Ccrn: &s.CCRN,
Metadata: getModelMetadata(s.BaseService.Metadata),
}
}
Expand All @@ -380,10 +380,10 @@ func NewServiceWithAggregations(service *entity.ServiceResult) Service {
}

return Service{
ID: fmt.Sprintf("%d", service.Id),
Ccrn: &service.CCRN,
ID: fmt.Sprintf("%d", service.Id),
Ccrn: &service.CCRN,
ServiceMetadata: &serviceMetadata,
Metadata: getModelMetadata(s.BaseService.Metadata),
Metadata: getModelMetadata(service.BaseService.Metadata),
}
}

Expand All @@ -397,8 +397,8 @@ func NewServiceEntity(service *ServiceInput) entity.Service {

func NewSupportGroup(supportGroup *entity.SupportGroup) SupportGroup {
return SupportGroup{
ID: fmt.Sprintf("%d", supportGroup.Id),
Ccrn: &supportGroup.CCRN,
ID: fmt.Sprintf("%d", supportGroup.Id),
Ccrn: &supportGroup.CCRN,
Metadata: getModelMetadata(supportGroup.Metadata),
}
}
Expand Down Expand Up @@ -465,9 +465,9 @@ func NewEvidenceEntity(evidence *EvidenceInput) entity.Evidence {
func NewComponent(component *entity.Component) Component {
componentType, _ := ComponentTypeValue(component.Type)
return Component{
ID: fmt.Sprintf("%d", component.Id),
Ccrn: &component.CCRN,
Type: &componentType,
ID: fmt.Sprintf("%d", component.Id),
Ccrn: &component.CCRN,
Type: &componentType,
Metadata: getModelMetadata(component.Metadata),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ query ($filter: IssueFilter, $first: Int, $after: String) {
node {
id
lastModified
metadata {
issueMetadata {
serviceCount
activityCount
issueMatchCount
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ query ($filter: ServiceFilter, $first: Int, $after: String) {
}
}
}
metadata {
serviceMetadata {
issueMatchCount
componentInstanceCount
}
}
cursor
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
package issue_repository

import (
"github.com/sirupsen/logrus"
"github.com/cloudoperators/heureka/internal/app/event"
"github.com/cloudoperators/heureka/internal/database"
"github.com/cloudoperators/heureka/internal/entity"
"github.com/sirupsen/logrus"
)

const (
Expand Down
32 changes: 19 additions & 13 deletions internal/database/mariadb/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
}
}
Expand All @@ -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),
Expand All @@ -461,9 +465,9 @@ type ComponentRow struct {

func (cr *ComponentRow) AsComponent() entity.Component {
return entity.Component{
Id: GetInt64Value(cr.Id),
CCRN: GetStringValue(cr.CCRN),
Type: GetStringValue(cr.Type),
Id: GetInt64Value(cr.Id),
CCRN: GetStringValue(cr.CCRN),
Type: GetStringValue(cr.Type),
Metadata: entity.Metadata{
CreatedAt: GetTimeValue(cr.CreatedAt),
CreatedBy: GetInt64Value(cr.CreatedBy),
Expand Down Expand Up @@ -534,8 +538,8 @@ type SupportGroupRow struct {

func (sgr *SupportGroupRow) AsSupportGroup() entity.SupportGroup {
return entity.SupportGroup{
Id: GetInt64Value(sgr.Id),
CCRN: GetStringValue(sgr.CCRN),
Id: GetInt64Value(sgr.Id),
CCRN: GetStringValue(sgr.CCRN),
Metadata: entity.Metadata{
CreatedAt: GetTimeValue(sgr.CreatedAt),
CreatedBy: GetInt64Value(sgr.CreatedBy),
Expand Down Expand Up @@ -648,10 +652,12 @@ func (sbr *GetServicesByRow) AsServiceWithAggregations() entity.ServiceWithAggre
CCRN: GetStringValue(sbr.BaseServiceRow.CCRN),
Owners: []entity.User{},
Activities: []entity.Activity{},
Metadata: entity.Metadata{
CreatedAt: GetTimeValue(sbr.BaseServiceRow.CreatedAt),
DeletedAt: GetTimeValue(sbr.BaseServiceRow.DeletedAt),
UpdatedAt: GetTimeValue(sbr.BaseServiceRow.UpdatedAt),
Metadata: entity.Metadata{
CreatedAt: GetTimeValue(sbr.BaseServiceRow.CreatedAt),
CreatedBy: GetInt64Value(sbr.BaseServiceRow.CreatedBy),
DeletedAt: GetTimeValue(sbr.BaseServiceRow.DeletedAt),
UpdatedAt: GetTimeValue(sbr.BaseServiceRow.UpdatedAt),
UpdatedBy: GetInt64Value(sbr.BaseServiceRow.UpdatedBy),
},
},
IssueRepositoryService: entity.IssueRepositoryService{
Expand Down
2 changes: 1 addition & 1 deletion internal/database/mariadb/init/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions internal/database/mariadb/service_issue_variant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ var _ = Describe("ServiceIssueVariant - ", Label("database", "IssueVariant"), fu
BeforeEach(func() {
// Create service
services = seeder.SeedServices(1)

// Create issue
issues := seeder.SeedIssues(1)
issue = issues[0]
Expand All @@ -228,7 +228,7 @@ var _ = Describe("ServiceIssueVariant - ", Label("database", "IssueVariant"), fu
}
_, err := seeder.InsertFakeComponentVersionIssue(cvi)
Expect(err).To(BeNil())

// Create component instance
componentInstances = seeder.SeedComponentInstances(1, componentVersions, services)

Expand Down Expand Up @@ -263,13 +263,13 @@ var _ = Describe("ServiceIssueVariant - ", Label("database", "IssueVariant"), fu
It("returns all variants when filtering for the issue", func() {
filter := &entity.ServiceIssueVariantFilter{
ComponentInstanceId: []*int64{lo.ToPtr(componentInstances[0].Id.Int64)},
IssueId: []*int64{lo.ToPtr(issue.Id.Int64)},
IssueId: []*int64{lo.ToPtr(issue.Id.Int64)},
}

res, err := db.GetServiceIssueVariants(filter)
Expect(err).To(BeNil())
Expect(res).To(HaveLen(5)) // One variant per repository

// All variants should be for our issue
for _, variant := range res {
Expect(variant.IssueId).To(Equal(issue.Id.Int64))
Expand Down
12 changes: 6 additions & 6 deletions internal/e2e/issue_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
}
})
})
Expand Down
6 changes: 3 additions & 3 deletions internal/e2e/service_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
}
})

Expand Down
1 change: 0 additions & 1 deletion internal/entity/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ type HeurekaEntity interface {
ComponentAggregations |
ComponentInstance |
ComponentInstanceAggregations |
ComponentInstance |
ComponentVersion |
ComponentVersionAggregations |
Evidence |
Expand Down
8 changes: 3 additions & 5 deletions internal/entity/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@

package entity

import "time"

type Component struct {
Metadata
Id int64 `json:"id"`
CCRN string `json:"ccrn"`
Type string `json:"type"`
Id int64 `json:"id"`
CCRN string `json:"ccrn"`
Type string `json:"type"`
}

type ComponentResult struct {
Expand Down
2 changes: 0 additions & 2 deletions internal/entity/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

package entity

import "time"

type BaseService struct {
Metadata
Id int64 `json:"id"`
Expand Down
6 changes: 2 additions & 4 deletions internal/entity/support_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@

package entity

import "time"

type SupportGroup struct {
Metadata
Id int64 `json:"id"`
CCRN string `json:"ccrn"`
Id int64 `json:"id"`
CCRN string `json:"ccrn"`
}

type SupportGroupFilter struct {
Expand Down
6 changes: 3 additions & 3 deletions internal/entity/test/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (

func NewFakeComponentEntity() entity.Component {
return entity.Component{
Id: int64(gofakeit.Number(1, 10000000)),
CCRN: gofakeit.Name(),
Type: gofakeit.Word(),
Id: int64(gofakeit.Number(1, 10000000)),
CCRN: gofakeit.Name(),
Type: gofakeit.Word(),
Metadata: entity.Metadata{
CreatedAt: gofakeit.Date(),
DeletedAt: gofakeit.Date(),
Expand Down
4 changes: 2 additions & 2 deletions internal/entity/test/support_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (

func NewFakeSupportGroupEntity() entity.SupportGroup {
return entity.SupportGroup{
Id: int64(gofakeit.Number(1, 10000000)),
CCRN: gofakeit.AppName(),
Id: int64(gofakeit.Number(1, 10000000)),
CCRN: gofakeit.AppName(),
Metadata: entity.Metadata{
CreatedAt: gofakeit.Date(),
DeletedAt: gofakeit.Date(),
Expand Down

0 comments on commit 22d26ea

Please sign in to comment.