-
Notifications
You must be signed in to change notification settings - Fork 24
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
Fixes #RHIROS-1401 - Dropping csv records with missing resource usage… #144
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,12 @@ import ( | |
"github.com/go-gota/gota/dataframe" | ||
"github.com/go-gota/gota/series" | ||
|
||
"github.com/redhatinsights/ros-ocp-backend/internal/logging" | ||
w "github.com/redhatinsights/ros-ocp-backend/internal/types/workload" | ||
) | ||
|
||
func Aggregate_data(df dataframe.DataFrame) dataframe.DataFrame { | ||
log = logging.GetLogger() | ||
df = df.FilterAggregation( | ||
dataframe.And, | ||
dataframe.F{Colname: "owner_kind", Comparator: series.Neq, Comparando: ""}, | ||
|
@@ -40,6 +42,33 @@ func Aggregate_data(df dataframe.DataFrame) dataframe.DataFrame { | |
|
||
df = df.Mutate(s.Col("X0")).Rename("k8s_object_type", "X0") | ||
df = df.Mutate(s.Col("X1")).Rename("k8s_object_name", "X1") | ||
|
||
// filter out only valid workload type | ||
df = df.Filter( | ||
dataframe.F{ | ||
Colname: "k8s_object_type", | ||
Comparator: series.In, | ||
Comparando: []string{ | ||
w.Daemonset.String(), | ||
w.Deployment.String(), | ||
w.Deploymentconfig.String(), | ||
w.Replicaset.String(), | ||
w.Replicationcontroller.String(), | ||
w.Statefulset.String(), | ||
saltgen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}}, | ||
) | ||
|
||
// Validation to check if metrics for cpuUsage, memoryUsage and memoryRSS are missing | ||
df, no_of_dropped_records := filter_valid_csv_records(df) | ||
if no_of_dropped_records != 0 { | ||
invalidDataPoints.Add(float64(no_of_dropped_records)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand then we are never going to return float from filter_valid_csv_records, is it prometheus which expects float value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, prometheus |
||
log.Infof("Invalid records in CSV - %v", no_of_dropped_records) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be at Info level? and do you think we should also print more about owner_name and workload? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, good to have at info level so that using request_id we can check in kibana how many rows where dropped for particular request/CSV. Our logging system by default logs all the request related info - https://github.com/RedHatInsights/ros-ocp-backend/blob/main/internal/logging/logging.go#L66-L71
saltgen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if df.Nrow() == 0 { | ||
return df | ||
} | ||
|
||
dfGroups := df.GroupBy( | ||
"namespace", | ||
"k8s_object_type", | ||
|
@@ -87,3 +116,25 @@ func Aggregate_data(df dataframe.DataFrame) dataframe.DataFrame { | |
df = dfGroups.Aggregation(columnsAggregationType, columnsToAggregate) | ||
return df | ||
} | ||
|
||
func filter_valid_csv_records(main_df dataframe.DataFrame) (dataframe.DataFrame, int) { | ||
patilsuraj767 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
df := main_df.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}, | ||
dataframe.F{Colname: "memory_rss_usage_container_min", Comparator: series.GreaterEq, Comparando: 0}, | ||
dataframe.F{Colname: "memory_rss_usage_container_avg", Comparator: series.GreaterEq, Comparando: 0}, | ||
dataframe.F{Colname: "memory_usage_container_sum", Comparator: series.GreaterEq, Comparando: 0}, | ||
dataframe.F{Colname: "memory_usage_container_max", Comparator: series.GreaterEq, Comparando: 0}, | ||
dataframe.F{Colname: "memory_usage_container_min", Comparator: series.GreaterEq, Comparando: 0}, | ||
dataframe.F{Colname: "memory_usage_container_avg", Comparator: series.GreaterEq, Comparando: 0}, | ||
dataframe.F{Colname: "cpu_usage_container_sum", Comparator: series.GreaterEq, Comparando: 0}, | ||
dataframe.F{Colname: "cpu_usage_container_max", Comparator: series.GreaterEq, Comparando: 0}, | ||
dataframe.F{Colname: "cpu_usage_container_min", Comparator: series.GreaterEq, Comparando: 0}, | ||
dataframe.F{Colname: "cpu_usage_container_avg", Comparator: series.GreaterEq, Comparando: 0}, | ||
) | ||
|
||
no_of_dropped_records := main_df.Nrow() - df.Nrow() | ||
|
||
return df, no_of_dropped_records | ||
} |
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,13 @@ | ||||||||||
package utils | ||||||||||
|
||||||||||
import ( | ||||||||||
"github.com/prometheus/client_golang/prometheus" | ||||||||||
"github.com/prometheus/client_golang/prometheus/promauto" | ||||||||||
) | ||||||||||
|
||||||||||
var ( | ||||||||||
invalidDataPoints = promauto.NewCounter(prometheus.CounterOpts{ | ||||||||||
Name: "rosocp_invalid_datapoints_total", | ||||||||||
Help: "The total number of invalid datapoints(rows) found in CSVs recevied", | ||||||||||
saltgen marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to prometheus metric naming convention - https://prometheus.io/docs/practices/naming/ suffix should describe the unit. |
||||||||||
}) | ||||||||||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to get this out as separate function? I understand its just a call to Filter however the
Aggregate_data
is already lengthy. With that can we have tests then? So looking at those one would understand what is invalid?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added test cases