Skip to content

Commit

Permalink
Convert all workload_type values to lowercase before comparision
Browse files Browse the repository at this point in the history
  • Loading branch information
upadhyeammit committed Dec 13, 2024
1 parent 8f3e347 commit 0e884ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
1 change: 1 addition & 0 deletions .~lock.output.csv#
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,amit,fedora,13.12.2024 18:49,file:///home/amit/.config/libreoffice/4;
34 changes: 27 additions & 7 deletions internal/utils/aggregator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func Aggregate_data(df dataframe.DataFrame) (dataframe.DataFrame, error) {
if df.Nrow() == 0 {
return df, fmt.Errorf("no valid records present in CSV to process further")
}

df = determine_k8s_object_type(df)

dfGroups := df.GroupBy(
Expand Down Expand Up @@ -82,8 +81,8 @@ func Aggregate_data(df dataframe.DataFrame) (dataframe.DataFrame, error) {
return df, nil
}

func filter_valid_csv_records(main_df dataframe.DataFrame) (dataframe.DataFrame, int) {
df := main_df.FilterAggregation(
func filter_valid_csv_records(mainDf dataframe.DataFrame) (dataframe.DataFrame, int) {
df := mainDf.FilterAggregation(
dataframe.And,
dataframe.F{Colname: "memory_rss_usage_container_sum", Comparator: series.GreaterEq, Comparando: 0},
dataframe.F{Colname: "memory_rss_usage_container_max", Comparator: series.GreaterEq, Comparando: 0},
Expand All @@ -101,22 +100,43 @@ func filter_valid_csv_records(main_df dataframe.DataFrame) (dataframe.DataFrame,
dataframe.F{Colname: "owner_name", Comparator: series.Neq, Comparando: ""},
dataframe.F{Colname: "owner_kind", Comparator: series.Neq, Comparando: "<none>"},
dataframe.F{Colname: "owner_name", Comparator: series.Neq, Comparando: "<none>"},
dataframe.F{Colname: "workload_type", Comparator: series.Neq, Comparando: "<none>"},
dataframe.F{Colname: "workload_type", Comparator: series.Neq, Comparando: ""},
)

// Change the case of all workload_type to lowercase
lcaseWorkloadTypes := df.Rapply(func(s series.Series) series.Series {
columns := df.Names()
indexOfWorkloadType := findInStringSlice("workload_type", columns)
workloadType := s.Elem(indexOfWorkloadType).String()
lcaseWorkloadType := strings.ToLower(workloadType)
return series.Strings([]string{lcaseWorkloadType})
})

// Delete existing workload_type column
df = df.Mutate(df.Col("workload_type")).Drop("workload_type")

// Rename lowercase converted column to workload_type
df = df.Mutate(lcaseWorkloadTypes.Col("X0")).Rename("workload_type", "X0")

// The Replicaset and Replicationcontroller has been removed from filter
// as these types do not get populated in workload_type column
df = df.FilterAggregation(
dataframe.And,
dataframe.F{
Colname: "workload_type",
Comparator: series.In,
Comparando: []string{
w.Daemonset.String(),
w.Deployment.String(),
w.Deploymentconfig.String(),
w.Replicaset.String(),
w.Replicationcontroller.String(),
w.Statefulset.String(),
}},
)

no_of_dropped_records := main_df.Nrow() - df.Nrow()
noOfDroppedRecords := mainDf.Nrow() - df.Nrow()

return df, no_of_dropped_records
return df, noOfDroppedRecords
}

func determine_k8s_object_type(df dataframe.DataFrame) dataframe.DataFrame {
Expand Down

0 comments on commit 0e884ac

Please sign in to comment.