Skip to content

Commit

Permalink
feat: integrations view (#362)
Browse files Browse the repository at this point in the history
* feat: integrations view

* chore: address review comments
  • Loading branch information
adityathebe authored Dec 12, 2023
1 parent 987e8c5 commit 65b6c29
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 3 deletions.
43 changes: 43 additions & 0 deletions models/integrations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package models

import (
"time"

"github.com/google/uuid"
)

type IntegrationType string

const (
IntegrationTypeScraper IntegrationType = "scrapers"
IntegrationTypeLoggingBackends IntegrationType = "logging_backends"
IntegrationTypeTopology IntegrationType = "topology"
)

type Integration struct {
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Integration IntegrationType `json:"integration"`
Source string `json:"source"`
AgentID *uuid.UUID `json:"agent_id,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *time.Time `json:"deleted_at,omitempty"`
CreatedBy *uuid.UUID `json:"created_by,omitempty"`
JobName string `json:"job_name"`
JobSuccess int `json:"job_success_count"`
JobError int `json:"job_error_count"`
JobDetails string `json:"job_details"`
JobHostname string `json:"job_hostname"`
JobDuration int `json:"job_duration_millis"`
JobResource string `json:"job_resource_type"`
JobStatus string `json:"job_status"`
JobTimeStart time.Time `json:"job_time_start"`
JobTimeEnd time.Time `json:"job_time_end"`
JobCreatedAt time.Time `json:"job_created_at"`
}

func (t *Integration) TableName() string {
return "integrations_with_status"
}
1 change: 1 addition & 0 deletions models/logging_backends.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type LoggingBackend struct {
Labels types.JSONStringMap `json:"labels" gorm:"type:jsonstringmap"`
Spec string `json:"spec,omitempty"`
Source string `json:"source,omitempty"`
AgentID *uuid.UUID `json:"agent_id,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
DeletedAt *time.Time `json:"deleted_at,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions models/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ const (
SourceCRD = "KubernetesCRD"
SourceConfigFile = "ConfigFile"
SourceUI = "UI"
SourceTopology = "Topology"
)
1 change: 1 addition & 0 deletions models/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Topology struct {
Name string
Namespace string
Labels types.JSONStringMap `json:"labels,omitempty" gorm:"default:null"`
Source string `json:"source"`
Spec types.JSON `gorm:"default:null"`
Schedule *string
CreatedAt *time.Time `json:"created_at,omitempty" time_format:"postgres_timestamp"`
Expand Down
5 changes: 5 additions & 0 deletions schema/components.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ table "topologies" {
null = true
type = jsonb
}
column "source" {
null = false
type = enum.source
default = "Topology"
}
column "spec" {
null = true
type = jsonb
Expand Down
6 changes: 5 additions & 1 deletion schema/logging_backends.hcl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
enum "source" {
schema = schema.public
values = ["KubernetesCRD", "ConfigFile", "UI"]
values = ["KubernetesCRD", "ConfigFile", "UI", "Topology"]
}

table "logging_backends" {
Expand All @@ -26,6 +26,10 @@ table "logging_backends" {
null = true
type = enum.source
}
column "agent_id" {
null = true
type = uuid
}
column "created_at" {
null = true
type = timestamptz
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/dummy/topologies.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var LogisticsTopology = models.Topology{
ID: uuid.MustParse("df39086e-506b-4ad9-9af7-baf5275c382b"),
Name: "logistics",
Namespace: "default",
Source: models.SourceUI,
}

var AllDummyTopologies = []models.Topology{
Expand Down
17 changes: 17 additions & 0 deletions tests/integrations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package tests

import (
"github.com/flanksource/duty/models"
"github.com/flanksource/duty/testutils"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Integration view", func() {
It("should be able to call integrations view", func() {
var integrations []models.Integration
err := testutils.DefaultContext.DB().Find(&integrations).Error
Expect(err).ToNot(HaveOccurred())
Expect(len(integrations)).To(BeNumerically(">", 0))
})
})
5 changes: 3 additions & 2 deletions views/015_job_history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ FROM
AND job_history.created_at = latest_job_history.max_created_at;

-- Topologies with job status
DROP VIEW IF EXISTS topologies_with_status;
DROP VIEW IF EXISTS topologies_with_status CASCADE;

CREATE OR REPLACE VIEW
topologies_with_status AS
SELECT
Expand Down Expand Up @@ -104,7 +105,7 @@ WHERE
teams.deleted_at IS NULL;

-- Config scrapers View
DROP VIEW IF EXISTS config_scrapers_with_status;
DROP VIEW IF EXISTS config_scrapers_with_status CASCADE;

CREATE OR REPLACE VIEW
config_scrapers_with_status AS
Expand Down
76 changes: 76 additions & 0 deletions views/024_integrations.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
CREATE
OR REPLACE VIEW integrations_with_status AS
SELECT
id,
NAME,
description,
'scrapers' AS integration_type,
source,
agent_id,
created_at,
updated_at,
deleted_at,
created_by,
job_name,
job_success_count,
job_error_count,
job_details,
job_hostname,
job_duration_millis,
job_resource_type,
job_status,
job_time_start,
job_time_end,
job_created_at
FROM
config_scrapers_with_status
UNION
SELECT
id,
NAME,
'',
'topologies' AS integration_type,
source,
agent_id,
created_at,
updated_at,
deleted_at,
created_by,
job_name,
job_success_count,
job_error_count,
job_details,
job_hostname,
job_duration_millis,
job_resource_type,
job_status,
job_time_start,
job_time_end,
job_created_at
FROM
topologies_with_status
UNION
SELECT
id,
NAME,
'',
'logging_backends' AS integration_type,
source,
agent_id,
created_at,
updated_at,
deleted_at,
created_by,
'',
0,
0,
NULL,
'',
0,
NULL,
'',
NULL,
NULL,
NULL
FROM
logging_backends;

0 comments on commit 65b6c29

Please sign in to comment.