diff --git a/cli/cmd/tap.go b/cli/cmd/tap.go index 3399fc24a..6a590eeed 100644 --- a/cli/cmd/tap.go +++ b/cli/cmd/tap.go @@ -123,4 +123,5 @@ func init() { tapCmd.Flags().String(configStructs.ContractFile, defaultTapConfig.ContractFile, "OAS/Swagger file to validate to monitor the contracts") tapCmd.Flags().Bool(configStructs.ServiceMeshName, defaultTapConfig.ServiceMesh, "Record decrypted traffic if the cluster is configured with a service mesh and with mtls") tapCmd.Flags().Bool(configStructs.TlsName, defaultTapConfig.Tls, "Record tls traffic") + tapCmd.Flags().Bool(configStructs.ProfilerName, defaultTapConfig.Profiler, "Run pprof server") } diff --git a/cli/cmd/tapRunner.go b/cli/cmd/tapRunner.go index 5f8ecbaee..8073fc29f 100644 --- a/cli/cmd/tapRunner.go +++ b/cli/cmd/tapRunner.go @@ -124,7 +124,7 @@ func RunMizuTap() { } logger.Log.Infof("Waiting for Mizu Agent to start...") - if state.mizuServiceAccountExists, err = resources.CreateTapMizuResources(ctx, kubernetesProvider, serializedValidationRules, serializedContract, serializedMizuConfig, config.Config.IsNsRestrictedMode(), config.Config.MizuResourcesNamespace, config.Config.AgentImage, getSyncEntriesConfig(), config.Config.Tap.MaxEntriesDBSizeBytes(), config.Config.Tap.ApiServerResources, config.Config.ImagePullPolicy(), config.Config.LogLevel()); err != nil { + if state.mizuServiceAccountExists, err = resources.CreateTapMizuResources(ctx, kubernetesProvider, serializedValidationRules, serializedContract, serializedMizuConfig, config.Config.IsNsRestrictedMode(), config.Config.MizuResourcesNamespace, config.Config.AgentImage, getSyncEntriesConfig(), config.Config.Tap.MaxEntriesDBSizeBytes(), config.Config.Tap.ApiServerResources, config.Config.ImagePullPolicy(), config.Config.LogLevel(), config.Config.Tap.Profiler); err != nil { var statusError *k8serrors.StatusError if errors.As(err, &statusError) && (statusError.ErrStatus.Reason == metav1.StatusReasonAlreadyExists) { logger.Log.Info("Mizu is already running in this namespace, change the `mizu-resources-namespace` configuration or run `mizu clean` to remove the currently running Mizu instance") diff --git a/cli/config/configStructs/tapConfig.go b/cli/config/configStructs/tapConfig.go index c3c4a8b35..4aba8ca7d 100644 --- a/cli/config/configStructs/tapConfig.go +++ b/cli/config/configStructs/tapConfig.go @@ -30,6 +30,7 @@ const ( ContractFile = "contract" ServiceMeshName = "service-mesh" TlsName = "tls" + ProfilerName = "profiler" ) type TapConfig struct { @@ -54,6 +55,7 @@ type TapConfig struct { TapperResources shared.Resources `yaml:"tapper-resources"` ServiceMesh bool `yaml:"service-mesh" default:"false"` Tls bool `yaml:"tls" default:"false"` + Profiler bool `yaml:"profiler" default:"false"` } func (config *TapConfig) PodRegex() *regexp.Regexp { diff --git a/cli/resources/createResources.go b/cli/resources/createResources.go index ee2f2a46b..9d359cb7d 100644 --- a/cli/resources/createResources.go +++ b/cli/resources/createResources.go @@ -14,7 +14,7 @@ import ( core "k8s.io/api/core/v1" ) -func CreateTapMizuResources(ctx context.Context, kubernetesProvider *kubernetes.Provider, serializedValidationRules string, serializedContract string, serializedMizuConfig string, isNsRestrictedMode bool, mizuResourcesNamespace string, agentImage string, syncEntriesConfig *shared.SyncEntriesConfig, maxEntriesDBSizeBytes int64, apiServerResources shared.Resources, imagePullPolicy core.PullPolicy, logLevel logging.Level) (bool, error) { +func CreateTapMizuResources(ctx context.Context, kubernetesProvider *kubernetes.Provider, serializedValidationRules string, serializedContract string, serializedMizuConfig string, isNsRestrictedMode bool, mizuResourcesNamespace string, agentImage string, syncEntriesConfig *shared.SyncEntriesConfig, maxEntriesDBSizeBytes int64, apiServerResources shared.Resources, imagePullPolicy core.PullPolicy, logLevel logging.Level, profiler bool) (bool, error) { if !isNsRestrictedMode { if err := createMizuNamespace(ctx, kubernetesProvider, mizuResourcesNamespace); err != nil { return false, err @@ -50,6 +50,7 @@ func CreateTapMizuResources(ctx context.Context, kubernetesProvider *kubernetes. Resources: apiServerResources, ImagePullPolicy: imagePullPolicy, LogLevel: logLevel, + Profiler: profiler, } if err := createMizuApiServerPod(ctx, kubernetesProvider, opts); err != nil { diff --git a/shared/kubernetes/provider.go b/shared/kubernetes/provider.go index 0994b34c7..610b3d5ab 100644 --- a/shared/kubernetes/provider.go +++ b/shared/kubernetes/provider.go @@ -181,6 +181,7 @@ type ApiServerOptions struct { Resources shared.Resources ImagePullPolicy core.PullPolicy LogLevel logging.Level + Profiler bool } func (provider *Provider) GetMizuApiServerPodObject(opts *ApiServerOptions, mountVolumeClaim bool, volumeClaimName string, createAuthContainer bool) (*core.Pod, error) { @@ -212,7 +213,15 @@ func (provider *Provider) GetMizuApiServerPodObject(opts *ApiServerOptions, moun return nil, fmt.Errorf("invalid memory request for %s container", opts.PodName) } - command := []string{"./mizuagent", "--api-server"} + command := []string{ + "./mizuagent", + "--api-server", + } + + if opts.Profiler { + command = append(command, "--profiler") + } + if opts.IsNamespaceRestricted { command = append(command, "--namespace", opts.Namespace) }