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

fix(InitializeMetrics): fixed access to CIFlag #5395

Merged
merged 2 commits into from
May 24, 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
2 changes: 1 addition & 1 deletion internal/console/pre_scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func preRun(cmd *cobra.Command) error {
if err != nil {
return errors.New(initError + err.Error())
}
err = metrics.InitializeMetrics(flags.GetStrFlag(flags.ProfilingFlag), flags.GetStrFlag(flags.CIFlag))
err = metrics.InitializeMetrics(flags.GetStrFlag(flags.ProfilingFlag), flags.GetBoolFlag(flags.CIFlag))
if err != nil {
return errors.New(initError + err.Error())
}
Expand Down
5 changes: 2 additions & 3 deletions internal/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"math"
"strconv"
"strings"

"github.com/google/pprof/profile"
Expand Down Expand Up @@ -41,7 +40,7 @@ type Metrics struct {
}

// InitializeMetrics - creates a new instance of a Metrics based on the type of metrics specified
func InitializeMetrics(metric, ci string) error {
func InitializeMetrics(metric string, ci bool) error {
var err error
switch strings.ToLower(metric) {
case "cpu":
Expand All @@ -64,7 +63,7 @@ func InitializeMetrics(metric, ci string) error {
// Create temporary dir to keep pprof file
if !Metric.Disable {
Metric.metricsID = metric
Metric.ci, _ = strconv.ParseBool(ci)
Metric.ci = ci
}

return err
Expand Down
30 changes: 15 additions & 15 deletions internal/metrics/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func TestMetrics_InitializeMetrics(t *testing.T) {
type args struct {
metric string
ci string
ci bool
}
tests := []struct {
name string
Expand All @@ -23,7 +23,7 @@ func TestMetrics_InitializeMetrics(t *testing.T) {
name: "test_initialize_metrics_cpu",
args: args{
metric: "cpu",
ci: "true",
ci: true,
},
wantErr: false,
disable: false,
Expand All @@ -32,7 +32,7 @@ func TestMetrics_InitializeMetrics(t *testing.T) {
name: "test_initialize_metrics_mem",
args: args{
metric: "mem",
ci: "true",
ci: true,
},
wantErr: false,
disable: false,
Expand All @@ -41,7 +41,7 @@ func TestMetrics_InitializeMetrics(t *testing.T) {
name: "test_initialize_metrics_empty",
args: args{
metric: "",
ci: "true",
ci: true,
},
wantErr: false,
disable: true,
Expand All @@ -50,7 +50,7 @@ func TestMetrics_InitializeMetrics(t *testing.T) {
name: "test_initialize_metrics_unknown",
args: args{
metric: "unknown",
ci: "true",
ci: true,
},
wantErr: true,
disable: true,
Expand Down Expand Up @@ -205,23 +205,23 @@ func TestMetrics_Start_Stop(t *testing.T) {
type fields struct {
value string
allocation []string
ci string
ci bool
}
tests := []struct {
name string
args args
feilds fields
fields fields
disabled bool
}{
{
name: "test_cpu_start_stop",
args: args{
location: "test_location",
},
feilds: fields{
fields: fields{
value: "cpu",
allocation: []string{"1", "2", "3"},
ci: "false",
ci: false,
},
disabled: false,
},
Expand All @@ -230,9 +230,9 @@ func TestMetrics_Start_Stop(t *testing.T) {
args: args{
location: "test_location",
},
feilds: fields{
fields: fields{
value: "mem",
ci: "false",
ci: false,
allocation: []string{
"1", "2", "3", "4", "5",
"6", "7", "8", "9", "10",
Expand All @@ -247,9 +247,9 @@ func TestMetrics_Start_Stop(t *testing.T) {
args: args{
location: "test_location",
},
feilds: fields{
fields: fields{
value: "",
ci: "false",
ci: false,
allocation: []string{"1", "2", "3"},
},
disabled: true,
Expand All @@ -258,9 +258,9 @@ func TestMetrics_Start_Stop(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := InitializeMetrics(tt.feilds.value, tt.feilds.ci)
err := InitializeMetrics(tt.fields.value, tt.fields.ci)
require.NoError(t, err)
metricFunc(tt.feilds.allocation, tt.args.location)
metricFunc(tt.fields.allocation, tt.args.location)
})
}
}
Expand Down