diff --git a/Dockerfile b/Dockerfile index 0fa90f951..7a15bd2b8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,10 +13,10 @@ ENV CGO_ENABLED=1 GOOS=linux GOARCH=amd64 RUN apk add libpcap-dev gcc g++ make -# Move to api working directory (/api-build). -WORKDIR /app/api-build +# Move to agent working directory (/agent-build). +WORKDIR /app/agent-build -COPY api/go.mod api/go.sum ./ +COPY agent/go.mod agent/go.sum ./ COPY shared/go.mod shared/go.mod ../shared/ COPY tap/go.mod tap/go.mod ../tap/ RUN go mod download @@ -28,10 +28,10 @@ ARG GIT_BRANCH ARG BUILD_TIMESTAMP ARG SEM_VER -# Copy and build api code +# Copy and build agent code COPY shared ../shared COPY tap ../tap -COPY api . +COPY agent . RUN go build -ldflags="-s -w \ -X 'mizuserver/pkg/version.GitCommitHash=${COMMIT_HASH}' \ -X 'mizuserver/pkg/version.Branch=${GIT_BRANCH}' \ @@ -45,10 +45,10 @@ RUN apk add bash libpcap-dev tcpdump WORKDIR /app # Copy binary and config files from /build to root folder of scratch container. -COPY --from=builder ["/app/api-build/mizuagent", "."] +COPY --from=builder ["/app/agent-build/mizuagent", "."] COPY --from=site-build ["/app/ui-build/build", "site"] -COPY api/start.sh . +COPY agent/start.sh . # this script runs both apiserver and passivetapper and exits either if one of them exits, preventing a scenario where the container runs without one process ENTRYPOINT "/app/mizuagent" diff --git a/Makefile b/Makefile index b304676bc..2de4db43c 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ SHELL=/bin/bash # HELP # This will output the help for each task # thanks to https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html -.PHONY: help ui api cli tap docker +.PHONY: help ui agent cli tap docker help: ## This help. @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) @@ -27,10 +27,10 @@ ui: ## build UI cli: # build CLI @echo "building cli"; cd cli && $(MAKE) build -api: ## build API server - @(echo "building API server .." ) - @(cd api; go build -o build/apiserver main.go) - @ls -l api/build +agent: ## build mizuagent server + @(echo "building mizu agent .." ) + @(cd agent; go build -o build/mizuagent main.go) + @ls -l agent/build #tap: ## build tap binary # @(cd tap; go build -o build/tap ./src) @@ -55,13 +55,13 @@ push-cli: gsutil setmeta -r -h "Cache-Control:public, max-age=30" gs://${BUCKET_PATH}/\* -clean: clean-ui clean-api clean-cli clean-docker ## Clean all build artifacts +clean: clean-ui clean-agent clean-cli clean-docker ## Clean all build artifacts clean-ui: @(rm -rf ui/build ; echo "UI cleanup done" ) -clean-api: - @(rm -rf api/build ; echo "api cleanup done" ) +clean-agent: + @(rm -rf agent/build ; echo "agent cleanup done" ) clean-cli: @(cd cli; make clean ; echo "CLI cleanup done" ) diff --git a/api/README.md b/agent/README.md similarity index 91% rename from api/README.md rename to agent/README.md index cfa4b4627..f275a0988 100644 --- a/api/README.md +++ b/agent/README.md @@ -1,5 +1,5 @@ -# mizu API server -API server for MIZU +# mizu agent +Agent for MIZU (API server and tapper) Basic APIs: * /fetch - retrieve traffic data * /stats - retrieve statistics of collected data @@ -14,7 +14,7 @@ Basic APIs: ### Connecting 1. Start mizu using the cli with the debug image `mizu tap --mizu-image gcr.io/up9-docker-hub/mizu/debug:latest {tapped_pod_name}` -2. Forward the debug port using `kubectl port-forward -n default mizu-collector 2345:2345` +2. Forward the debug port using `kubectl port-forward -n default mizu-api-server 2345:2345` 3. Run the run/debug configuration you've created earlier in Intellij. Do note that dlv won't start the api until a debugger connects to it. diff --git a/api/go.mod b/agent/go.mod similarity index 100% rename from api/go.mod rename to agent/go.mod diff --git a/api/go.sum b/agent/go.sum similarity index 100% rename from api/go.sum rename to agent/go.sum diff --git a/api/main.go b/agent/main.go similarity index 91% rename from api/main.go rename to agent/main.go index d5016b7f1..5ea036aa5 100644 --- a/api/main.go +++ b/agent/main.go @@ -22,16 +22,16 @@ import ( ) var shouldTap = flag.Bool("tap", false, "Run in tapper mode without API") -var aggregator = flag.Bool("aggregator", false, "Run in aggregator mode with API") +var apiServer = flag.Bool("api-server", false, "Run in API server mode with API") var standalone = flag.Bool("standalone", false, "Run in standalone tapper and API mode") -var aggregatorAddress = flag.String("aggregator-address", "", "Address of mizu collector for tapping") +var apiServerAddress = flag.String("api-server-address", "", "Address of mizu API server") func main() { flag.Parse() hostMode := os.Getenv(shared.HostModeEnvVar) == "1" tapOpts := &tap.TapOpts{HostMode: hostMode} - if !*shouldTap && !*aggregator && !*standalone { + if !*shouldTap && !*apiServer && !*standalone { panic("One of the flags --tap, --api or --standalone must be provided") } @@ -45,8 +45,8 @@ func main() { hostApi(nil) } else if *shouldTap { - if *aggregatorAddress == "" { - panic("Aggregator address must be provided with --aggregator-address when using --tap") + if *apiServerAddress == "" { + panic("API server address must be provided with --api-server-address when using --tap") } tapTargets := getTapTargets() @@ -57,14 +57,14 @@ func main() { harOutputChannel, outboundLinkOutputChannel := tap.StartPassiveTapper(tapOpts) - socketConnection, err := shared.ConnectToSocketServer(*aggregatorAddress, shared.DEFAULT_SOCKET_RETRIES, shared.DEFAULT_SOCKET_RETRY_SLEEP_TIME, false) + socketConnection, err := shared.ConnectToSocketServer(*apiServerAddress, shared.DEFAULT_SOCKET_RETRIES, shared.DEFAULT_SOCKET_RETRY_SLEEP_TIME, false) if err != nil { - panic(fmt.Sprintf("Error connecting to socket server at %s %v", *aggregatorAddress, err)) + panic(fmt.Sprintf("Error connecting to socket server at %s %v", *apiServerAddress, err)) } go pipeChannelToSocket(socketConnection, harOutputChannel) go api.StartReadingOutbound(outboundLinkOutputChannel) - } else if *aggregator { + } else if *apiServer { socketHarOutChannel := make(chan *tap.OutputChannelItem, 1000) filteredHarChannel := make(chan *tap.OutputChannelItem) diff --git a/api/pkg/api/main.go b/agent/pkg/api/main.go similarity index 100% rename from api/pkg/api/main.go rename to agent/pkg/api/main.go diff --git a/api/pkg/api/socket_server_handlers.go b/agent/pkg/api/socket_server_handlers.go similarity index 100% rename from api/pkg/api/socket_server_handlers.go rename to agent/pkg/api/socket_server_handlers.go diff --git a/api/pkg/controllers/entries_controller.go b/agent/pkg/controllers/entries_controller.go similarity index 100% rename from api/pkg/controllers/entries_controller.go rename to agent/pkg/controllers/entries_controller.go diff --git a/api/pkg/controllers/metadata_controller.go b/agent/pkg/controllers/metadata_controller.go similarity index 100% rename from api/pkg/controllers/metadata_controller.go rename to agent/pkg/controllers/metadata_controller.go diff --git a/api/pkg/controllers/resolving_controller.go b/agent/pkg/controllers/resolving_controller.go similarity index 100% rename from api/pkg/controllers/resolving_controller.go rename to agent/pkg/controllers/resolving_controller.go diff --git a/api/pkg/controllers/status_controller.go b/agent/pkg/controllers/status_controller.go similarity index 100% rename from api/pkg/controllers/status_controller.go rename to agent/pkg/controllers/status_controller.go diff --git a/api/pkg/database/main.go b/agent/pkg/database/main.go similarity index 100% rename from api/pkg/database/main.go rename to agent/pkg/database/main.go diff --git a/api/pkg/database/size_enforcer.go b/agent/pkg/database/size_enforcer.go similarity index 100% rename from api/pkg/database/size_enforcer.go rename to agent/pkg/database/size_enforcer.go diff --git a/api/pkg/holder/main.go b/agent/pkg/holder/main.go similarity index 100% rename from api/pkg/holder/main.go rename to agent/pkg/holder/main.go diff --git a/api/pkg/middleware/fiber_middleware.go b/agent/pkg/middleware/fiber_middleware.go similarity index 100% rename from api/pkg/middleware/fiber_middleware.go rename to agent/pkg/middleware/fiber_middleware.go diff --git a/api/pkg/models/models.go b/agent/pkg/models/models.go similarity index 100% rename from api/pkg/models/models.go rename to agent/pkg/models/models.go diff --git a/api/pkg/resolver/README.md b/agent/pkg/resolver/README.md similarity index 100% rename from api/pkg/resolver/README.md rename to agent/pkg/resolver/README.md diff --git a/api/pkg/resolver/go.sum b/agent/pkg/resolver/go.sum similarity index 100% rename from api/pkg/resolver/go.sum rename to agent/pkg/resolver/go.sum diff --git a/api/pkg/resolver/loader.go b/agent/pkg/resolver/loader.go similarity index 100% rename from api/pkg/resolver/loader.go rename to agent/pkg/resolver/loader.go diff --git a/api/pkg/resolver/resolver.go b/agent/pkg/resolver/resolver.go similarity index 100% rename from api/pkg/resolver/resolver.go rename to agent/pkg/resolver/resolver.go diff --git a/api/pkg/routes/entries_routes.go b/agent/pkg/routes/entries_routes.go similarity index 100% rename from api/pkg/routes/entries_routes.go rename to agent/pkg/routes/entries_routes.go diff --git a/api/pkg/routes/metadata_routes.go b/agent/pkg/routes/metadata_routes.go similarity index 100% rename from api/pkg/routes/metadata_routes.go rename to agent/pkg/routes/metadata_routes.go diff --git a/api/pkg/routes/not_found_route.go b/agent/pkg/routes/not_found_route.go similarity index 100% rename from api/pkg/routes/not_found_route.go rename to agent/pkg/routes/not_found_route.go diff --git a/api/pkg/routes/socket_routes.go b/agent/pkg/routes/socket_routes.go similarity index 100% rename from api/pkg/routes/socket_routes.go rename to agent/pkg/routes/socket_routes.go diff --git a/api/pkg/sensitiveDataFiltering/consts.go b/agent/pkg/sensitiveDataFiltering/consts.go similarity index 100% rename from api/pkg/sensitiveDataFiltering/consts.go rename to agent/pkg/sensitiveDataFiltering/consts.go diff --git a/api/pkg/sensitiveDataFiltering/messageSensitiveDataCleaner.go b/agent/pkg/sensitiveDataFiltering/messageSensitiveDataCleaner.go similarity index 100% rename from api/pkg/sensitiveDataFiltering/messageSensitiveDataCleaner.go rename to agent/pkg/sensitiveDataFiltering/messageSensitiveDataCleaner.go diff --git a/api/pkg/up9/main.go b/agent/pkg/up9/main.go similarity index 100% rename from api/pkg/up9/main.go rename to agent/pkg/up9/main.go diff --git a/api/pkg/utils/pathUtils.go b/agent/pkg/utils/pathUtils.go similarity index 100% rename from api/pkg/utils/pathUtils.go rename to agent/pkg/utils/pathUtils.go diff --git a/api/pkg/utils/randomString.go b/agent/pkg/utils/randomString.go similarity index 100% rename from api/pkg/utils/randomString.go rename to agent/pkg/utils/randomString.go diff --git a/api/pkg/utils/truncating_logger.go b/agent/pkg/utils/truncating_logger.go similarity index 100% rename from api/pkg/utils/truncating_logger.go rename to agent/pkg/utils/truncating_logger.go diff --git a/api/pkg/utils/utils.go b/agent/pkg/utils/utils.go similarity index 100% rename from api/pkg/utils/utils.go rename to agent/pkg/utils/utils.go diff --git a/api/pkg/utils/zip.go b/agent/pkg/utils/zip.go similarity index 100% rename from api/pkg/utils/zip.go rename to agent/pkg/utils/zip.go diff --git a/api/pkg/validation/validation.go b/agent/pkg/validation/validation.go similarity index 100% rename from api/pkg/validation/validation.go rename to agent/pkg/validation/validation.go diff --git a/api/pkg/version/consts.go b/agent/pkg/version/consts.go similarity index 100% rename from api/pkg/version/consts.go rename to agent/pkg/version/consts.go diff --git a/api/start.sh b/agent/start.sh similarity index 100% rename from api/start.sh rename to agent/start.sh diff --git a/cli/cmd/fetchRunner.go b/cli/cmd/fetchRunner.go index 36e6182f9..0baa437c4 100644 --- a/cli/cmd/fetchRunner.go +++ b/cli/cmd/fetchRunner.go @@ -15,7 +15,7 @@ import ( ) func RunMizuFetch(fetch *MizuFetchOptions) { - mizuProxiedUrl := kubernetes.GetMizuCollectorProxiedHostAndPath(fetch.MizuPort) + mizuProxiedUrl := kubernetes.GetMizuApiServerProxiedHostAndPath(fetch.MizuPort) resp, err := http.Get(fmt.Sprintf("http://%s/api/har?from=%v&to=%v", mizuProxiedUrl, fetch.FromTimestamp, fetch.ToTimestamp)) if err != nil { log.Fatal(err) diff --git a/cli/cmd/tap.go b/cli/cmd/tap.go index bdf7b732c..6d62e0084 100644 --- a/cli/cmd/tap.go +++ b/cli/cmd/tap.go @@ -99,7 +99,7 @@ func init() { tapCmd.Flags().Uint16VarP(&mizuTapOptions.SleepIntervalSec, "upload-interval", "", 10, "Interval in seconds for uploading data to UP9") tapCmd.Flags().BoolVarP(&mizuTapOptions.AllNamespaces, "all-namespaces", "A", false, "Tap all namespaces") tapCmd.Flags().StringVarP(&mizuTapOptions.KubeConfigPath, "kube-config", "k", "", "Path to kube-config file") - tapCmd.Flags().StringVarP(&mizuTapOptions.MizuImage, "mizu-image", "", fmt.Sprintf("gcr.io/up9-docker-hub/mizu/%s:%s", mizu.Branch, mizu.SemVer), "Custom image for mizu collector") + tapCmd.Flags().StringVarP(&mizuTapOptions.MizuImage, "mizu-image", "", fmt.Sprintf("gcr.io/up9-docker-hub/mizu/%s:%s", mizu.Branch, mizu.SemVer), "Custom image for mizu API server") tapCmd.Flags().StringArrayVarP(&mizuTapOptions.PlainTextFilterRegexes, "regex-masking", "r", nil, "List of regex expressions that are used to filter matching values from text/plain http bodies") tapCmd.Flags().StringVarP(&direction, "direction", "", "in", "Record traffic that goes in this direction (relative to the tapped pod): in/any") tapCmd.Flags().BoolVar(&mizuTapOptions.HideHealthChecks, "hide-healthchecks", false, "hides requests with kube-probe or prometheus user-agent headers") diff --git a/cli/cmd/tapRunner.go b/cli/cmd/tapRunner.go index 3301f9341..e086f6c82 100644 --- a/cli/cmd/tapRunner.go +++ b/cli/cmd/tapRunner.go @@ -22,7 +22,7 @@ import ( ) var mizuServiceAccountExists bool -var aggregatorService *core.Service +var apiServerService *core.Service const ( updateTappersDelay = 5 * time.Second @@ -100,7 +100,7 @@ func createMizuResources(ctx context.Context, kubernetesProvider *kubernetes.Pro return err } - if err := createMizuAggregator(ctx, kubernetesProvider, tappingOptions, mizuApiFilteringOptions); err != nil { + if err := createMizuApiServer(ctx, kubernetesProvider, tappingOptions, mizuApiFilteringOptions); err != nil { return err } @@ -120,7 +120,7 @@ func createMizuNamespace(ctx context.Context, kubernetesProvider *kubernetes.Pro return err } -func createMizuAggregator(ctx context.Context, kubernetesProvider *kubernetes.Provider, tappingOptions *MizuTapOptions, mizuApiFilteringOptions *shared.TrafficFilteringOptions) error { +func createMizuApiServer(ctx context.Context, kubernetesProvider *kubernetes.Provider, tappingOptions *MizuTapOptions, mizuApiFilteringOptions *shared.TrafficFilteringOptions) error { var err error mizuServiceAccountExists = createRBACIfNecessary(ctx, kubernetesProvider) @@ -130,15 +130,15 @@ func createMizuAggregator(ctx context.Context, kubernetesProvider *kubernetes.Pr } else { serviceAccountName = "" } - _, err = kubernetesProvider.CreateMizuAggregatorPod(ctx, mizu.ResourcesNamespace, mizu.AggregatorPodName, tappingOptions.MizuImage, serviceAccountName, mizuApiFilteringOptions, tappingOptions.MaxEntriesDBSizeBytes) + _, err = kubernetesProvider.CreateMizuApiServerPod(ctx, mizu.ResourcesNamespace, mizu.ApiServerPodName, tappingOptions.MizuImage, serviceAccountName, mizuApiFilteringOptions, tappingOptions.MaxEntriesDBSizeBytes) if err != nil { - fmt.Printf("Error creating mizu collector pod: %v\n", err) + fmt.Printf("Error creating mizu %s pod: %v\n", mizu.ApiServerPodName, err) return err } - aggregatorService, err = kubernetesProvider.CreateService(ctx, mizu.ResourcesNamespace, mizu.AggregatorPodName, mizu.AggregatorPodName) + apiServerService, err = kubernetesProvider.CreateService(ctx, mizu.ResourcesNamespace, mizu.ApiServerPodName, mizu.ApiServerPodName) if err != nil { - fmt.Printf("Error creating mizu collector service: %v\n", err) + fmt.Printf("Error creating mizu %s service: %v\n", mizu.ApiServerPodName, err) return err } @@ -178,7 +178,7 @@ func updateMizuTappers(ctx context.Context, kubernetesProvider *kubernetes.Provi mizu.TapperDaemonSetName, tappingOptions.MizuImage, mizu.TapperPodName, - fmt.Sprintf("%s.%s.svc.cluster.local", aggregatorService.Name, aggregatorService.Namespace), + fmt.Sprintf("%s.%s.svc.cluster.local", apiServerService.Name, apiServerService.Namespace), nodeToTappedPodIPMap, serviceAccountName, tappingOptions.TapOutgoing, @@ -288,7 +288,7 @@ func watchPodsForTapping(ctx context.Context, kubernetesProvider *kubernetes.Pro } func portForwardApiPod(ctx context.Context, kubernetesProvider *kubernetes.Provider, cancel context.CancelFunc, tappingOptions *MizuTapOptions) { - podExactRegex := regexp.MustCompile(fmt.Sprintf("^%s$", mizu.AggregatorPodName)) + podExactRegex := regexp.MustCompile(fmt.Sprintf("^%s$", mizu.ApiServerPodName)) added, modified, removed, errorChan := kubernetes.FilteredWatch(ctx, kubernetesProvider.GetPodWatcher(ctx, mizu.ResourcesNamespace), podExactRegex) isPodReady := false timeAfter := time.After(25 * time.Second) @@ -300,20 +300,20 @@ func portForwardApiPod(ctx context.Context, kubernetesProvider *kubernetes.Provi case <-added: continue case <-removed: - fmt.Printf("%s removed\n", mizu.AggregatorPodName) + fmt.Printf("%s removed\n", mizu.ApiServerPodName) cancel() return case modifiedPod := <-modified: if modifiedPod.Status.Phase == "Running" && !isPodReady { isPodReady = true go func() { - err := kubernetes.StartProxy(kubernetesProvider, tappingOptions.GuiPort, mizu.ResourcesNamespace, mizu.AggregatorPodName) + err := kubernetes.StartProxy(kubernetesProvider, tappingOptions.GuiPort, mizu.ResourcesNamespace, mizu.ApiServerPodName) if err != nil { fmt.Printf("Error occured while running k8s proxy %v\n", err) cancel() } }() - mizuProxiedUrl := kubernetes.GetMizuCollectorProxiedHostAndPath(tappingOptions.GuiPort) + mizuProxiedUrl := kubernetes.GetMizuApiServerProxiedHostAndPath(tappingOptions.GuiPort) fmt.Printf("Mizu is available at http://%s\n", mizuProxiedUrl) time.Sleep(time.Second * 5) // Waiting to be sure the proxy is ready @@ -336,7 +336,7 @@ func portForwardApiPod(ctx context.Context, kubernetesProvider *kubernetes.Provi case <-timeAfter: if !isPodReady { - fmt.Printf("error: %s pod was not ready in time", mizu.AggregatorPodName) + fmt.Printf("error: %s pod was not ready in time", mizu.ApiServerPodName) cancel() } @@ -389,7 +389,7 @@ func waitForFinish(ctx context.Context, cancel context.CancelFunc) { } func syncApiStatus(ctx context.Context, cancel context.CancelFunc, tappingOptions *MizuTapOptions) { - controlSocketStr := fmt.Sprintf("ws://%s/ws", kubernetes.GetMizuCollectorProxiedHostAndPath(tappingOptions.GuiPort)) + controlSocketStr := fmt.Sprintf("ws://%s/ws", kubernetes.GetMizuApiServerProxiedHostAndPath(tappingOptions.GuiPort)) controlSocket, err := mizu.CreateControlSocket(controlSocketStr) if err != nil { fmt.Printf("error establishing control socket connection %s\n", err) diff --git a/cli/cmd/viewRunner.go b/cli/cmd/viewRunner.go index d37a85559..d339010a7 100644 --- a/cli/cmd/viewRunner.go +++ b/cli/cmd/viewRunner.go @@ -25,25 +25,25 @@ func runMizuView(mizuViewOptions *MizuViewOptions) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - exists, err := kubernetesProvider.DoesServicesExist(ctx, mizu.ResourcesNamespace, mizu.AggregatorPodName) + exists, err := kubernetesProvider.DoesServicesExist(ctx, mizu.ResourcesNamespace, mizu.ApiServerPodName) if err != nil { panic(err) } if !exists { - fmt.Printf("The %s service not found\n", mizu.AggregatorPodName) + fmt.Printf("The %s service not found\n", mizu.ApiServerPodName) return } - mizuProxiedUrl := kubernetes.GetMizuCollectorProxiedHostAndPath(mizuViewOptions.GuiPort) + mizuProxiedUrl := kubernetes.GetMizuApiServerProxiedHostAndPath(mizuViewOptions.GuiPort) _, err = http.Get(fmt.Sprintf("http://%s/", mizuProxiedUrl)) if err == nil { - fmt.Printf("Found a running service %s and open port %d\n", mizu.AggregatorPodName, mizuViewOptions.GuiPort) + fmt.Printf("Found a running service %s and open port %d\n", mizu.ApiServerPodName, mizuViewOptions.GuiPort) return } - fmt.Printf("Found service %s, creating k8s proxy\n", mizu.AggregatorPodName) + fmt.Printf("Found service %s, creating k8s proxy\n", mizu.ApiServerPodName) - fmt.Printf("Mizu is available at http://%s\n", kubernetes.GetMizuCollectorProxiedHostAndPath(mizuViewOptions.GuiPort)) - err = kubernetes.StartProxy(kubernetesProvider, mizuViewOptions.GuiPort, mizu.ResourcesNamespace, mizu.AggregatorPodName) + fmt.Printf("Mizu is available at http://%s\n", kubernetes.GetMizuApiServerProxiedHostAndPath(mizuViewOptions.GuiPort)) + err = kubernetes.StartProxy(kubernetesProvider, mizuViewOptions.GuiPort, mizu.ResourcesNamespace, mizu.ApiServerPodName) if err != nil { fmt.Printf("Error occured while running k8s proxy %v\n", err) } diff --git a/cli/kubernetes/provider.go b/cli/kubernetes/provider.go index df62afae7..bf40986c3 100644 --- a/cli/kubernetes/provider.go +++ b/cli/kubernetes/provider.go @@ -124,7 +124,7 @@ func (provider *Provider) CreateNamespace(ctx context.Context, name string) (*co return provider.clientSet.CoreV1().Namespaces().Create(ctx, namespaceSpec, metav1.CreateOptions{}) } -func (provider *Provider) CreateMizuAggregatorPod(ctx context.Context, namespace string, podName string, podImage string, serviceAccountName string, mizuApiFilteringOptions *shared.TrafficFilteringOptions, maxEntriesDBSizeBytes int64) (*core.Pod, error) { +func (provider *Provider) CreateMizuApiServerPod(ctx context.Context, namespace string, podName string, podImage string, serviceAccountName string, mizuApiFilteringOptions *shared.TrafficFilteringOptions, maxEntriesDBSizeBytes int64) (*core.Pod, error) { marshaledFilteringOptions, err := json.Marshal(mizuApiFilteringOptions) if err != nil { return nil, err @@ -132,19 +132,19 @@ func (provider *Provider) CreateMizuAggregatorPod(ctx context.Context, namespace cpuLimit, err := resource.ParseQuantity("750m") if err != nil { - return nil, errors.New("invalid cpu limit for aggregator container") + return nil, errors.New(fmt.Sprintf("invalid cpu limit for %s container", podName)) } memLimit, err := resource.ParseQuantity("512Mi") if err != nil { - return nil, errors.New("invalid memory limit for aggregator container") + return nil, errors.New(fmt.Sprintf("invalid memory limit for %s container", podName)) } cpuRequests, err := resource.ParseQuantity("50m") if err != nil { - return nil, errors.New("invalid cpu request for aggregator container") + return nil, errors.New(fmt.Sprintf("invalid cpu request for %s container", podName)) } memRequests, err := resource.ParseQuantity("50Mi") if err != nil { - return nil, errors.New("invalid memory request for aggregator container") + return nil, errors.New(fmt.Sprintf("invalid memory request for %s container", podName)) } pod := &core.Pod{ @@ -159,7 +159,7 @@ func (provider *Provider) CreateMizuAggregatorPod(ctx context.Context, namespace Name: podName, Image: podImage, ImagePullPolicy: core.PullAlways, - Command: []string{"./mizuagent", "--aggregator"}, + Command: []string{"./mizuagent", "--api-server"}, Env: []core.EnvVar{ { Name: shared.HostModeEnvVar, @@ -471,7 +471,7 @@ func (provider *Provider) CheckDaemonSetExists(ctx context.Context, namespace st return false, nil } -func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespace string, daemonSetName string, podImage string, tapperPodName string, aggregatorPodIp string, nodeToTappedPodIPMap map[string][]string, serviceAccountName string, tapOutgoing 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, tapOutgoing bool) error { if len(nodeToTappedPodIPMap) == 0 { return fmt.Errorf("Daemon set %s must tap at least 1 pod", daemonSetName) } @@ -486,7 +486,7 @@ func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespac "-i", "any", "--tap", "--hardump", - "--aggregator-address", fmt.Sprintf("ws://%s/wsTapper", aggregatorPodIp), + "--api-server-address", fmt.Sprintf("ws://%s/wsTapper", apiServerPodIp), } if tapOutgoing { mizuCmd = append(mizuCmd, "--anydirection") @@ -512,19 +512,19 @@ func (provider *Provider) ApplyMizuTapperDaemonSet(ctx context.Context, namespac ) cpuLimit, err := resource.ParseQuantity("500m") if err != nil { - return errors.New("invalid cpu limit for tapper container") + return errors.New(fmt.Sprintf("invalid cpu limit for %s container", tapperPodName)) } memLimit, err := resource.ParseQuantity("1Gi") if err != nil { - return errors.New("invalid memory limit for tapper container") + return errors.New(fmt.Sprintf("invalid memory limit for %s container", tapperPodName)) } cpuRequests, err := resource.ParseQuantity("50m") if err != nil { - return errors.New("invalid cpu request for tapper container") + return errors.New(fmt.Sprintf("invalid cpu request for %s container", tapperPodName)) } memRequests, err := resource.ParseQuantity("50Mi") if err != nil { - return errors.New("invalid memory request for tapper container") + return errors.New(fmt.Sprintf("invalid memory request for %s container", tapperPodName)) } agentResourceLimits := core.ResourceList{ "cpu": cpuLimit, diff --git a/cli/kubernetes/proxy.go b/cli/kubernetes/proxy.go index 77904ddaa..2d2967bd4 100644 --- a/cli/kubernetes/proxy.go +++ b/cli/kubernetes/proxy.go @@ -40,24 +40,24 @@ func StartProxy(kubernetesProvider *Provider, mizuPort uint16, mizuNamespace str return server.Serve(l) } -func getMizuCollectorProxiedHostAndPath(mizuNamespace string, mizuServiceName string) string { +func getMizuApiServerProxiedHostAndPath(mizuNamespace string, mizuServiceName string) string { return fmt.Sprintf("/api/v1/namespaces/%s/services/%s:%d/proxy/", mizuNamespace, mizuServiceName, mizuServicePort) } -func GetMizuCollectorProxiedHostAndPath(mizuPort uint16) string { +func GetMizuApiServerProxiedHostAndPath(mizuPort uint16) string { return fmt.Sprintf("localhost:%d/mizu", mizuPort) } func getRerouteHttpHandlerMizuAPI(proxyHandler http.Handler, mizuNamespace string, mizuServiceName string) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - r.URL.Path = strings.Replace(r.URL.Path, "/mizu/", getMizuCollectorProxiedHostAndPath(mizuNamespace, mizuServiceName), 1) + r.URL.Path = strings.Replace(r.URL.Path, "/mizu/", getMizuApiServerProxiedHostAndPath(mizuNamespace, mizuServiceName), 1) proxyHandler.ServeHTTP(w, r) }) } func getRerouteHttpHandlerMizuStatic(proxyHandler http.Handler, mizuNamespace string, mizuServiceName string) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - r.URL.Path = strings.Replace(r.URL.Path, "/static/", fmt.Sprintf("%s/static/", getMizuCollectorProxiedHostAndPath(mizuNamespace, mizuServiceName)), 1) + r.URL.Path = strings.Replace(r.URL.Path, "/static/", fmt.Sprintf("%s/static/", getMizuApiServerProxiedHostAndPath(mizuNamespace, mizuServiceName)), 1) proxyHandler.ServeHTTP(w, r) }) } diff --git a/cli/mizu/consts.go b/cli/mizu/consts.go index 45d2a2246..6874069d5 100644 --- a/cli/mizu/consts.go +++ b/cli/mizu/consts.go @@ -9,7 +9,7 @@ var ( ) const ( - AggregatorPodName = "mizu-collector" + ApiServerPodName = "mizu-api-server" ClusterRoleBindingName = "mizu-cluster-role-binding" ClusterRoleName = "mizu-cluster-role" K8sAllNamespaces = "" diff --git a/debug.Dockerfile b/debug.Dockerfile index c894d2f27..f3145d218 100644 --- a/debug.Dockerfile +++ b/debug.Dockerfile @@ -1,4 +1,4 @@ -# creates image in which mizu api is remotely debuggable using delve +# creates image in which mizu agent is remotely debuggable using delve FROM node:14-slim AS site-build WORKDIR /app/ui-build @@ -14,10 +14,10 @@ ENV CGO_ENABLED=1 GOOS=linux GOARCH=amd64 RUN apk add libpcap-dev gcc g++ make -# Move to api working directory (/api-build). -WORKDIR /app/api-build +# Move to agent working directory (/agent-build). +WORKDIR /app/agent-build -COPY api/go.mod api/go.sum ./ +COPY agent/go.mod agent/go.sum ./ COPY shared/go.mod shared/go.mod ../shared/ COPY tap/go.mod tap/go.mod ../tap/ @@ -25,10 +25,10 @@ RUN go mod download # cheap trick to make the build faster (As long as go.mod wasn't changes) RUN go list -f '{{.Path}}@{{.Version}}' -m all | sed 1d | grep -e 'go-cache' -e 'sqlite' | xargs go get -# Copy and build api code +# Copy and build agent code COPY shared ../shared COPY tap ../tap -COPY api . +COPY agent . RUN go build -gcflags="all=-N -l" -o mizuagent . @@ -38,11 +38,11 @@ RUN apk add bash libpcap-dev tcpdump WORKDIR /app # Copy binary and config files from /build to root folder of scratch container. -COPY --from=builder ["/app/api-build/mizuagent", "."] +COPY --from=builder ["/app/agent-build/mizuagent", "."] COPY --from=site-build ["/app/ui-build/build", "site"] # install remote debugging tool RUN go get github.com/go-delve/delve/cmd/dlv ENTRYPOINT "/app/mizuagent" -#CMD ["sh", "-c", "dlv --headless=true --listen=:2345 --log --api-version=2 --accept-multiclient exec ./mizuagent -- --aggregator"] +#CMD ["sh", "-c", "dlv --headless=true --listen=:2345 --log --api-version=2 --accept-multiclient exec ./mizuagent -- --api-server"] diff --git a/tap/passive_tapper.go b/tap/passive_tapper.go index 0625c666d..c1eef2c75 100644 --- a/tap/passive_tapper.go +++ b/tap/passive_tapper.go @@ -33,8 +33,7 @@ import ( const AppPortsEnvVar = "APP_PORTS" const maxHTTP2DataLenEnvVar = "HTTP2_DATA_SIZE_LIMIT" -// default is 1MB, more than the max size accepted by collector and traffic-dumper -const maxHTTP2DataLenDefault = 1 * 1024 * 1024 +const maxHTTP2DataLenDefault = 1 * 1024 * 1024 // 1MB const cleanPeriod = time.Second * 10 var remoteOnlyOutboundPorts = []int { 80, 443 }