Skip to content

Commit

Permalink
Read cluster_id from env variable and add it to summary data (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
seswarrajan authored Nov 21, 2022
1 parent 5d6133b commit 5fab626
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
13 changes: 11 additions & 2 deletions src/config/configManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"os"
"strconv"

types "github.com/accuknox/auto-policy-discovery/src/types"
"github.com/spf13/viper"
Expand Down Expand Up @@ -120,8 +121,12 @@ func LoadConfigFromFile() {
CurrentCfg.Status = 1 // 1: active 0: inactive

// Load cluster related config
workspaceId, _ := strconv.ParseInt(os.Getenv("workspace_id"), 0, 32)
clusterId, _ := strconv.ParseInt(os.Getenv("cluster_id"), 0, 32)

CurrentCfg.ClusterName = os.Getenv("cluster_name")
CurrentCfg.WorkspaceID = os.Getenv("workspace_id")
CurrentCfg.WorkspaceID = int32(workspaceId)
CurrentCfg.ClusterID = int32(clusterId)

// load network policy discovery
CurrentCfg.ConfigNetPolicy = types.ConfigNetworkPolicy{
Expand Down Expand Up @@ -233,10 +238,14 @@ func GetCfgClusterName() string {
return CurrentCfg.ClusterName
}

func GetCfgWorkspaceId() string {
func GetCfgWorkspaceId() int32 {
return CurrentCfg.WorkspaceID
}

func GetCfgClusterId() int32 {
return CurrentCfg.ClusterID
}

// ============================= //
// == Get Network Config Info == //
// ============================= //
Expand Down
2 changes: 1 addition & 1 deletion src/libs/dbHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ func getSysSummarySQL(db *sql.DB, dbName string, filterOptions types.SystemSumma
concatWhereClause(&whereClause, "cluster_name")
args = append(args, filterOptions.ClusterName)
}
if filterOptions.ClusterId != "" {
if filterOptions.ClusterId != 0 {
concatWhereClause(&whereClause, "cluster_id")
args = append(args, filterOptions.ClusterId)
}
Expand Down
4 changes: 1 addition & 3 deletions src/observability/consumer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package observability

import (
"strconv"
"sync"

ppb "github.com/accuknox/auto-policy-discovery/src/protobuf/v1/publisher"
Expand Down Expand Up @@ -109,10 +108,9 @@ func validateSummaryRequest(consumer *SummaryConsumer, summary types.SystemSumma

func convertSystemSummaryToGrpcResponse(summary *types.SystemSummary) *ppb.SummaryResponse {

clusterId, _ := strconv.ParseInt(summary.ClusterId, 0, 32)
return &ppb.SummaryResponse{
ClusterName: summary.ClusterName,
ClusterId: int32(clusterId),
ClusterId: summary.ClusterId,
NamespaceName: summary.NamespaceName,
NamespaceId: summary.NamespaceId,
ContainerName: summary.ContainerName,
Expand Down
5 changes: 2 additions & 3 deletions src/observability/summarizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ func convertSysLogToSysSummaryMap(syslogs []*pb.Log) {
sysSummary.ClusterName = config.GetCfgClusterName()
}

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

sysSummary.WorkspaceId = int32(workspaceId)
sysSummary.WorkspaceId = config.GetCfgWorkspaceId()
sysSummary.ClusterId = config.GetCfgClusterId()
sysSummary.NamespaceName = syslog.NamespaceName
sysSummary.ContainerName = syslog.ContainerName
sysSummary.ContainerImage = syslog.ContainerImage
Expand Down
3 changes: 2 additions & 1 deletion src/types/configData.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ type Configuration struct {
Status int `json:"status,omitempty" bson:"status,omitempty"`

ClusterName string `json:"cluster_name,omitempty" bson:"cluster_name,omitempty"`
WorkspaceID string `json:"workspace_id,omitempty" bson:"workspace_id,omitempty"`
WorkspaceID int32 `json:"workspace_id,omitempty" bson:"workspace_id,omitempty"`
ClusterID int32 `json:"cluster_id,omitempty" bson:"cluster_id,omitempty"`

ConfigDB ConfigDB `json:"config_db,omitempty" bson:"config_db,omitempty"`
ConfigCiliumHubble ConfigCiliumHubble `json:"config_cilium_hubble,omitempty" bson:"config_cilium_hubble,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion src/types/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type NetworkSummary struct {

type SystemSummary struct {
ClusterName string `json:"ClusterName,omitempty"`
ClusterId string `json:"ClusterId,omitempty"`
ClusterId int32 `json:"ClusterId,omitempty"`
WorkspaceId int32 `json:"WorkspaceId,omitempty"`
NamespaceName string `json:"Namespace,omitempty"`
NamespaceId int32 `json:"NamespaceId,omitempty"`
Expand Down

0 comments on commit 5fab626

Please sign in to comment.