Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Mizu
Commits
14a5fe11
Unverified
Commit
14a5fe11
authored
3 years ago
by
RoyUP9
Committed by
GitHub
3 years ago
Browse files
Options
Download
Email Patches
Plain Diff
changed logger debug mode to log level (#456)
parent
6909e6e6
No related merge requests found
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
agent/main.go
+5
-4
agent/main.go
cli/cmd/root.go
+1
-0
cli/cmd/root.go
cli/cmd/tapRunner.go
+3
-2
cli/cmd/tapRunner.go
cli/config/config.go
+5
-1
cli/config/config.go
cli/config/configStruct.go
+15
-0
cli/config/configStruct.go
cli/go.mod
+1
-0
cli/go.mod
shared/consts.go
+1
-1
shared/consts.go
shared/kubernetes/mizuTapperSyncer.go
+3
-2
shared/kubernetes/mizuTapperSyncer.go
shared/kubernetes/provider.go
+6
-15
shared/kubernetes/provider.go
shared/models.go
+2
-1
shared/models.go
with
42 additions
and
26 deletions
+42
-26
agent/main.go
+
5
-
4
View file @
14a5fe11
...
...
@@ -398,10 +398,11 @@ func getSyncEntriesConfig() *shared.SyncEntriesConfig {
}
func
determineLogLevel
()
(
logLevel
logging
.
Level
)
{
logLevel
=
logging
.
INFO
if
os
.
Getenv
(
shared
.
DebugModeEnvVar
)
==
"1"
{
logLevel
=
logging
.
DEBUG
logLevel
,
err
:
=
logging
.
LogLevel
(
os
.
Getenv
(
shared
.
LogLevelEnvVar
))
if
err
!=
nil
{
logLevel
=
logging
.
INFO
}
return
}
...
...
@@ -438,7 +439,7 @@ func startMizuTapperSyncer(ctx context.Context) (*kubernetes.MizuTapperSyncer, e
AgentImage
:
config
.
Config
.
AgentImage
,
TapperResources
:
config
.
Config
.
TapperResources
,
ImagePullPolicy
:
v1
.
PullPolicy
(
config
.
Config
.
PullPolicy
),
DumpLogs
:
config
.
Config
.
DumpLogs
,
LogLevel
:
config
.
Config
.
LogLevel
,
IgnoredUserAgents
:
config
.
Config
.
IgnoredUserAgents
,
MizuApiFilteringOptions
:
config
.
Config
.
MizuApiFilteringOptions
,
MizuServiceAccountExists
:
true
,
//assume service account exists since daemon mode will not function without it anyway
...
...
This diff is collapsed.
Click to expand it.
cli/cmd/root.go
+
1
-
0
View file @
14a5fe11
...
...
@@ -23,6 +23,7 @@ Further info is available at https://github.com/up9inc/mizu`,
if
err
:=
config
.
InitConfig
(
cmd
);
err
!=
nil
{
logger
.
Log
.
Fatal
(
err
)
}
return
nil
},
}
...
...
This diff is collapsed.
Click to expand it.
cli/cmd/tapRunner.go
+
3
-
2
View file @
14a5fe11
...
...
@@ -33,7 +33,7 @@ import (
"github.com/up9inc/mizu/tap/api"
)
const
cleanupTimeout
=
5
*
time
.
Minute
const
cleanupTimeout
=
time
.
Minute
type
tapState
struct
{
apiServerService
*
core
.
Service
...
...
@@ -200,7 +200,7 @@ func startTapperSyncer(ctx context.Context, cancel context.CancelFunc, provider
AgentImage
:
config
.
Config
.
AgentImage
,
TapperResources
:
config
.
Config
.
Tap
.
TapperResources
,
ImagePullPolicy
:
config
.
Config
.
ImagePullPolicy
(),
DumpLogs
:
config
.
Config
.
DumpLogs
,
LogLevel
:
config
.
Config
.
LogLevel
()
,
IgnoredUserAgents
:
config
.
Config
.
Tap
.
IgnoredUserAgents
,
MizuApiFilteringOptions
:
mizuApiFilteringOptions
,
MizuServiceAccountExists
:
state
.
mizuServiceAccountExists
,
...
...
@@ -310,6 +310,7 @@ func createMizuResources(ctx context.Context, cancel context.CancelFunc, kuberne
MaxEntriesDBSizeBytes
:
config
.
Config
.
Tap
.
MaxEntriesDBSizeBytes
(),
Resources
:
config
.
Config
.
Tap
.
ApiServerResources
,
ImagePullPolicy
:
config
.
Config
.
ImagePullPolicy
(),
LogLevel
:
config
.
Config
.
LogLevel
(),
}
if
config
.
Config
.
Tap
.
DaemonMode
{
...
...
This diff is collapsed.
Click to expand it.
cli/config/config.go
+
5
-
1
View file @
14a5fe11
...
...
@@ -52,6 +52,10 @@ func InitConfig(cmd *cobra.Command) error {
cmd
.
Flags
()
.
Visit
(
initFlag
)
if
err
:=
Config
.
validate
();
err
!=
nil
{
return
fmt
.
Errorf
(
"config validation failed, err: %v"
,
err
)
}
finalConfigPrettified
,
_
:=
uiUtils
.
PrettyJson
(
Config
)
logger
.
Log
.
Debugf
(
"Init config finished
\n
Final config: %v"
,
finalConfigPrettified
)
...
...
@@ -392,7 +396,7 @@ func getMizuAgentConfig(targetNamespaces []string, mizuApiFilteringOptions *api.
TargetNamespaces
:
targetNamespaces
,
AgentImage
:
Config
.
AgentImage
,
PullPolicy
:
Config
.
ImagePullPolicyStr
,
DumpLogs
:
Config
.
DumpLogs
,
LogLevel
:
Config
.
LogLevel
()
,
IgnoredUserAgents
:
Config
.
Tap
.
IgnoredUserAgents
,
TapperResources
:
Config
.
Tap
.
TapperResources
,
MizuResourcesNamespace
:
Config
.
MizuResourcesNamespace
,
...
...
This diff is collapsed.
Click to expand it.
cli/config/configStruct.go
+
15
-
0
View file @
14a5fe11
...
...
@@ -2,6 +2,7 @@ package config
import
(
"fmt"
"github.com/op/go-logging"
"github.com/up9inc/mizu/cli/config/configStructs"
"github.com/up9inc/mizu/cli/mizu"
v1
"k8s.io/api/core/v1"
...
...
@@ -32,6 +33,15 @@ type ConfigStruct struct {
KubeConfigPathStr
string
`yaml:"kube-config-path"`
ConfigFilePath
string
`yaml:"config-path,omitempty" readonly:""`
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
()
{
...
...
@@ -60,3 +70,8 @@ func (config *ConfigStruct) KubeConfigPath() string {
home
:=
homedir
.
HomeDir
()
return
filepath
.
Join
(
home
,
".kube"
,
"config"
)
}
func
(
config
*
ConfigStruct
)
LogLevel
()
logging
.
Level
{
logLevel
,
_
:=
logging
.
LogLevel
(
config
.
LogLevelStr
)
return
logLevel
}
This diff is collapsed.
Click to expand it.
cli/go.mod
+
1
-
0
View file @
14a5fe11
...
...
@@ -8,6 +8,7 @@ require (
github.com/getkin/kin-openapi v0.79.0
github.com/google/go-github/v37 v37.0.0
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/pflag v1.0.5
github.com/up9inc/mizu/shared v0.0.0
...
...
This diff is collapsed.
Click to expand it.
shared/consts.go
+
1
-
1
View file @
14a5fe11
...
...
@@ -13,7 +13,7 @@ const (
ConfigFileName
=
"mizu-config.json"
GoGCEnvVar
=
"GOGC"
DefaultApiServerPort
=
8899
DebugMode
EnvVar
=
"
MIZU_DEBUG
"
LogLevel
EnvVar
=
"
LOG_LEVEL
"
BasenineHost
=
"localhost"
BaseninePort
=
"9099"
)
This diff is collapsed.
Click to expand it.
shared/kubernetes/mizuTapperSyncer.go
+
3
-
2
View file @
14a5fe11
...
...
@@ -3,6 +3,7 @@ package kubernetes
import
(
"context"
"fmt"
"github.com/op/go-logging"
"github.com/up9inc/mizu/shared"
"github.com/up9inc/mizu/shared/debounce"
"github.com/up9inc/mizu/shared/logger"
...
...
@@ -36,7 +37,7 @@ type TapperSyncerConfig struct {
AgentImage
string
TapperResources
shared
.
Resources
ImagePullPolicy
core
.
PullPolicy
DumpLogs
boo
l
LogLevel
logging
.
Leve
l
IgnoredUserAgents
[]
string
MizuApiFilteringOptions
api
.
TrafficFilteringOptions
MizuServiceAccountExists
bool
...
...
@@ -192,7 +193,7 @@ func (tapperSyncer *MizuTapperSyncer) updateMizuTappers() error {
tapperSyncer
.
config
.
TapperResources
,
tapperSyncer
.
config
.
ImagePullPolicy
,
tapperSyncer
.
config
.
MizuApiFilteringOptions
,
tapperSyncer
.
config
.
DumpLogs
,
tapperSyncer
.
config
.
LogLevel
,
);
err
!=
nil
{
return
err
}
...
...
This diff is collapsed.
Click to expand it.
shared/kubernetes/provider.go
+
6
-
15
View file @
14a5fe11
...
...
@@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/op/go-logging"
"github.com/up9inc/mizu/shared"
"github.com/up9inc/mizu/shared/logger"
"github.com/up9inc/mizu/shared/semver"
...
...
@@ -179,7 +180,7 @@ type ApiServerOptions struct {
MaxEntriesDBSizeBytes
int64
Resources
shared
.
Resources
ImagePullPolicy
core
.
PullPolicy
DumpLogs
boo
l
LogLevel
logging
.
Leve
l
}
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
)
debugMode
:=
""
if
opts
.
DumpLogs
{
debugMode
=
"1"
}
pod
:=
&
core
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
opts
.
PodName
,
...
...
@@ -272,8 +268,8 @@ func (provider *Provider) GetMizuApiServerPodObject(opts *ApiServerOptions, moun
Value
:
string
(
marshaledSyncEntriesConfig
),
},
{
Name
:
shared
.
DebugMode
EnvVar
,
Value
:
debugMode
,
Name
:
shared
.
LogLevel
EnvVar
,
Value
:
opts
.
LogLevel
.
String
()
,
},
},
Resources
:
core
.
ResourceRequirements
{
...
...
@@ -619,7 +615,7 @@ func (provider *Provider) CreateConfigMap(ctx context.Context, namespace string,
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
boo
l
)
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
.
Leve
l
)
error
{
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
{
...
...
@@ -645,11 +641,6 @@ func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespac
"--procfs"
,
procfsMountPath
,
}
debugMode
:=
""
if
dumpLogs
{
debugMode
=
"1"
}
agentContainer
:=
applyconfcore
.
Container
()
agentContainer
.
WithName
(
tapperPodName
)
agentContainer
.
WithImage
(
podImage
)
...
...
@@ -657,7 +648,7 @@ func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespac
agentContainer
.
WithSecurityContext
(
applyconfcore
.
SecurityContext
()
.
WithPrivileged
(
true
))
agentContainer
.
WithCommand
(
mizuCmd
...
)
agentContainer
.
WithEnv
(
applyconfcore
.
EnvVar
()
.
WithName
(
shared
.
DebugMode
EnvVar
)
.
WithValue
(
debugMode
),
applyconfcore
.
EnvVar
()
.
WithName
(
shared
.
LogLevel
EnvVar
)
.
WithValue
(
logLevel
.
String
()
),
applyconfcore
.
EnvVar
()
.
WithName
(
shared
.
HostModeEnvVar
)
.
WithValue
(
"1"
),
applyconfcore
.
EnvVar
()
.
WithName
(
shared
.
TappedAddressesPerNodeDictEnvVar
)
.
WithValue
(
string
(
nodeToTappedPodIPMapJsonStr
)),
applyconfcore
.
EnvVar
()
.
WithName
(
shared
.
GoGCEnvVar
)
.
WithValue
(
"12800"
),
...
...
This diff is collapsed.
Click to expand it.
shared/models.go
+
2
-
1
View file @
14a5fe11
package
shared
import
(
"github.com/op/go-logging"
"github.com/up9inc/mizu/tap/api"
"io/ioutil"
"log"
...
...
@@ -36,7 +37,7 @@ type MizuAgentConfig struct {
TargetNamespaces
[]
string
`json:"targetNamespaces"`
AgentImage
string
`json:"agentImage"`
PullPolicy
string
`json:"pullPolicy"`
DumpLogs
bool
`json:"
dumpLogs
"`
LogLevel
logging
.
Level
`json:"
logLevel
"`
IgnoredUserAgents
[]
string
`json:"ignoredUserAgents"`
TapperResources
Resources
`json:"tapperResources"`
MizuResourcesNamespace
string
`json:"mizuResourceNamespace"`
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help