From 9447a1f844add9346eadcb5f9f59db7706c28d96 Mon Sep 17 00:00:00 2001 From: Eswar Rajan Subramanian Date: Mon, 14 Nov 2022 11:18:53 +0530 Subject: [PATCH 1/2] Add WorkspaceId to publisher proto Signed-off-by: Eswar Rajan Subramanian --- src/observability/summarizer.go | 4 ++- src/protobuf/v1/publisher/publisher.pb.go | 34 +++++++++++++++-------- src/protobuf/v1/publisher/publisher.proto | 1 + src/types/observability.go | 5 ++-- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/observability/summarizer.go b/src/observability/summarizer.go index f8e684be..eca0d625 100644 --- a/src/observability/summarizer.go +++ b/src/observability/summarizer.go @@ -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 diff --git a/src/protobuf/v1/publisher/publisher.pb.go b/src/protobuf/v1/publisher/publisher.pb.go index 19720fa6..5e348e9d 100644 --- a/src/protobuf/v1/publisher/publisher.pb.go +++ b/src/protobuf/v1/publisher/publisher.pb.go @@ -135,6 +135,7 @@ type SummaryResponse struct { Action string `protobuf:"bytes,21,opt,name=Action,proto3" json:"Action,omitempty"` Count int32 `protobuf:"varint,22,opt,name=Count,proto3" json:"Count,omitempty"` UpdatedTime int64 `protobuf:"varint,23,opt,name=UpdatedTime,proto3" json:"UpdatedTime,omitempty"` + WorkspaceId int32 `protobuf:"varint,24,opt,name=WorkspaceId,proto3" json:"WorkspaceId,omitempty"` } func (x *SummaryResponse) Reset() { @@ -330,6 +331,13 @@ func (x *SummaryResponse) GetUpdatedTime() int64 { return 0 } +func (x *SummaryResponse) GetWorkspaceId() int32 { + if x != nil { + return x.WorkspaceId + } + return 0 +} + var File_v1_publisher_publisher_proto protoreflect.FileDescriptor var file_v1_publisher_publisher_proto_rawDesc = []byte{ @@ -348,7 +356,7 @@ var file_v1_publisher_publisher_proto_rawDesc = []byte{ 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x44, 0x65, 0x70, 0x6c, 0x6f, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x4f, 0x70, - 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0xbf, 0x05, 0x0a, 0x0f, 0x53, 0x75, 0x6d, 0x6d, + 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0xe1, 0x05, 0x0a, 0x0f, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1c, 0x0a, @@ -392,17 +400,19 @@ var file_v1_publisher_publisher_proto_rawDesc = []byte{ 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x16, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x20, 0x0a, 0x0b, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x18, 0x17, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x55, 0x70, - 0x64, 0x61, 0x74, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x32, 0x58, 0x0a, 0x09, 0x50, 0x75, 0x62, - 0x6c, 0x69, 0x73, 0x68, 0x65, 0x72, 0x12, 0x4b, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x53, 0x75, 0x6d, - 0x6d, 0x61, 0x72, 0x79, 0x12, 0x1c, 0x2e, 0x76, 0x31, 0x2e, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, - 0x68, 0x65, 0x72, 0x2e, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x76, 0x31, 0x2e, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, - 0x72, 0x2e, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x30, 0x01, 0x42, 0x41, 0x5a, 0x3f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x6b, 0x75, 0x62, 0x65, 0x61, 0x72, 0x6d, 0x6f, 0x72, 0x2f, 0x64, 0x69, 0x73, 0x63, - 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2d, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2f, 0x73, 0x72, 0x63, - 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x31, 0x2f, 0x70, 0x75, 0x62, - 0x6c, 0x69, 0x73, 0x68, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x64, 0x61, 0x74, 0x65, 0x64, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x57, 0x6f, 0x72, + 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x18, 0x18, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0b, + 0x57, 0x6f, 0x72, 0x6b, 0x73, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x32, 0x58, 0x0a, 0x09, 0x50, + 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, 0x72, 0x12, 0x4b, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x53, + 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x1c, 0x2e, 0x76, 0x31, 0x2e, 0x70, 0x75, 0x62, 0x6c, + 0x69, 0x73, 0x68, 0x65, 0x72, 0x2e, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x76, 0x31, 0x2e, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, + 0x68, 0x65, 0x72, 0x2e, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x30, 0x01, 0x42, 0x41, 0x5a, 0x3f, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x6b, 0x75, 0x62, 0x65, 0x61, 0x72, 0x6d, 0x6f, 0x72, 0x2f, 0x64, 0x69, + 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2d, 0x65, 0x6e, 0x67, 0x69, 0x6e, 0x65, 0x2f, 0x73, + 0x72, 0x63, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x76, 0x31, 0x2f, 0x70, + 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x65, 0x72, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/src/protobuf/v1/publisher/publisher.proto b/src/protobuf/v1/publisher/publisher.proto index fec0f1aa..2c6c6dfc 100644 --- a/src/protobuf/v1/publisher/publisher.proto +++ b/src/protobuf/v1/publisher/publisher.proto @@ -41,4 +41,5 @@ message SummaryResponse{ string Action = 21; int32 Count = 22; int64 UpdatedTime = 23; + int32 WorkspaceId = 24; } diff --git a/src/types/observability.go b/src/types/observability.go index 49a6b5f2..0973af06 100644 --- a/src/types/observability.go +++ b/src/types/observability.go @@ -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"` @@ -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"` @@ -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"` From c76a6304ab7ee82752e79645f514afa645edcbd3 Mon Sep 17 00:00:00 2001 From: Eswar Rajan Subramanian Date: Mon, 14 Nov 2022 11:27:31 +0530 Subject: [PATCH 2/2] Add workspaceId to DB Signed-off-by: Eswar Rajan Subramanian --- src/libs/dbHandler.go | 8 +++++--- src/libs/sqliteHandler.go | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/dbHandler.go b/src/libs/dbHandler.go index 0b0c8818..dbf16866 100644 --- a/src/libs/dbHandler.go +++ b/src/libs/dbHandler.go @@ -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 = ?` @@ -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, @@ -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 @@ -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, diff --git a/src/libs/sqliteHandler.go b/src/libs/sqliteHandler.go index a209539f..400ec3b8 100644 --- a/src/libs/sqliteHandler.go +++ b/src/libs/sqliteHandler.go @@ -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," +