in internal/onetime/configure/configure.go [317:466]
func (c *Configure) modifyFeature(ctx context.Context, config *cpb.Configuration) subcommands.ExitStatus {
// var isEnabled any
var isEnabled *bool
if c.Enable || c.Disable {
isEnabled = &c.Enable
}
isCmdValid := false
switch c.Feature {
case hostMetrics:
if isEnabled != nil {
isCmdValid = true
config.ProvideSapHostAgentMetrics = &wpb.BoolValue{Value: *isEnabled}
}
case processMetrics:
if isEnabled != nil {
isCmdValid = true
checkCollectionConfig(config).CollectProcessMetrics = *isEnabled
}
if c.FastMetricsFrequency != 0 {
if c.FastMetricsFrequency < 0 {
c.oteLogger.LogErrorToFileAndConsole(ctx, "Inappropriate flag values:", fmt.Errorf("frequency must be non-negative"))
return subcommands.ExitUsageError
}
isCmdValid = true
checkCollectionConfig(config).ProcessMetricsFrequency = c.FastMetricsFrequency
}
if c.SlowMetricsFrequency != 0 {
if c.SlowMetricsFrequency < 0 {
c.oteLogger.LogErrorToFileAndConsole(ctx, "Inappropriate flag values:", fmt.Errorf("slow-metrics-frequency must be non-negative"))
return subcommands.ExitUsageError
}
isCmdValid = true
checkCollectionConfig(config).SlowProcessMetricsFrequency = c.SlowMetricsFrequency
}
if len(c.SkipMetrics) > 0 {
log.CtxLogger(ctx).Info("Skip Metrics: ", c.SkipMetrics)
if !c.Add && !c.Remove {
c.oteLogger.LogMessageToFileAndConsole(ctx, "Please choose to add or remove given list of process metrics.")
return subcommands.ExitUsageError
}
isCmdValid = true
if res := c.modifyProcessMetricsToSkip(ctx, config); res != subcommands.ExitSuccess {
return res
}
}
case hanaMonitoring:
if isEnabled != nil {
isCmdValid = true
if hmc := config.GetHanaMonitoringConfiguration(); hmc != nil {
hmc.Enabled = *isEnabled
} else {
config.HanaMonitoringConfiguration = &cpb.HANAMonitoringConfiguration{Enabled: *isEnabled}
}
}
if c.SampleIntervalSec != 0 {
if c.SampleIntervalSec < 0 {
c.oteLogger.LogErrorToFileAndConsole(ctx, "Inappropriate flag values:", fmt.Errorf("sample-interval-sec must be non-negative"))
return subcommands.ExitUsageError
}
isCmdValid = true
config.HanaMonitoringConfiguration.SampleIntervalSec = c.SampleIntervalSec
}
if c.QueryTimeoutSec != 0 {
if c.QueryTimeoutSec < 0 {
c.oteLogger.LogErrorToFileAndConsole(ctx, "Inappropriate flag values:", fmt.Errorf("query-timeout-sec must be non-negative"))
return subcommands.ExitUsageError
}
isCmdValid = true
config.HanaMonitoringConfiguration.QueryTimeoutSec = c.QueryTimeoutSec
}
case sapDiscovery:
if isEnabled != nil {
isCmdValid = true
checkDiscoveryConfig(config).EnableDiscovery = &wpb.BoolValue{Value: *isEnabled}
}
case agentMetrics:
if isEnabled != nil {
isCmdValid = true
checkCollectionConfig(config).CollectAgentMetrics = *isEnabled
}
if c.AgentMetricsFrequency != 0 {
if c.AgentMetricsFrequency < 0 {
c.oteLogger.LogErrorToFileAndConsole(ctx, "Inappropriate flag values:", fmt.Errorf("frequency must be non-negative"))
return subcommands.ExitUsageError
}
isCmdValid = true
checkCollectionConfig(config).AgentMetricsFrequency = c.AgentMetricsFrequency
}
if c.AgentHealthFrequency != 0 {
if c.AgentHealthFrequency < 0 {
c.oteLogger.LogErrorToFileAndConsole(ctx, "Inappropriate flag values:", fmt.Errorf("agent-health-frequency must be non-negative"))
return subcommands.ExitUsageError
}
isCmdValid = true
checkCollectionConfig(config).AgentHealthFrequency = c.AgentHealthFrequency
}
if c.HeartbeatFrequency != 0 {
if c.HeartbeatFrequency < 0 {
c.oteLogger.LogErrorToFileAndConsole(ctx, "Inappropriate flag values:", fmt.Errorf("heartbeat-frequency must be non-negative"))
return subcommands.ExitUsageError
}
isCmdValid = true
checkCollectionConfig(config).HeartbeatFrequency = c.HeartbeatFrequency
}
case workloadValidation:
if isEnabled != nil {
isCmdValid = true
checkCollectionConfig(config).CollectWorkloadValidationMetrics = &wpb.BoolValue{Value: *isEnabled}
}
if c.ValidationMetricsFrequency != 0 {
if c.ValidationMetricsFrequency < 0 {
c.oteLogger.LogErrorToFileAndConsole(ctx, "Inappropriate flag values:", fmt.Errorf("frequency must be non-negative"))
return subcommands.ExitUsageError
}
isCmdValid = true
checkCollectionConfig(config).WorkloadValidationMetricsFrequency = c.ValidationMetricsFrequency
}
if c.DbFrequency != 0 {
if c.DbFrequency < 0 {
c.oteLogger.LogErrorToFileAndConsole(ctx, "Inappropriate flag values:", fmt.Errorf("db-frequency must be non-negative"))
return subcommands.ExitUsageError
}
isCmdValid = true
checkCollectionConfig(config).WorkloadValidationDbMetricsFrequency = c.DbFrequency
}
case workloadDiscovery:
if isEnabled != nil {
isCmdValid = true
checkDiscoveryConfig(config).EnableWorkloadDiscovery = &wpb.BoolValue{Value: *isEnabled}
}
default:
c.oteLogger.LogMessageToFileAndConsole(ctx, "Unsupported Metric")
return subcommands.ExitUsageError
}
if !isCmdValid {
c.oteLogger.LogMessageToFileAndConsole(ctx, "Insufficient flags. Please check usage:\n")
// Checking for nil for testing purposes
if c.usageFunc != nil {
c.usageFunc()
}
return subcommands.ExitUsageError
}
return subcommands.ExitSuccess
}