diff --git a/agent/pkg/controllers/entries_controller.go b/agent/pkg/controllers/entries_controller.go index 4737884ff..a7fe7a6dc 100644 --- a/agent/pkg/controllers/entries_controller.go +++ b/agent/pkg/controllers/entries_controller.go @@ -64,15 +64,15 @@ func GetEntries(c *gin.Context) { c.JSON(http.StatusOK, baseEntries) } -func UploadEntries(c *gin.Context) { - rlog.Infof("Upload entries - started\n") +func SyncEntries(c *gin.Context) { + rlog.Infof("Sync entries - started\n") - uploadParams := &models.UploadEntriesRequestQuery{} - if err := c.BindQuery(uploadParams); err != nil { + syncParams := &models.SyncEntriesRequestQuery{} + if err := c.BindQuery(syncParams); err != nil { c.JSON(http.StatusBadRequest, err) return } - if err := validation.Validate(uploadParams); err != nil { + if err := validation.Validate(syncParams); err != nil { c.JSON(http.StatusBadRequest, err) return } @@ -81,14 +81,14 @@ func UploadEntries(c *gin.Context) { return } - rlog.Infof("Upload entries - creating token. dest %s\n", uploadParams.Dest) - token, err := up9.CreateAnonymousToken(uploadParams.Dest) + rlog.Infof("Sync entries - creating token. env %s\n", syncParams.Env) + token, err := up9.CreateAnonymousToken(syncParams.Env) if err != nil { c.String(http.StatusServiceUnavailable, "Cannot analyze, mizu is already analyzing") return } - rlog.Infof("Upload entries - uploading. token: %s model: %s\n", token.Token, token.Model) - go up9.UploadEntriesImpl(token.Token, token.Model, uploadParams.Dest, uploadParams.SleepIntervalSec) + rlog.Infof("Sync entries - syncing. token: %s model: %s\n", token.Token, token.Model) + go up9.SyncEntriesImpl(token.Token, token.Model, syncParams.Env, syncParams.SleepIntervalSec) c.String(http.StatusOK, "OK") } diff --git a/agent/pkg/models/models.go b/agent/pkg/models/models.go index 3356dc75a..66416f6f8 100644 --- a/agent/pkg/models/models.go +++ b/agent/pkg/models/models.go @@ -22,8 +22,8 @@ type EntriesFilter struct { Timestamp int64 `form:"timestamp" validate:"required,min=1"` } -type UploadEntriesRequestQuery struct { - Dest string `form:"dest"` +type SyncEntriesRequestQuery struct { + Env string `form:"env"` SleepIntervalSec int `form:"interval"` } diff --git a/agent/pkg/routes/entries_routes.go b/agent/pkg/routes/entries_routes.go index 12d901d0f..1267a5ea1 100644 --- a/agent/pkg/routes/entries_routes.go +++ b/agent/pkg/routes/entries_routes.go @@ -12,7 +12,7 @@ func EntriesRoutes(ginApp *gin.Engine) { routeGroup.GET("/entries", controllers.GetEntries) // get entries (base/thin entries) routeGroup.GET("/entries/:entryId", controllers.GetEntry) // get single (full) entry routeGroup.GET("/exportEntries", controllers.GetFullEntries) - routeGroup.GET("/uploadEntries", controllers.UploadEntries) + routeGroup.GET("/syncEntries", controllers.SyncEntries) routeGroup.GET("/resolving", controllers.GetCurrentResolvingInformation) routeGroup.GET("/resetDB", controllers.DeleteAllEntries) // get single (full) entry diff --git a/agent/pkg/up9/main.go b/agent/pkg/up9/main.go index bfdd7d12d..3633c4217 100644 --- a/agent/pkg/up9/main.go +++ b/agent/pkg/up9/main.go @@ -117,7 +117,7 @@ func GetAnalyzeInfo() *shared.AnalyzeStatus { } } -func UploadEntriesImpl(token string, model string, envPrefix string, sleepIntervalSec int) { +func SyncEntriesImpl(token string, model string, envPrefix string, sleepIntervalSec int) { analyzeInformation.IsAnalyzing = true analyzeInformation.AnalyzedModel = model analyzeInformation.AnalyzeToken = token @@ -160,7 +160,7 @@ func UploadEntriesImpl(token string, model string, envPrefix string, sleepInterv body, jMarshalErr := json.Marshal(result) if jMarshalErr != nil { analyzeInformation.Reset() - rlog.Infof("Stopping analyzing") + rlog.Infof("Stopping sync entries") log.Fatal(jMarshalErr) } @@ -183,7 +183,7 @@ func UploadEntriesImpl(token string, model string, envPrefix string, sleepInterv if _, postErr := http.DefaultClient.Do(req); postErr != nil { analyzeInformation.Reset() - rlog.Info("Stopping analyzing") + rlog.Info("Stopping sync entries") log.Fatal(postErr) } analyzeInformation.SentCount += len(entriesArray) diff --git a/cli/apiserver/provider.go b/cli/apiserver/provider.go index 7555eb587..5bd3e6771 100644 --- a/cli/apiserver/provider.go +++ b/cli/apiserver/provider.go @@ -82,23 +82,23 @@ func (provider *apiServerProvider) ReportTappedPods(pods []core.Pod) error { } } -func (provider *apiServerProvider) RequestAnalysis(analysisDestination string, sleepIntervalSec int) error { +func (provider *apiServerProvider) RequestSyncEntries(analysisDestination string, sleepIntervalSec int) error { if !provider.isReady { return fmt.Errorf("trying to reach api server when not initialized yet") } - urlPath := fmt.Sprintf("%s/api/uploadEntries?dest=%s&interval=%v", provider.url, url.QueryEscape(analysisDestination), sleepIntervalSec) - u, parseErr := url.ParseRequestURI(urlPath) + urlPath := fmt.Sprintf("%s/api/syncEntries?env=%s&interval=%v", provider.url, url.QueryEscape(analysisDestination), sleepIntervalSec) + syncEntriesUrl, parseErr := url.ParseRequestURI(urlPath) if parseErr != nil { - logger.Log.Fatal("Failed parsing the URL (consider changing the analysis dest URL), err: %v", parseErr) + logger.Log.Fatal("Failed parsing the URL (consider changing the env name), err: %v", parseErr) } - logger.Log.Debugf("Analysis url %v", u.String()) - if response, requestErr := http.Get(u.String()); requestErr != nil { - return fmt.Errorf("failed to notify agent for analysis, err: %w", requestErr) + logger.Log.Debugf("Sync entries url %v", syncEntriesUrl.String()) + if response, requestErr := http.Get(syncEntriesUrl.String()); requestErr != nil { + return fmt.Errorf("failed to notify api server for sync entries, err: %w", requestErr) } else if response.StatusCode != 200 { - return fmt.Errorf("failed to notify agent for analysis, status code: %v", response.StatusCode) + return fmt.Errorf("failed to notify api server for sync entries, status code: %v", response.StatusCode) } else { - logger.Log.Infof(uiUtils.Purple, "Traffic is uploading to UP9 for further analysis") + logger.Log.Infof(uiUtils.Purple, "Entries are syncing to UP9 for further analysis") return nil } } diff --git a/cli/cmd/tapRunner.go b/cli/cmd/tapRunner.go index 55791019d..c75ecdab1 100644 --- a/cli/cmd/tapRunner.go +++ b/cli/cmd/tapRunner.go @@ -579,7 +579,7 @@ func watchApiServerPod(ctx context.Context, kubernetesProvider *kubernetes.Provi logger.Log.Infof("Mizu is available at %s\n", url) uiUtils.OpenBrowser(url) - requestForAnalysisIfNeeded() + requestForSyncEntriesIfNeeded() if err := apiserver.Provider.ReportTappedPods(state.currentlyTappedPods); err != nil { logger.Log.Debugf("[Error] failed update tapped pods %v", err) } @@ -671,12 +671,12 @@ func watchTapperPod(ctx context.Context, kubernetesProvider *kubernetes.Provider } } -func requestForAnalysisIfNeeded() { +func requestForSyncEntriesIfNeeded() { if !config.Config.Tap.Analysis { return } - if err := apiserver.Provider.RequestAnalysis(config.Config.Tap.AnalysisDestination, config.Config.Tap.SleepIntervalSec); err != nil { - logger.Log.Debugf("[Error] failed requesting for analysis %v", err) + if err := apiserver.Provider.RequestSyncEntries(config.Config.Tap.AnalysisDestination, config.Config.Tap.UploadIntervalSec); err != nil { + logger.Log.Debugf("[Error] failed requesting for sync entries, err: %v", err) } } diff --git a/cli/config/configStructs/tapConfig.go b/cli/config/configStructs/tapConfig.go index 80c15375a..eda9674aa 100644 --- a/cli/config/configStructs/tapConfig.go +++ b/cli/config/configStructs/tapConfig.go @@ -20,21 +20,21 @@ const ( ) type TapConfig struct { - AnalysisDestination string `yaml:"dest" default:"up9.app"` - SleepIntervalSec int `yaml:"upload-interval" default:"10"` - PodRegexStr string `yaml:"regex" default:".*"` - GuiPort uint16 `yaml:"gui-port" default:"8899"` - Namespaces []string `yaml:"namespaces"` - Analysis bool `yaml:"analysis" default:"false"` - AllNamespaces bool `yaml:"all-namespaces" default:"false"` - PlainTextFilterRegexes []string `yaml:"regex-masking"` - IgnoredUserAgents []string `yaml:"ignored-user-agents"` - DisableRedaction bool `yaml:"no-redact" default:"false"` - HumanMaxEntriesDBSize string `yaml:"max-entries-db-size" default:"200MB"` - DryRun bool `yaml:"dry-run" default:"false"` - EnforcePolicyFile string `yaml:"traffic-validation-file"` - ApiServerResources Resources `yaml:"api-server-resources"` - TapperResources Resources `yaml:"tapper-resources"` + AnalysisDestination string `yaml:"dest" default:"up9.app"` + UploadIntervalSec int `yaml:"upload-interval" default:"10"` + PodRegexStr string `yaml:"regex" default:".*"` + GuiPort uint16 `yaml:"gui-port" default:"8899"` + Namespaces []string `yaml:"namespaces"` + Analysis bool `yaml:"analysis" default:"false"` + AllNamespaces bool `yaml:"all-namespaces" default:"false"` + PlainTextFilterRegexes []string `yaml:"regex-masking"` + IgnoredUserAgents []string `yaml:"ignored-user-agents"` + DisableRedaction bool `yaml:"no-redact" default:"false"` + HumanMaxEntriesDBSize string `yaml:"max-entries-db-size" default:"200MB"` + DryRun bool `yaml:"dry-run" default:"false"` + EnforcePolicyFile string `yaml:"traffic-validation-file"` + ApiServerResources Resources `yaml:"api-server-resources"` + TapperResources Resources `yaml:"tapper-resources"` } type Resources struct {