mirror of
https://github.com/kubeshark/kubeshark.git
synced 2025-08-14 14:43:46 +00:00
changed logger debug mode to log level (#456)
This commit is contained in:
parent
6909e6e657
commit
14a5fe11e7
@ -398,10 +398,11 @@ func getSyncEntriesConfig() *shared.SyncEntriesConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func determineLogLevel() (logLevel logging.Level) {
|
func determineLogLevel() (logLevel logging.Level) {
|
||||||
logLevel = logging.INFO
|
logLevel, err := logging.LogLevel(os.Getenv(shared.LogLevelEnvVar))
|
||||||
if os.Getenv(shared.DebugModeEnvVar) == "1" {
|
if err != nil {
|
||||||
logLevel = logging.DEBUG
|
logLevel = logging.INFO
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,7 +439,7 @@ func startMizuTapperSyncer(ctx context.Context) (*kubernetes.MizuTapperSyncer, e
|
|||||||
AgentImage: config.Config.AgentImage,
|
AgentImage: config.Config.AgentImage,
|
||||||
TapperResources: config.Config.TapperResources,
|
TapperResources: config.Config.TapperResources,
|
||||||
ImagePullPolicy: v1.PullPolicy(config.Config.PullPolicy),
|
ImagePullPolicy: v1.PullPolicy(config.Config.PullPolicy),
|
||||||
DumpLogs: config.Config.DumpLogs,
|
LogLevel: config.Config.LogLevel,
|
||||||
IgnoredUserAgents: config.Config.IgnoredUserAgents,
|
IgnoredUserAgents: config.Config.IgnoredUserAgents,
|
||||||
MizuApiFilteringOptions: config.Config.MizuApiFilteringOptions,
|
MizuApiFilteringOptions: config.Config.MizuApiFilteringOptions,
|
||||||
MizuServiceAccountExists: true, //assume service account exists since daemon mode will not function without it anyway
|
MizuServiceAccountExists: true, //assume service account exists since daemon mode will not function without it anyway
|
||||||
|
@ -23,6 +23,7 @@ Further info is available at https://github.com/up9inc/mizu`,
|
|||||||
if err := config.InitConfig(cmd); err != nil {
|
if err := config.InitConfig(cmd); err != nil {
|
||||||
logger.Log.Fatal(err)
|
logger.Log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ import (
|
|||||||
"github.com/up9inc/mizu/tap/api"
|
"github.com/up9inc/mizu/tap/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
const cleanupTimeout = 5 * time.Minute
|
const cleanupTimeout = time.Minute
|
||||||
|
|
||||||
type tapState struct {
|
type tapState struct {
|
||||||
apiServerService *core.Service
|
apiServerService *core.Service
|
||||||
@ -200,7 +200,7 @@ func startTapperSyncer(ctx context.Context, cancel context.CancelFunc, provider
|
|||||||
AgentImage: config.Config.AgentImage,
|
AgentImage: config.Config.AgentImage,
|
||||||
TapperResources: config.Config.Tap.TapperResources,
|
TapperResources: config.Config.Tap.TapperResources,
|
||||||
ImagePullPolicy: config.Config.ImagePullPolicy(),
|
ImagePullPolicy: config.Config.ImagePullPolicy(),
|
||||||
DumpLogs: config.Config.DumpLogs,
|
LogLevel: config.Config.LogLevel(),
|
||||||
IgnoredUserAgents: config.Config.Tap.IgnoredUserAgents,
|
IgnoredUserAgents: config.Config.Tap.IgnoredUserAgents,
|
||||||
MizuApiFilteringOptions: mizuApiFilteringOptions,
|
MizuApiFilteringOptions: mizuApiFilteringOptions,
|
||||||
MizuServiceAccountExists: state.mizuServiceAccountExists,
|
MizuServiceAccountExists: state.mizuServiceAccountExists,
|
||||||
@ -310,6 +310,7 @@ func createMizuResources(ctx context.Context, cancel context.CancelFunc, kuberne
|
|||||||
MaxEntriesDBSizeBytes: config.Config.Tap.MaxEntriesDBSizeBytes(),
|
MaxEntriesDBSizeBytes: config.Config.Tap.MaxEntriesDBSizeBytes(),
|
||||||
Resources: config.Config.Tap.ApiServerResources,
|
Resources: config.Config.Tap.ApiServerResources,
|
||||||
ImagePullPolicy: config.Config.ImagePullPolicy(),
|
ImagePullPolicy: config.Config.ImagePullPolicy(),
|
||||||
|
LogLevel: config.Config.LogLevel(),
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Config.Tap.DaemonMode {
|
if config.Config.Tap.DaemonMode {
|
||||||
|
@ -52,6 +52,10 @@ func InitConfig(cmd *cobra.Command) error {
|
|||||||
|
|
||||||
cmd.Flags().Visit(initFlag)
|
cmd.Flags().Visit(initFlag)
|
||||||
|
|
||||||
|
if err := Config.validate(); err != nil {
|
||||||
|
return fmt.Errorf("config validation failed, err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
finalConfigPrettified, _ := uiUtils.PrettyJson(Config)
|
finalConfigPrettified, _ := uiUtils.PrettyJson(Config)
|
||||||
logger.Log.Debugf("Init config finished\n Final config: %v", finalConfigPrettified)
|
logger.Log.Debugf("Init config finished\n Final config: %v", finalConfigPrettified)
|
||||||
|
|
||||||
@ -392,7 +396,7 @@ func getMizuAgentConfig(targetNamespaces []string, mizuApiFilteringOptions *api.
|
|||||||
TargetNamespaces: targetNamespaces,
|
TargetNamespaces: targetNamespaces,
|
||||||
AgentImage: Config.AgentImage,
|
AgentImage: Config.AgentImage,
|
||||||
PullPolicy: Config.ImagePullPolicyStr,
|
PullPolicy: Config.ImagePullPolicyStr,
|
||||||
DumpLogs: Config.DumpLogs,
|
LogLevel: Config.LogLevel(),
|
||||||
IgnoredUserAgents: Config.Tap.IgnoredUserAgents,
|
IgnoredUserAgents: Config.Tap.IgnoredUserAgents,
|
||||||
TapperResources: Config.Tap.TapperResources,
|
TapperResources: Config.Tap.TapperResources,
|
||||||
MizuResourcesNamespace: Config.MizuResourcesNamespace,
|
MizuResourcesNamespace: Config.MizuResourcesNamespace,
|
||||||
|
@ -2,6 +2,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/op/go-logging"
|
||||||
"github.com/up9inc/mizu/cli/config/configStructs"
|
"github.com/up9inc/mizu/cli/config/configStructs"
|
||||||
"github.com/up9inc/mizu/cli/mizu"
|
"github.com/up9inc/mizu/cli/mizu"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
@ -32,6 +33,15 @@ type ConfigStruct struct {
|
|||||||
KubeConfigPathStr string `yaml:"kube-config-path"`
|
KubeConfigPathStr string `yaml:"kube-config-path"`
|
||||||
ConfigFilePath string `yaml:"config-path,omitempty" readonly:""`
|
ConfigFilePath string `yaml:"config-path,omitempty" readonly:""`
|
||||||
HeadlessMode bool `yaml:"headless" default:"false"`
|
HeadlessMode bool `yaml:"headless" default:"false"`
|
||||||
|
LogLevelStr string `yaml:"log-level,omitempty" default:"INFO" readonly:""`
|
||||||
|
}
|
||||||
|
|
||||||
|
func(config *ConfigStruct) validate() error {
|
||||||
|
if _, err := logging.LogLevel(config.LogLevelStr); err != nil {
|
||||||
|
return fmt.Errorf("%s is not a valid log level, err: %v", config.LogLevelStr, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *ConfigStruct) SetDefaults() {
|
func (config *ConfigStruct) SetDefaults() {
|
||||||
@ -60,3 +70,8 @@ func (config *ConfigStruct) KubeConfigPath() string {
|
|||||||
home := homedir.HomeDir()
|
home := homedir.HomeDir()
|
||||||
return filepath.Join(home, ".kube", "config")
|
return filepath.Join(home, ".kube", "config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (config *ConfigStruct) LogLevel() logging.Level {
|
||||||
|
logLevel, _ := logging.LogLevel(config.LogLevelStr)
|
||||||
|
return logLevel
|
||||||
|
}
|
||||||
|
@ -8,6 +8,7 @@ require (
|
|||||||
github.com/getkin/kin-openapi v0.79.0
|
github.com/getkin/kin-openapi v0.79.0
|
||||||
github.com/google/go-github/v37 v37.0.0
|
github.com/google/go-github/v37 v37.0.0
|
||||||
github.com/google/uuid v1.1.2
|
github.com/google/uuid v1.1.2
|
||||||
|
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
|
||||||
github.com/spf13/cobra v1.1.3
|
github.com/spf13/cobra v1.1.3
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
github.com/up9inc/mizu/shared v0.0.0
|
github.com/up9inc/mizu/shared v0.0.0
|
||||||
|
@ -13,7 +13,7 @@ const (
|
|||||||
ConfigFileName = "mizu-config.json"
|
ConfigFileName = "mizu-config.json"
|
||||||
GoGCEnvVar = "GOGC"
|
GoGCEnvVar = "GOGC"
|
||||||
DefaultApiServerPort = 8899
|
DefaultApiServerPort = 8899
|
||||||
DebugModeEnvVar = "MIZU_DEBUG"
|
LogLevelEnvVar = "LOG_LEVEL"
|
||||||
BasenineHost = "localhost"
|
BasenineHost = "localhost"
|
||||||
BaseninePort = "9099"
|
BaseninePort = "9099"
|
||||||
)
|
)
|
||||||
|
@ -3,6 +3,7 @@ package kubernetes
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/op/go-logging"
|
||||||
"github.com/up9inc/mizu/shared"
|
"github.com/up9inc/mizu/shared"
|
||||||
"github.com/up9inc/mizu/shared/debounce"
|
"github.com/up9inc/mizu/shared/debounce"
|
||||||
"github.com/up9inc/mizu/shared/logger"
|
"github.com/up9inc/mizu/shared/logger"
|
||||||
@ -36,7 +37,7 @@ type TapperSyncerConfig struct {
|
|||||||
AgentImage string
|
AgentImage string
|
||||||
TapperResources shared.Resources
|
TapperResources shared.Resources
|
||||||
ImagePullPolicy core.PullPolicy
|
ImagePullPolicy core.PullPolicy
|
||||||
DumpLogs bool
|
LogLevel logging.Level
|
||||||
IgnoredUserAgents []string
|
IgnoredUserAgents []string
|
||||||
MizuApiFilteringOptions api.TrafficFilteringOptions
|
MizuApiFilteringOptions api.TrafficFilteringOptions
|
||||||
MizuServiceAccountExists bool
|
MizuServiceAccountExists bool
|
||||||
@ -192,7 +193,7 @@ func (tapperSyncer *MizuTapperSyncer) updateMizuTappers() error {
|
|||||||
tapperSyncer.config.TapperResources,
|
tapperSyncer.config.TapperResources,
|
||||||
tapperSyncer.config.ImagePullPolicy,
|
tapperSyncer.config.ImagePullPolicy,
|
||||||
tapperSyncer.config.MizuApiFilteringOptions,
|
tapperSyncer.config.MizuApiFilteringOptions,
|
||||||
tapperSyncer.config.DumpLogs,
|
tapperSyncer.config.LogLevel,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/op/go-logging"
|
||||||
"github.com/up9inc/mizu/shared"
|
"github.com/up9inc/mizu/shared"
|
||||||
"github.com/up9inc/mizu/shared/logger"
|
"github.com/up9inc/mizu/shared/logger"
|
||||||
"github.com/up9inc/mizu/shared/semver"
|
"github.com/up9inc/mizu/shared/semver"
|
||||||
@ -179,7 +180,7 @@ type ApiServerOptions struct {
|
|||||||
MaxEntriesDBSizeBytes int64
|
MaxEntriesDBSizeBytes int64
|
||||||
Resources shared.Resources
|
Resources shared.Resources
|
||||||
ImagePullPolicy core.PullPolicy
|
ImagePullPolicy core.PullPolicy
|
||||||
DumpLogs bool
|
LogLevel logging.Level
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provider *Provider) GetMizuApiServerPodObject(opts *ApiServerOptions, mountVolumeClaim bool, volumeClaimName string) (*core.Pod, error) {
|
func (provider *Provider) GetMizuApiServerPodObject(opts *ApiServerOptions, mountVolumeClaim bool, volumeClaimName string) (*core.Pod, error) {
|
||||||
@ -248,11 +249,6 @@ func (provider *Provider) GetMizuApiServerPodObject(opts *ApiServerOptions, moun
|
|||||||
|
|
||||||
port := intstr.FromInt(shared.DefaultApiServerPort)
|
port := intstr.FromInt(shared.DefaultApiServerPort)
|
||||||
|
|
||||||
debugMode := ""
|
|
||||||
if opts.DumpLogs {
|
|
||||||
debugMode = "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
pod := &core.Pod{
|
pod := &core.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: opts.PodName,
|
Name: opts.PodName,
|
||||||
@ -272,8 +268,8 @@ func (provider *Provider) GetMizuApiServerPodObject(opts *ApiServerOptions, moun
|
|||||||
Value: string(marshaledSyncEntriesConfig),
|
Value: string(marshaledSyncEntriesConfig),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: shared.DebugModeEnvVar,
|
Name: shared.LogLevelEnvVar,
|
||||||
Value: debugMode,
|
Value: opts.LogLevel.String(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Resources: core.ResourceRequirements{
|
Resources: core.ResourceRequirements{
|
||||||
@ -619,7 +615,7 @@ func (provider *Provider) CreateConfigMap(ctx context.Context, namespace string,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespace string, daemonSetName string, podImage string, tapperPodName string, apiServerPodIp string, nodeToTappedPodIPMap map[string][]string, serviceAccountName string, resources shared.Resources, imagePullPolicy core.PullPolicy, mizuApiFilteringOptions api.TrafficFilteringOptions, dumpLogs bool) error {
|
func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespace string, daemonSetName string, podImage string, tapperPodName string, apiServerPodIp string, nodeToTappedPodIPMap map[string][]string, serviceAccountName string, resources shared.Resources, imagePullPolicy core.PullPolicy, mizuApiFilteringOptions api.TrafficFilteringOptions, logLevel logging.Level) error {
|
||||||
logger.Log.Debugf("Applying %d tapper daemon sets, ns: %s, daemonSetName: %s, podImage: %s, tapperPodName: %s", len(nodeToTappedPodIPMap), namespace, daemonSetName, podImage, tapperPodName)
|
logger.Log.Debugf("Applying %d tapper daemon sets, ns: %s, daemonSetName: %s, podImage: %s, tapperPodName: %s", len(nodeToTappedPodIPMap), namespace, daemonSetName, podImage, tapperPodName)
|
||||||
|
|
||||||
if len(nodeToTappedPodIPMap) == 0 {
|
if len(nodeToTappedPodIPMap) == 0 {
|
||||||
@ -645,11 +641,6 @@ func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespac
|
|||||||
"--procfs", procfsMountPath,
|
"--procfs", procfsMountPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
debugMode := ""
|
|
||||||
if dumpLogs {
|
|
||||||
debugMode = "1"
|
|
||||||
}
|
|
||||||
|
|
||||||
agentContainer := applyconfcore.Container()
|
agentContainer := applyconfcore.Container()
|
||||||
agentContainer.WithName(tapperPodName)
|
agentContainer.WithName(tapperPodName)
|
||||||
agentContainer.WithImage(podImage)
|
agentContainer.WithImage(podImage)
|
||||||
@ -657,7 +648,7 @@ func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespac
|
|||||||
agentContainer.WithSecurityContext(applyconfcore.SecurityContext().WithPrivileged(true))
|
agentContainer.WithSecurityContext(applyconfcore.SecurityContext().WithPrivileged(true))
|
||||||
agentContainer.WithCommand(mizuCmd...)
|
agentContainer.WithCommand(mizuCmd...)
|
||||||
agentContainer.WithEnv(
|
agentContainer.WithEnv(
|
||||||
applyconfcore.EnvVar().WithName(shared.DebugModeEnvVar).WithValue(debugMode),
|
applyconfcore.EnvVar().WithName(shared.LogLevelEnvVar).WithValue(logLevel.String()),
|
||||||
applyconfcore.EnvVar().WithName(shared.HostModeEnvVar).WithValue("1"),
|
applyconfcore.EnvVar().WithName(shared.HostModeEnvVar).WithValue("1"),
|
||||||
applyconfcore.EnvVar().WithName(shared.TappedAddressesPerNodeDictEnvVar).WithValue(string(nodeToTappedPodIPMapJsonStr)),
|
applyconfcore.EnvVar().WithName(shared.TappedAddressesPerNodeDictEnvVar).WithValue(string(nodeToTappedPodIPMapJsonStr)),
|
||||||
applyconfcore.EnvVar().WithName(shared.GoGCEnvVar).WithValue("12800"),
|
applyconfcore.EnvVar().WithName(shared.GoGCEnvVar).WithValue("12800"),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package shared
|
package shared
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/op/go-logging"
|
||||||
"github.com/up9inc/mizu/tap/api"
|
"github.com/up9inc/mizu/tap/api"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
@ -36,7 +37,7 @@ type MizuAgentConfig struct {
|
|||||||
TargetNamespaces []string `json:"targetNamespaces"`
|
TargetNamespaces []string `json:"targetNamespaces"`
|
||||||
AgentImage string `json:"agentImage"`
|
AgentImage string `json:"agentImage"`
|
||||||
PullPolicy string `json:"pullPolicy"`
|
PullPolicy string `json:"pullPolicy"`
|
||||||
DumpLogs bool `json:"dumpLogs"`
|
LogLevel logging.Level `json:"logLevel"`
|
||||||
IgnoredUserAgents []string `json:"ignoredUserAgents"`
|
IgnoredUserAgents []string `json:"ignoredUserAgents"`
|
||||||
TapperResources Resources `json:"tapperResources"`
|
TapperResources Resources `json:"tapperResources"`
|
||||||
MizuResourcesNamespace string `json:"mizuResourceNamespace"`
|
MizuResourcesNamespace string `json:"mizuResourceNamespace"`
|
||||||
|
Loading…
Reference in New Issue
Block a user