Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Workspace Id to publisher proto #590

Merged
merged 2 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/libs/dbHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ func UpsertSystemSummary(cfg types.ConfigDB, summaryMap map[types.SystemSummary]
}

func upsertSysSummarySQL(db *sql.DB, summary types.SystemSummary, timeCount types.SysSummaryTimeCount) error {
queryString := `cluster_name = ? and cluster_id = ? and namespace_name = ? and namespace_id = ? and container_name = ? and container_image = ?
queryString := `cluster_name = ? and cluster_id = ? and workspace_id = ? and namespace_name = ? and namespace_id = ? and container_name = ? and container_image = ?
and container_id = ? and podname = ? and operation = ? and labels = ? and deployment_name = ? and source = ? and destination = ?
and destination_namespace = ? and destination_labels = ? and type = ? and ip = ? and port = ? and protocol = ? and action = ?`

Expand All @@ -418,6 +418,7 @@ func upsertSysSummarySQL(db *sql.DB, summary types.SystemSummary, timeCount type
timeCount.UpdatedTime,
summary.ClusterName,
summary.ClusterId,
summary.WorkspaceId,
summary.NamespaceName,
summary.NamespaceId,
summary.ContainerName,
Expand Down Expand Up @@ -446,8 +447,8 @@ func upsertSysSummarySQL(db *sql.DB, summary types.SystemSummary, timeCount type

if err == nil && rowsAffected == 0 {

insertQueryString := `(cluster_name,cluster_id,namespace_name,namespace_id,container_name,container_image,container_id,podname,operation,labels,deployment_name,
source,destination,destination_namespace,destination_labels,type,ip,port,protocol,action,count,updated_time) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`
insertQueryString := `(cluster_name,cluster_id,workspace_id,namespace_name,namespace_id,container_name,container_image,container_id,podname,operation,labels,deployment_name,
source,destination,destination_namespace,destination_labels,type,ip,port,protocol,action,count,updated_time) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)`

insertQuery := "INSERT INTO " + TableSystemSummarySQLite + insertQueryString

Expand All @@ -460,6 +461,7 @@ func upsertSysSummarySQL(db *sql.DB, summary types.SystemSummary, timeCount type
_, err = insertStmt.Exec(
summary.ClusterName,
summary.ClusterId,
summary.WorkspaceId,
summary.NamespaceName,
summary.NamespaceId,
summary.ContainerName,
Expand Down
1 change: 1 addition & 0 deletions src/libs/sqliteHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ func CreateSystemSummaryTableSQLite(cfg types.ConfigDB) error {
" `id` INTEGER AUTO_INCREMENT," +
" `cluster_name` varchar(50) DEFAULT NULL," +
" `cluster_id` int DEFAULT NULL," +
" `workspace_id` int DEFAULT NULL," +
" `namespace_name` varchar(50) DEFAULT NULL," +
" `namespace_id` int DEFAULT NULL," +
" `container_name` varchar(50) DEFAULT NULL," +
Expand Down
4 changes: 3 additions & 1 deletion src/observability/summarizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ func convertSysLogToSysSummaryMap(syslogs []*pb.Log) {
sysSummary.ClusterName = config.GetCfgClusterName()
}

sysSummary.ClusterId = config.GetCfgWorkspaceId()
workspaceId, _ := strconv.ParseInt(config.GetCfgWorkspaceId(), 0, 32)

sysSummary.WorkspaceId = int32(workspaceId)
sysSummary.NamespaceName = syslog.NamespaceName
sysSummary.ContainerName = syslog.ContainerName
sysSummary.ContainerImage = syslog.ContainerImage
Expand Down
34 changes: 22 additions & 12 deletions src/protobuf/v1/publisher/publisher.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/protobuf/v1/publisher/publisher.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ message SummaryResponse{
string Action = 21;
int32 Count = 22;
int64 UpdatedTime = 23;
int32 WorkspaceId = 24;
}
5 changes: 3 additions & 2 deletions src/types/observability.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package types

//KubeArmor - Structure for KubeArmor Logs Flow
// KubeArmor - Structure for KubeArmor Logs Flow
type KubeArmor struct {
ClusterName string `json:"cluster_name,omitempty"`
HostName string `json:"host_name,omitempty"`
Expand All @@ -20,7 +20,7 @@ type KubeArmor struct {
Total int64 `json:"total,omitempty"`
}

//Cilium - Structure for Hubble Log Flow
// Cilium - Structure for Hubble Log Flow
type CiliumLog struct {
Verdict string `json:"verdict,omitempty"`
IpSource string `json:"ip_source,omitempty"`
Expand Down Expand Up @@ -98,6 +98,7 @@ type NetworkSummary struct {
type SystemSummary struct {
ClusterName string `json:"ClusterName,omitempty"`
ClusterId string `json:"ClusterId,omitempty"`
WorkspaceId int32 `json:"WorkspaceId,omitempty"`
NamespaceName string `json:"Namespace,omitempty"`
NamespaceId int32 `json:"NamespaceId,omitempty"`
ContainerName string `json:"ContainerName,omitempty"`
Expand Down