diff --git a/api/v1/group_routes_test.go b/api/v1/group_routes_test.go index bb33aa01a0f3..84cc8dcd3416 100644 --- a/api/v1/group_routes_test.go +++ b/api/v1/group_routes_test.go @@ -45,7 +45,7 @@ func getControlSurface(tb testing.TB, testState *lib.TestRunState) *ControlSurfa execScheduler, err := execution.NewScheduler(testState, local.NewController()) require.NoError(tb, err) - me, err := engine.NewMetricsEngine(testState, true) + me, err := engine.NewMetricsEngine(testState.Registry, testState.Logger) require.NoError(tb, err) ctx, cancel := context.WithCancel(context.Background()) diff --git a/api/v1/setup_teardown_routes_test.go b/api/v1/setup_teardown_routes_test.go index b05ac94ba8a4..5a804eca21d6 100644 --- a/api/v1/setup_teardown_routes_test.go +++ b/api/v1/setup_teardown_routes_test.go @@ -141,7 +141,7 @@ func TestSetupData(t *testing.T) { execScheduler, err := execution.NewScheduler(testState, local.NewController()) require.NoError(t, err) - metricsEngine, err := engine.NewMetricsEngine(testState, true) + metricsEngine, err := engine.NewMetricsEngine(testState.Registry, testState.Logger) require.NoError(t, err) globalCtx, globalCancel := context.WithCancel(context.Background()) diff --git a/api/v1/status_routes_test.go b/api/v1/status_routes_test.go index ad8b099868f3..9328ae1505f8 100644 --- a/api/v1/status_routes_test.go +++ b/api/v1/status_routes_test.go @@ -116,7 +116,7 @@ func TestPatchStatus(t *testing.T) { execScheduler, err := execution.NewScheduler(testState, local.NewController()) require.NoError(t, err) - metricsEngine, err := engine.NewMetricsEngine(testState, true) + metricsEngine, err := engine.NewMetricsEngine(testState.Registry, testState.Logger) require.NoError(t, err) globalCtx, globalCancel := context.WithCancel(context.Background()) diff --git a/cmd/agent.go b/cmd/agent.go index 7167ddbf89b9..06e3a3811647 100644 --- a/cmd/agent.go +++ b/cmd/agent.go @@ -85,12 +85,72 @@ func getMetricsHook( } } +func loadAndConfigureDistTest(gs *state.GlobalState, distTest *distributed.Test) (*loadedAndConfiguredTest, error) { + var options lib.Options + if err := json.Unmarshal(distTest.Options, &options); err != nil { + return nil, err + } + + arc, err := lib.ReadArchive(bytes.NewReader(distTest.Archive)) + if err != nil { + return nil, err + } + + registry := metrics.NewRegistry() + piState := &lib.TestPreInitState{ + Logger: gs.Logger, + RuntimeOptions: lib.RuntimeOptions{ + NoThresholds: null.BoolFrom(true), + NoSummary: null.BoolFrom(true), + Env: arc.Env, + CompatibilityMode: null.StringFrom(arc.CompatibilityMode), + }, + Registry: registry, + BuiltinMetrics: metrics.RegisterBuiltinMetrics(registry), + } + + initRunner, err := js.NewFromArchive(piState, arc) + if err != nil { + return nil, err + } + + test := &loadedTest{ + pwd: arc.Pwd, + sourceRootPath: arc.Filename, + source: &loader.SourceData{ + Data: distTest.Archive, + URL: arc.FilenameURL, + }, + fs: afero.NewMemMapFs(), // TODO: figure out what should be here + fileSystems: arc.Filesystems, + preInitState: piState, + initRunner: initRunner, + } + + pseudoConsoldatedConfig := applyDefault(Config{Options: options}) + for _, thresholds := range pseudoConsoldatedConfig.Thresholds { + if err = thresholds.Parse(); err != nil { + return nil, err + } + } + derivedConfig, err := deriveAndValidateConfig(pseudoConsoldatedConfig, initRunner.IsExecutable, gs.Logger) + if err != nil { + return nil, err + } + + return &loadedAndConfiguredTest{ + loadedTest: test, + consolidatedConfig: pseudoConsoldatedConfig, + derivedConfig: derivedConfig, + }, nil +} + // TODO: a whole lot of cleanup, refactoring, error handling and hardening -func getCmdAgent(gs *state.GlobalState) *cobra.Command { //nolint: funlen +func getCmdAgent(gs *state.GlobalState) *cobra.Command { c := &cmdsRunAndAgent{gs: gs} - c.loadConfiguredTest = func(cmd *cobra.Command, args []string) ( - *loadedAndConfiguredTest, execution.Controller, error, + c.loadConfiguredTests = func(cmd *cobra.Command, args []string) ( + []*loadedAndConfiguredTest, execution.Controller, error, ) { conn, err := grpc.Dial(args[0], grpc.WithInsecure()) if err != nil { @@ -108,74 +168,25 @@ func getCmdAgent(gs *state.GlobalState) *cobra.Command { //nolint: funlen return nil, nil, err } - c.metricsEngineHook = getMetricsHook(gs.Ctx, resp.InstanceID, client, gs.Logger) - - controller, err := distributed.NewAgentController(gs.Ctx, resp.InstanceID, client, gs.Logger) - if err != nil { - return nil, nil, err - } - - var options lib.Options - if err := json.Unmarshal(resp.Options, &options); err != nil { - return nil, nil, err - } - - arc, err := lib.ReadArchive(bytes.NewReader(resp.Archive)) - if err != nil { - return nil, nil, err - } - - registry := metrics.NewRegistry() - piState := &lib.TestPreInitState{ - Logger: gs.Logger, - RuntimeOptions: lib.RuntimeOptions{ - NoThresholds: null.BoolFrom(true), - NoSummary: null.BoolFrom(true), - Env: arc.Env, - CompatibilityMode: null.StringFrom(arc.CompatibilityMode), - }, - Registry: registry, - BuiltinMetrics: metrics.RegisterBuiltinMetrics(registry), - } - - initRunner, err := js.NewFromArchive(piState, arc) - if err != nil { - return nil, nil, err - } - - test := &loadedTest{ - pwd: arc.Pwd, - sourceRootPath: arc.Filename, - source: &loader.SourceData{ - Data: resp.Archive, - URL: arc.FilenameURL, - }, - fs: afero.NewMemMapFs(), // TODO: figure out what should be here - fileSystems: arc.Filesystems, - preInitState: piState, - initRunner: initRunner, - } - - pseudoConsoldatedConfig := applyDefault(Config{Options: options}) - for _, thresholds := range pseudoConsoldatedConfig.Thresholds { - if err = thresholds.Parse(); err != nil { + var configuredTests []*loadedAndConfiguredTest + for _, test := range resp.Tests { + cTest, err := loadAndConfigureDistTest(gs, test) + if err != nil { return nil, nil, err } + configuredTests = append(configuredTests, cTest) } - derivedConfig, err := deriveAndValidateConfig(pseudoConsoldatedConfig, initRunner.IsExecutable, gs.Logger) + + c.metricsEngineHook = getMetricsHook(gs.Ctx, resp.InstanceID, client, gs.Logger) + + controller, err := distributed.NewAgentController(gs.Ctx, resp.InstanceID, client, gs.Logger) if err != nil { return nil, nil, err } - configuredTest := &loadedAndConfiguredTest{ - loadedTest: test, - consolidatedConfig: pseudoConsoldatedConfig, - derivedConfig: derivedConfig, - } - gs.Flags.Address = "" // TODO: fix, this is a hack so agents don't start an API server - return configuredTest, controller, nil // TODO + return configuredTests, controller, nil // TODO } agentCmd := &cobra.Command{ diff --git a/cmd/archive.go b/cmd/archive.go index bb3dfbcb5683..d48f4433f00f 100644 --- a/cmd/archive.go +++ b/cmd/archive.go @@ -16,7 +16,11 @@ type cmdArchive struct { } func (c *cmdArchive) run(cmd *cobra.Command, args []string) error { - test, err := loadAndConfigureLocalTest(c.gs, cmd, args, getPartialConfig) + preInitState, err := getPreInitState(c.gs, cmd) + if err != nil { + return err + } + test, err := loadAndConfigureLocalTest(c.gs, preInitState, cmd, args[0], getPartialConfig) if err != nil { return err } @@ -88,7 +92,7 @@ func getCmdArchive(gs *state.GlobalState) *cobra.Command { An archive is a fully self-contained test run, and can be executed identically elsewhere.`, Example: exampleText, - Args: cobra.ExactArgs(1), + Args: cobra.ExactArgs(1), // TODO: remove and support test suites? RunE: c.run, } diff --git a/cmd/cloud.go b/cmd/cloud.go index 9712d335b6e9..244390841a5c 100644 --- a/cmd/cloud.go +++ b/cmd/cloud.go @@ -84,7 +84,11 @@ func (c *cmdCloud) run(cmd *cobra.Command, args []string) error { ) printBar(c.gs, progressBar) - test, err := loadAndConfigureLocalTest(c.gs, cmd, args, getPartialConfig) + preInitState, err := getPreInitState(c.gs, cmd) + if err != nil { + return err + } + test, err := loadAndConfigureLocalTest(c.gs, preInitState, cmd, args[0], getPartialConfig) if err != nil { return err } diff --git a/cmd/coordinator.go b/cmd/coordinator.go index 797129ac9cb2..8ef24c5a4148 100644 --- a/cmd/coordinator.go +++ b/cmd/coordinator.go @@ -28,36 +28,52 @@ type cmdCoordinator struct { func (c *cmdCoordinator) run(cmd *cobra.Command, args []string) (err error) { ctx, runAbort := execution.NewTestRunContext(c.gs.Ctx, c.gs.Logger) - test, err := loadAndConfigureLocalTest(c.gs, cmd, args, getPartialConfig) + tests, err := loadAndConfigureLocalTests(c.gs, cmd, args, getPartialConfig) if err != nil { return err } - // Only consolidated options, not derived - testRunState, err := test.buildTestRunState(test.consolidatedConfig.Options) + // TODO: refactor at some point, this limits us to handleSummary() from the first test + firstTest := tests[0] + // TODO: refactor - this is safe, preInitState is the same for all tests, + // but it's still icky to get it that way + preInitState := firstTest.preInitState + metricsEngine, err := engine.NewMetricsEngine(preInitState.Registry, c.gs.Logger) if err != nil { return err } - shouldProcessMetrics := !testRunState.RuntimeOptions.NoSummary.Bool || !testRunState.RuntimeOptions.NoThresholds.Bool - metricsEngine, err := engine.NewMetricsEngine(testRunState, shouldProcessMetrics) - if err != nil { - return err + testArchives := make([]*lib.Archive, len(tests)) + for i, test := range tests { + runState, err := test.buildTestRunState(test.consolidatedConfig.Options) + if err != nil { + return err + } + + // We get the thresholds from all tests + testArchives[i] = runState.Runner.MakeArchive() + err = metricsEngine.InitSubMetricsAndThresholds( + test.derivedConfig.Options, + preInitState.RuntimeOptions.NoThresholds.Bool, + ) + if err != nil { + return err + } } coordinator, err := distributed.NewCoordinatorServer( - c.instanceCount, test.initRunner.MakeArchive(), metricsEngine, c.gs.Logger, + c.instanceCount, testArchives, metricsEngine, c.gs.Logger, ) if err != nil { return err } - if !testRunState.RuntimeOptions.NoSummary.Bool { + if !preInitState.RuntimeOptions.NoSummary.Bool { defer func() { c.gs.Logger.Debug("Generating the end-of-test summary...") - summaryResult, serr := test.initRunner.HandleSummary(ctx, &lib.Summary{ + summaryResult, serr := firstTest.initRunner.HandleSummary(ctx, &lib.Summary{ Metrics: metricsEngine.ObservedMetrics, - RootGroup: test.initRunner.GetDefaultGroup(), + RootGroup: firstTest.initRunner.GetDefaultGroup(), TestRunDuration: coordinator.GetCurrentTestRunDuration(), NoColor: c.gs.Flags.NoColor, UIState: lib.UIState{ @@ -74,9 +90,9 @@ func (c *cmdCoordinator) run(cmd *cobra.Command, args []string) (err error) { }() } - if !testRunState.RuntimeOptions.NoThresholds.Bool { + if !preInitState.RuntimeOptions.NoThresholds.Bool { getCurrentTestDuration := coordinator.GetCurrentTestRunDuration - finalizeThresholds := metricsEngine.StartThresholdCalculations(runAbort, getCurrentTestDuration) + finalizeThresholds := metricsEngine.StartThresholdCalculations(nil, runAbort, getCurrentTestDuration) defer func() { // This gets called after all of the outputs have stopped, so we are diff --git a/cmd/inspect.go b/cmd/inspect.go index de646ab5440d..463640211b09 100644 --- a/cmd/inspect.go +++ b/cmd/inspect.go @@ -19,9 +19,14 @@ func getCmdInspect(gs *state.GlobalState) *cobra.Command { Use: "inspect [file]", Short: "Inspect a script or archive", Long: `Inspect a script or archive.`, - Args: cobra.ExactArgs(1), + Args: cobra.ExactArgs(1), // TODO: remove and support test suites? RunE: func(cmd *cobra.Command, args []string) error { - test, err := loadLocalTest(gs, cmd, args) + preInitState, err := getPreInitState(gs, cmd) + if err != nil { + return err + } + + test, err := loadLocalTest(gs, preInitState, cmd, args[0]) if err != nil { return err } diff --git a/cmd/run.go b/cmd/run.go index 6f6764948739..bc03016eac22 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -40,14 +40,11 @@ type cmdsRunAndAgent struct { gs *state.GlobalState // TODO: figure out something more elegant? - loadConfiguredTest func(cmd *cobra.Command, args []string) (*loadedAndConfiguredTest, execution.Controller, error) - metricsEngineHook func(*engine.MetricsEngine) func() - testEndHook func(err error) + loadConfiguredTests func(cmd *cobra.Command, args []string) ([]*loadedAndConfiguredTest, execution.Controller, error) + metricsEngineHook func(*engine.MetricsEngine) func() + testEndHook func(err error) } -// TODO: split apart some more -// -//nolint:funlen,gocognit,gocyclo,cyclop func (c *cmdsRunAndAgent) run(cmd *cobra.Command, args []string) (err error) { var logger logrus.FieldLogger = c.gs.Logger defer func() { @@ -62,6 +59,32 @@ func (c *cmdsRunAndAgent) run(cmd *cobra.Command, args []string) (err error) { }() printBanner(c.gs) + // TODO: hadnle contexts, Ctrl+C, REST API and a lot of other things here + + tests, controller, err := c.loadConfiguredTests(cmd, args) + if err != nil { + return err + } + + execution.SignalAndWait(controller, "test-suite-start") + defer execution.SignalAndWait(controller, "test-suite-done") + for i, test := range tests { + testName := fmt.Sprintf("%d", i) // TODO: something better but still unique + testController := execution.GetNamespacedController(testName, controller) + + err := c.runTest(cmd, test, testController) + if err != nil { + return err + } + } + return nil +} + +//nolint:funlen,gocognit,gocyclo,cyclop +func (c *cmdsRunAndAgent) runTest( + cmd *cobra.Command, test *loadedAndConfiguredTest, controller execution.Controller, +) (err error) { + var logger logrus.FieldLogger = c.gs.Logger globalCtx, globalCancel := context.WithCancel(c.gs.Ctx) defer globalCancel() @@ -69,16 +92,14 @@ func (c *cmdsRunAndAgent) run(cmd *cobra.Command, args []string) (err error) { // k6 was started with the --linger option. lingerCtx, lingerCancel := context.WithCancel(globalCtx) defer lingerCancel() + execution.SignalAndWait(controller, "test-start") + defer execution.SignalAndWait(controller, "test-done") // runCtx is used for the test run execution and is created with the special // execution.NewTestRunContext() function so that it can be aborted even // from sub-contexts while also attaching a reason for the abort. runCtx, runAbort := execution.NewTestRunContext(lingerCtx, logger) - test, controller, err := c.loadConfiguredTest(cmd, args) - if err != nil { - return err - } if test.keyLogger != nil { defer func() { if klErr := test.keyLogger.Close(); klErr != nil { @@ -129,19 +150,25 @@ func (c *cmdsRunAndAgent) run(cmd *cobra.Command, args []string) (err error) { return err } - // We'll need to pipe metrics to the MetricsEngine and process them if any - // of these are enabled: thresholds, end-of-test summary, engine hook - shouldProcessMetrics := (!testRunState.RuntimeOptions.NoSummary.Bool || - !testRunState.RuntimeOptions.NoThresholds.Bool || c.metricsEngineHook != nil) - metricsEngine, err := engine.NewMetricsEngine(testRunState, shouldProcessMetrics) + metricsEngine, err := engine.NewMetricsEngine(testRunState.Registry, logger) if err != nil { return err } + // We'll need to pipe metrics to the MetricsEngine and process them if any + // of these are enabled: thresholds, end-of-test summary, engine hook + shouldProcessMetrics := (!testRunState.RuntimeOptions.NoSummary.Bool || + !testRunState.RuntimeOptions.NoThresholds.Bool || c.metricsEngineHook != nil) + var metricsIngester *engine.OutputIngester if shouldProcessMetrics { + err = metricsEngine.InitSubMetricsAndThresholds(conf.Options, testRunState.RuntimeOptions.NoThresholds.Bool) + if err != nil { + return err + } // We'll need to pipe metrics to the MetricsEngine if either the // thresholds or the end-of-test summary are enabled. - outputs = append(outputs, metricsEngine.CreateIngester()) + metricsIngester = metricsEngine.CreateIngester() + outputs = append(outputs, metricsIngester) } executionState := execScheduler.GetState() @@ -198,7 +225,8 @@ func (c *cmdsRunAndAgent) run(cmd *cobra.Command, args []string) (err error) { } if !testRunState.RuntimeOptions.NoThresholds.Bool { - finalizeThresholds := metricsEngine.StartThresholdCalculations(runAbort, executionState.GetCurrentTestRunDuration) + getCurrentTestDuration := executionState.GetCurrentTestRunDuration + finalizeThresholds := metricsEngine.StartThresholdCalculations(metricsIngester, runAbort, getCurrentTestDuration) handleFinalThresholdCalculation := func() { // This gets called after the Samples channel has been closed and // the OutputManager has flushed all of the cached samples to @@ -273,7 +301,7 @@ func (c *cmdsRunAndAgent) run(cmd *cobra.Command, args []string) (err error) { } printExecutionDescription( - c.gs, "local", args[0], "", conf, executionState.ExecutionTuple, executionPlan, outputs, + c.gs, "local", test.sourceRootPath, "", conf, executionState.ExecutionTuple, executionPlan, outputs, ) // Trap Interrupts, SIGINTs and SIGTERMs. @@ -369,9 +397,11 @@ func (c *cmdsRunAndAgent) flagSet() *pflag.FlagSet { func getCmdRun(gs *state.GlobalState) *cobra.Command { c := &cmdsRunAndAgent{ gs: gs, - loadConfiguredTest: func(cmd *cobra.Command, args []string) (*loadedAndConfiguredTest, execution.Controller, error) { - test, err := loadAndConfigureLocalTest(gs, cmd, args, getConfig) - return test, local.NewController(), err + loadConfiguredTests: func(cmd *cobra.Command, args []string) ( + []*loadedAndConfiguredTest, execution.Controller, error, + ) { + tests, err := loadAndConfigureLocalTests(gs, cmd, args, getConfig) + return tests, local.NewController(), err }, } @@ -402,7 +432,6 @@ func getCmdRun(gs *state.GlobalState) *cobra.Command { This also exposes a REST API to interact with it. Various k6 subcommands offer a commandline interface for interacting with it.`, Example: exampleText, - Args: exactArgsWithMsg(1, "arg should either be \"-\", if reading script from stdin, or a path to a script file"), RunE: c.run, } diff --git a/cmd/test_load.go b/cmd/test_load.go index c9d327bda495..211f3395b24c 100644 --- a/cmd/test_load.go +++ b/cmd/test_load.go @@ -41,23 +41,7 @@ type loadedTest struct { keyLogger io.Closer } -func loadLocalTest(gs *state.GlobalState, cmd *cobra.Command, args []string) (*loadedTest, error) { - if len(args) < 1 { - return nil, fmt.Errorf("k6 needs at least one argument to load the test") - } - - sourceRootPath := args[0] - gs.Logger.Debugf("Resolving and reading test '%s'...", sourceRootPath) - src, fileSystems, pwd, err := readSource(gs, sourceRootPath) - if err != nil { - return nil, err - } - resolvedPath := src.URL.String() - gs.Logger.Debugf( - "'%s' resolved to '%s' and successfully loaded %d bytes!", - sourceRootPath, resolvedPath, len(src.Data), - ) - +func getPreInitState(gs *state.GlobalState, cmd *cobra.Command) (*lib.TestPreInitState, error) { gs.Logger.Debugf("Gathering k6 runtime options...") runtimeOptions, err := getRuntimeOptions(cmd.Flags(), gs.Env) if err != nil { @@ -65,7 +49,7 @@ func loadLocalTest(gs *state.GlobalState, cmd *cobra.Command, args []string) (*l } registry := metrics.NewRegistry() - state := &lib.TestPreInitState{ + return &lib.TestPreInitState{ Logger: gs.Logger, RuntimeOptions: runtimeOptions, Registry: registry, @@ -74,7 +58,22 @@ func loadLocalTest(gs *state.GlobalState, cmd *cobra.Command, args []string) (*l val, ok := gs.Env[key] return val, ok }, + }, nil +} + +func loadLocalTest( + gs *state.GlobalState, preInitState *lib.TestPreInitState, cmd *cobra.Command, sourceRootPath string, +) (*loadedTest, error) { + gs.Logger.Debugf("Resolving and reading test '%s'...", sourceRootPath) + src, fileSystems, pwd, err := readSource(gs, sourceRootPath) + if err != nil { + return nil, err } + resolvedPath := src.URL.String() + gs.Logger.Debugf( + "'%s' resolved to '%s' and successfully loaded %d bytes!", + sourceRootPath, resolvedPath, len(src.Data), + ) test := &loadedTest{ pwd: pwd, @@ -82,7 +81,7 @@ func loadLocalTest(gs *state.GlobalState, cmd *cobra.Command, args []string) (*l source: src, fs: gs.FS, fileSystems: fileSystems, - preInitState: state, + preInitState: preInitState, } gs.Logger.Debugf("Initializing k6 runner for '%s' (%s)...", sourceRootPath, resolvedPath) @@ -235,11 +234,36 @@ type loadedAndConfiguredTest struct { derivedConfig Config } -func loadAndConfigureLocalTest( +func loadAndConfigureLocalTests( gs *state.GlobalState, cmd *cobra.Command, args []string, cliConfigGetter func(flags *pflag.FlagSet) (Config, error), +) ([]*loadedAndConfiguredTest, error) { + if len(args) < 1 { + return nil, fmt.Errorf("k6 needs at least one argument to load the test") + } + + preInitState, err := getPreInitState(gs, cmd) + if err != nil { + return nil, err + } + + tests := make([]*loadedAndConfiguredTest, 0, len(args)) + for _, arg := range args { + test, err := loadAndConfigureLocalTest(gs, preInitState, cmd, arg, cliConfigGetter) + if err != nil { + return nil, err + } + tests = append(tests, test) + } + + return tests, nil +} + +func loadAndConfigureLocalTest( + gs *state.GlobalState, preInitState *lib.TestPreInitState, cmd *cobra.Command, sourceRootPath string, + cliConfigGetter func(flags *pflag.FlagSet) (Config, error), ) (*loadedAndConfiguredTest, error) { - test, err := loadLocalTest(gs, cmd, args) + test, err := loadLocalTest(gs, preInitState, cmd, sourceRootPath) if err != nil { return nil, err } diff --git a/execution/controller.go b/execution/controller.go index 662d19dc7df8..2baba03a4bbf 100644 --- a/execution/controller.go +++ b/execution/controller.go @@ -9,3 +9,32 @@ type Controller interface { Wait(eventId string) func() error Signal(eventId string) error } + +type namesspacedController struct { + namespace string + c Controller +} + +func (nc namesspacedController) GetOrCreateData(id string, callback func() ([]byte, error)) ([]byte, error) { + return nc.c.GetOrCreateData(nc.namespace+"/"+id, callback) +} + +func (nc namesspacedController) Wait(eventId string) func() error { + return nc.c.Wait(nc.namespace + "/" + eventId) +} + +func (nc namesspacedController) Signal(eventId string) error { + return nc.c.Signal(nc.namespace + "/" + eventId) +} + +func GetNamespacedController(namespace string, controller Controller) Controller { + return &namesspacedController{namespace: namespace, c: controller} +} + +func SignalAndWait(c Controller, eventID string) error { + wait := c.Wait(eventID) + if err := c.Signal(eventID); err != nil { + return err + } + return wait() +} diff --git a/execution/distributed/coordinator.go b/execution/distributed/coordinator.go index 644036cbc537..529a367d25ec 100644 --- a/execution/distributed/coordinator.go +++ b/execution/distributed/coordinator.go @@ -5,6 +5,8 @@ import ( context "context" "encoding/json" "fmt" + "path/filepath" + "strconv" "sync" "sync/atomic" "time" @@ -14,54 +16,64 @@ import ( "go.k6.io/k6/metrics/engine" ) +type test struct { + archive *lib.Archive + archiveData []byte + ess lib.ExecutionSegmentSequence +} + // TODO: something more polished... type CoordinatorServer struct { UnimplementedDistributedTestServer instanceCount int - test *lib.Archive logger logrus.FieldLogger metricsEngine *engine.MetricsEngine + tests []test + testStartTimeLock sync.Mutex testStartTime *time.Time cc *coordinatorController currentInstance int32 // TODO: something a bit better, support full execution plans from JSON? - ess lib.ExecutionSegmentSequence - archive []byte wg *sync.WaitGroup } func NewCoordinatorServer( - instanceCount int, test *lib.Archive, metricsEngine *engine.MetricsEngine, logger logrus.FieldLogger, + instanceCount int, testArchives []*lib.Archive, metricsEngine *engine.MetricsEngine, logger logrus.FieldLogger, ) (*CoordinatorServer, error) { - segments, err := test.Options.ExecutionSegment.Split(int64(instanceCount)) - if err != nil { - return nil, err - } - ess, err := lib.NewExecutionSegmentSequence(segments...) - if err != nil { - return nil, err + tests := make([]test, len(testArchives)) + for i, testArchive := range testArchives { + segments, err := testArchive.Options.ExecutionSegment.Split(int64(instanceCount)) + if err != nil { + return nil, err + } + ess, err := lib.NewExecutionSegmentSequence(segments...) + if err != nil { + return nil, err + } + buf := &bytes.Buffer{} + if err = testArchive.Write(buf); err != nil { + return nil, err + } + tests[i] = test{ + ess: ess, + archive: testArchive, + archiveData: buf.Bytes(), + } } // TODO: figure out some way to add metrics from the instance to the metricsEngine - buf := &bytes.Buffer{} - if err = test.Write(buf); err != nil { - return nil, err - } - wg := &sync.WaitGroup{} wg.Add(instanceCount) cs := &CoordinatorServer{ instanceCount: instanceCount, - test: test, + tests: tests, metricsEngine: metricsEngine, logger: logger, - ess: ess, cc: newCoordinatorController(instanceCount, logger), - archive: buf.Bytes(), wg: wg, } @@ -71,25 +83,31 @@ func NewCoordinatorServer( } func (cs *CoordinatorServer) monitorProgress() { - wg := cs.cc.getSignalWG("test-start") // TODO: use constant when we refactor scheduler.go + wg := cs.cc.getSignalWG("test-suite-start") // TODO: use constant when we refactor scheduler.go wg.Wait() - cs.logger.Info("All instances ready to start initializing VUs...") + cs.logger.Info("All instances ready!") - wg = cs.cc.getSignalWG("test-ready-to-run-setup") // TODO: use constant when we refactor scheduler.go - wg.Wait() - cs.logger.Info("VUs initialized, setup()...") - cs.testStartTimeLock.Lock() - t := time.Now() - cs.testStartTime = &t - cs.testStartTimeLock.Unlock() + for i, test := range cs.tests { + testName := fmt.Sprintf("%d", i) + wg = cs.cc.getSignalWG(testName + "/test-start") // TODO: use constant when we refactor scheduler.go + wg.Wait() + cs.logger.Infof("Test %d (%s) started...", i+1, filepath.Base(test.archive.FilenameURL.Path)) - wg = cs.cc.getSignalWG("setup-done") // TODO: use constant when we refactor scheduler.go - wg.Wait() - cs.logger.Info("setup() done, starting test!") + cs.testStartTimeLock.Lock() + if cs.testStartTime == nil { + t := time.Now() + cs.testStartTime = &t + } + cs.testStartTimeLock.Unlock() - wg = cs.cc.getSignalWG("test-done") // TODO: use constant when we refactor scheduler.go + wg = cs.cc.getSignalWG(testName + "/test-done") // TODO: use constant when we refactor scheduler.go + wg.Wait() + cs.logger.Infof("Test %d (%s) ended!", i+1, filepath.Base(test.archive.FilenameURL.Path)) + } + + wg = cs.cc.getSignalWG("test-suite-done") // TODO: use constant when we refactor scheduler.go wg.Wait() - cs.logger.Info("Instances finished with the test") + cs.logger.Info("Instances finished with the test suite") } func (cs *CoordinatorServer) GetCurrentTestRunDuration() time.Duration { @@ -110,18 +128,32 @@ func (cs *CoordinatorServer) Register(context.Context, *RegisterRequest) (*Regis } cs.logger.Infof("Instance %d of %d connected!", instanceID, cs.instanceCount) - instanceOptions := cs.test.Options - instanceOptions.ExecutionSegment = cs.ess[instanceID-1] - instanceOptions.ExecutionSegmentSequence = &cs.ess - options, err := json.Marshal(instanceOptions) - if err != nil { - return nil, err + instanceTests := make([]*Test, len(cs.tests)) + for i, test := range cs.tests { + opts := test.archive.Options + opts.ExecutionSegment = test.ess[instanceID-1] + opts.ExecutionSegmentSequence = &test.ess + + if opts.RunTags == nil { + opts.RunTags = make(map[string]string) + } + opts.RunTags["test_id"] = test.archive.Filename + opts.RunTags["instance_id"] = strconv.Itoa(int(instanceID)) + + jsonOpts, err := json.Marshal(opts) + if err != nil { + return nil, err + } + + instanceTests[i] = &Test{ + Archive: test.archiveData, + Options: jsonOpts, + } } return &RegisterResponse{ InstanceID: uint32(instanceID), - Archive: cs.archive, - Options: options, + Tests: instanceTests, }, nil } diff --git a/execution/distributed/distributed.pb.go b/execution/distributed/distributed.pb.go index f73564daa003..72f9d241cce3 100644 --- a/execution/distributed/distributed.pb.go +++ b/execution/distributed/distributed.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.27.1 -// protoc v3.19.4 +// protoc v3.21.6 // source: distributed.proto package distributed @@ -63,9 +63,8 @@ type RegisterResponse struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - InstanceID uint32 `protobuf:"varint,1,opt,name=instanceID,proto3" json:"instanceID,omitempty"` - Archive []byte `protobuf:"bytes,2,opt,name=archive,proto3" json:"archive,omitempty"` // TODO: send this with a `stream` of bytes chunks - Options []byte `protobuf:"bytes,3,opt,name=options,proto3" json:"options,omitempty"` + InstanceID uint32 `protobuf:"varint,1,opt,name=instanceID,proto3" json:"instanceID,omitempty"` + Tests []*Test `protobuf:"bytes,2,rep,name=tests,proto3" json:"tests,omitempty"` } func (x *RegisterResponse) Reset() { @@ -107,14 +106,62 @@ func (x *RegisterResponse) GetInstanceID() uint32 { return 0 } -func (x *RegisterResponse) GetArchive() []byte { +func (x *RegisterResponse) GetTests() []*Test { + if x != nil { + return x.Tests + } + return nil +} + +type Test struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Archive []byte `protobuf:"bytes,1,opt,name=archive,proto3" json:"archive,omitempty"` // TODO: send this with a `stream` of bytes chunks + Options []byte `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"` +} + +func (x *Test) Reset() { + *x = Test{} + if protoimpl.UnsafeEnabled { + mi := &file_distributed_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Test) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Test) ProtoMessage() {} + +func (x *Test) ProtoReflect() protoreflect.Message { + mi := &file_distributed_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Test.ProtoReflect.Descriptor instead. +func (*Test) Descriptor() ([]byte, []int) { + return file_distributed_proto_rawDescGZIP(), []int{2} +} + +func (x *Test) GetArchive() []byte { if x != nil { return x.Archive } return nil } -func (x *RegisterResponse) GetOptions() []byte { +func (x *Test) GetOptions() []byte { if x != nil { return x.Options } @@ -139,7 +186,7 @@ type AgentMessage struct { func (x *AgentMessage) Reset() { *x = AgentMessage{} if protoimpl.UnsafeEnabled { - mi := &file_distributed_proto_msgTypes[2] + mi := &file_distributed_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -152,7 +199,7 @@ func (x *AgentMessage) String() string { func (*AgentMessage) ProtoMessage() {} func (x *AgentMessage) ProtoReflect() protoreflect.Message { - mi := &file_distributed_proto_msgTypes[2] + mi := &file_distributed_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -165,7 +212,7 @@ func (x *AgentMessage) ProtoReflect() protoreflect.Message { // Deprecated: Use AgentMessage.ProtoReflect.Descriptor instead. func (*AgentMessage) Descriptor() ([]byte, []int) { - return file_distributed_proto_rawDescGZIP(), []int{2} + return file_distributed_proto_rawDescGZIP(), []int{3} } func (m *AgentMessage) GetMessage() isAgentMessage_Message { @@ -247,7 +294,7 @@ type ControllerMessage struct { func (x *ControllerMessage) Reset() { *x = ControllerMessage{} if protoimpl.UnsafeEnabled { - mi := &file_distributed_proto_msgTypes[3] + mi := &file_distributed_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -260,7 +307,7 @@ func (x *ControllerMessage) String() string { func (*ControllerMessage) ProtoMessage() {} func (x *ControllerMessage) ProtoReflect() protoreflect.Message { - mi := &file_distributed_proto_msgTypes[3] + mi := &file_distributed_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -273,7 +320,7 @@ func (x *ControllerMessage) ProtoReflect() protoreflect.Message { // Deprecated: Use ControllerMessage.ProtoReflect.Descriptor instead. func (*ControllerMessage) Descriptor() ([]byte, []int) { - return file_distributed_proto_rawDescGZIP(), []int{3} + return file_distributed_proto_rawDescGZIP(), []int{4} } func (x *ControllerMessage) GetInstanceID() uint32 { @@ -346,7 +393,7 @@ type DataPacket struct { func (x *DataPacket) Reset() { *x = DataPacket{} if protoimpl.UnsafeEnabled { - mi := &file_distributed_proto_msgTypes[4] + mi := &file_distributed_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -359,7 +406,7 @@ func (x *DataPacket) String() string { func (*DataPacket) ProtoMessage() {} func (x *DataPacket) ProtoReflect() protoreflect.Message { - mi := &file_distributed_proto_msgTypes[4] + mi := &file_distributed_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -372,7 +419,7 @@ func (x *DataPacket) ProtoReflect() protoreflect.Message { // Deprecated: Use DataPacket.ProtoReflect.Descriptor instead. func (*DataPacket) Descriptor() ([]byte, []int) { - return file_distributed_proto_rawDescGZIP(), []int{4} + return file_distributed_proto_rawDescGZIP(), []int{5} } func (x *DataPacket) GetId() string { @@ -408,7 +455,7 @@ type MetricsDump struct { func (x *MetricsDump) Reset() { *x = MetricsDump{} if protoimpl.UnsafeEnabled { - mi := &file_distributed_proto_msgTypes[5] + mi := &file_distributed_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -421,7 +468,7 @@ func (x *MetricsDump) String() string { func (*MetricsDump) ProtoMessage() {} func (x *MetricsDump) ProtoReflect() protoreflect.Message { - mi := &file_distributed_proto_msgTypes[5] + mi := &file_distributed_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -434,7 +481,7 @@ func (x *MetricsDump) ProtoReflect() protoreflect.Message { // Deprecated: Use MetricsDump.ProtoReflect.Descriptor instead. func (*MetricsDump) Descriptor() ([]byte, []int) { - return file_distributed_proto_rawDescGZIP(), []int{5} + return file_distributed_proto_rawDescGZIP(), []int{6} } func (x *MetricsDump) GetInstanceID() uint32 { @@ -463,7 +510,7 @@ type MetricDump struct { func (x *MetricDump) Reset() { *x = MetricDump{} if protoimpl.UnsafeEnabled { - mi := &file_distributed_proto_msgTypes[6] + mi := &file_distributed_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -476,7 +523,7 @@ func (x *MetricDump) String() string { func (*MetricDump) ProtoMessage() {} func (x *MetricDump) ProtoReflect() protoreflect.Message { - mi := &file_distributed_proto_msgTypes[6] + mi := &file_distributed_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -489,7 +536,7 @@ func (x *MetricDump) ProtoReflect() protoreflect.Message { // Deprecated: Use MetricDump.ProtoReflect.Descriptor instead. func (*MetricDump) Descriptor() ([]byte, []int) { - return file_distributed_proto_rawDescGZIP(), []int{6} + return file_distributed_proto_rawDescGZIP(), []int{7} } func (x *MetricDump) GetName() string { @@ -515,7 +562,7 @@ type MetricsDumpResponse struct { func (x *MetricsDumpResponse) Reset() { *x = MetricsDumpResponse{} if protoimpl.UnsafeEnabled { - mi := &file_distributed_proto_msgTypes[7] + mi := &file_distributed_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -528,7 +575,7 @@ func (x *MetricsDumpResponse) String() string { func (*MetricsDumpResponse) ProtoMessage() {} func (x *MetricsDumpResponse) ProtoReflect() protoreflect.Message { - mi := &file_distributed_proto_msgTypes[7] + mi := &file_distributed_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -541,7 +588,7 @@ func (x *MetricsDumpResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use MetricsDumpResponse.ProtoReflect.Descriptor instead. func (*MetricsDumpResponse) Descriptor() ([]byte, []int) { - return file_distributed_proto_rawDescGZIP(), []int{7} + return file_distributed_proto_rawDescGZIP(), []int{8} } var File_distributed_proto protoreflect.FileDescriptor @@ -550,75 +597,79 @@ var file_distributed_proto_rawDesc = []byte{ 0x0a, 0x11, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0b, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x22, 0x11, 0x0a, 0x0f, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x22, 0x66, 0x0a, 0x10, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, + 0x65, 0x73, 0x74, 0x22, 0x5b, 0x0a, 0x10, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x69, 0x6e, 0x73, - 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x72, 0x63, 0x68, 0x69, - 0x76, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x61, 0x72, 0x63, 0x68, 0x69, 0x76, - 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0xe8, 0x01, 0x0a, 0x0c, - 0x41, 0x67, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x28, 0x0a, 0x0e, - 0x69, 0x6e, 0x69, 0x74, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0d, 0x48, 0x00, 0x52, 0x0e, 0x69, 0x6e, 0x69, 0x74, 0x49, 0x6e, 0x73, 0x74, - 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x12, 0x2e, 0x0a, 0x11, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x6c, - 0x41, 0x6e, 0x64, 0x57, 0x61, 0x69, 0x74, 0x4f, 0x6e, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x48, 0x00, 0x52, 0x11, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x41, 0x6e, 0x64, 0x57, 0x61, - 0x69, 0x74, 0x4f, 0x6e, 0x49, 0x44, 0x12, 0x36, 0x0a, 0x15, 0x67, 0x65, 0x74, 0x4f, 0x72, 0x43, - 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x57, 0x69, 0x74, 0x68, 0x49, 0x44, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x15, 0x67, 0x65, 0x74, 0x4f, 0x72, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x57, 0x69, 0x74, 0x68, 0x49, 0x44, 0x12, 0x3b, - 0x0a, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, - 0x64, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x48, 0x00, 0x52, 0x0b, - 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x44, 0x61, 0x74, 0x61, 0x42, 0x09, 0x0a, 0x07, 0x4d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xd1, 0x01, 0x0a, 0x11, 0x43, 0x6f, 0x6e, 0x74, 0x72, - 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1e, 0x0a, 0x0a, - 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, - 0x52, 0x0a, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x12, 0x28, 0x0a, 0x0e, - 0x64, 0x6f, 0x6e, 0x65, 0x57, 0x61, 0x69, 0x74, 0x57, 0x69, 0x74, 0x68, 0x49, 0x44, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0e, 0x64, 0x6f, 0x6e, 0x65, 0x57, 0x61, 0x69, 0x74, - 0x57, 0x69, 0x74, 0x68, 0x49, 0x44, 0x12, 0x2c, 0x0a, 0x10, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x44, 0x61, 0x74, 0x61, 0x57, 0x69, 0x74, 0x68, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, - 0x48, 0x00, 0x52, 0x10, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x57, 0x69, - 0x74, 0x68, 0x49, 0x44, 0x12, 0x39, 0x0a, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x57, 0x69, 0x74, 0x68, - 0x49, 0x44, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, - 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x50, 0x61, 0x63, 0x6b, 0x65, - 0x74, 0x48, 0x00, 0x52, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x57, 0x69, 0x74, 0x68, 0x49, 0x44, 0x42, - 0x09, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x46, 0x0a, 0x0a, 0x44, 0x61, - 0x74, 0x61, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x05, - 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, - 0x6f, 0x72, 0x22, 0x60, 0x0a, 0x0b, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x44, 0x75, 0x6d, - 0x70, 0x12, 0x1e, 0x0a, 0x0a, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, - 0x44, 0x12, 0x31, 0x0a, 0x07, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x18, 0x02, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, - 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x44, 0x75, 0x6d, 0x70, 0x52, 0x07, 0x6d, 0x65, 0x74, - 0x72, 0x69, 0x63, 0x73, 0x22, 0x34, 0x0a, 0x0a, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x44, 0x75, - 0x6d, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x15, 0x0a, 0x13, 0x4d, 0x65, - 0x74, 0x72, 0x69, 0x63, 0x73, 0x44, 0x75, 0x6d, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x32, 0xff, 0x01, 0x0a, 0x0f, 0x44, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, - 0x64, 0x54, 0x65, 0x73, 0x74, 0x12, 0x49, 0x0a, 0x08, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, - 0x72, 0x12, 0x1c, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x2e, - 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1d, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x2e, 0x52, 0x65, - 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, - 0x12, 0x54, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x41, 0x6e, 0x64, 0x43, 0x6f, - 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x12, 0x19, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, - 0x74, 0x65, 0x64, 0x2e, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x1a, 0x1e, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x2e, 0x43, - 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x12, 0x4b, 0x0a, 0x0b, 0x53, 0x65, 0x6e, 0x64, 0x4d, 0x65, - 0x74, 0x72, 0x69, 0x63, 0x73, 0x12, 0x18, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, - 0x74, 0x65, 0x64, 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x44, 0x75, 0x6d, 0x70, 0x1a, - 0x20, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x2e, 0x4d, 0x65, - 0x74, 0x72, 0x69, 0x63, 0x73, 0x44, 0x75, 0x6d, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x22, 0x00, 0x42, 0x23, 0x5a, 0x21, 0x67, 0x6f, 0x2e, 0x6b, 0x36, 0x2e, 0x69, 0x6f, 0x2f, - 0x6b, 0x36, 0x2f, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x64, 0x69, 0x73, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x12, 0x27, 0x0a, 0x05, 0x74, 0x65, 0x73, 0x74, 0x73, + 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, + 0x75, 0x74, 0x65, 0x64, 0x2e, 0x54, 0x65, 0x73, 0x74, 0x52, 0x05, 0x74, 0x65, 0x73, 0x74, 0x73, + 0x22, 0x3a, 0x0a, 0x04, 0x54, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x72, 0x63, 0x68, + 0x69, 0x76, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x61, 0x72, 0x63, 0x68, 0x69, + 0x76, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x07, 0x6f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x22, 0xe8, 0x01, 0x0a, + 0x0c, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x28, 0x0a, + 0x0e, 0x69, 0x6e, 0x69, 0x74, 0x49, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0d, 0x48, 0x00, 0x52, 0x0e, 0x69, 0x6e, 0x69, 0x74, 0x49, 0x6e, 0x73, + 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x12, 0x2e, 0x0a, 0x11, 0x73, 0x69, 0x67, 0x6e, 0x61, + 0x6c, 0x41, 0x6e, 0x64, 0x57, 0x61, 0x69, 0x74, 0x4f, 0x6e, 0x49, 0x44, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x48, 0x00, 0x52, 0x11, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x41, 0x6e, 0x64, 0x57, + 0x61, 0x69, 0x74, 0x4f, 0x6e, 0x49, 0x44, 0x12, 0x36, 0x0a, 0x15, 0x67, 0x65, 0x74, 0x4f, 0x72, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x57, 0x69, 0x74, 0x68, 0x49, 0x44, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x15, 0x67, 0x65, 0x74, 0x4f, 0x72, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x57, 0x69, 0x74, 0x68, 0x49, 0x44, 0x12, + 0x3b, 0x0a, 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x44, 0x61, 0x74, 0x61, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, + 0x65, 0x64, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x48, 0x00, 0x52, + 0x0b, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x44, 0x61, 0x74, 0x61, 0x42, 0x09, 0x0a, 0x07, + 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xd1, 0x01, 0x0a, 0x11, 0x43, 0x6f, 0x6e, 0x74, + 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1e, 0x0a, + 0x0a, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0d, 0x52, 0x0a, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, 0x12, 0x28, 0x0a, + 0x0e, 0x64, 0x6f, 0x6e, 0x65, 0x57, 0x61, 0x69, 0x74, 0x57, 0x69, 0x74, 0x68, 0x49, 0x44, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x0e, 0x64, 0x6f, 0x6e, 0x65, 0x57, 0x61, 0x69, + 0x74, 0x57, 0x69, 0x74, 0x68, 0x49, 0x44, 0x12, 0x2c, 0x0a, 0x10, 0x63, 0x72, 0x65, 0x61, 0x74, + 0x65, 0x44, 0x61, 0x74, 0x61, 0x57, 0x69, 0x74, 0x68, 0x49, 0x44, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x48, 0x00, 0x52, 0x10, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x44, 0x61, 0x74, 0x61, 0x57, + 0x69, 0x74, 0x68, 0x49, 0x44, 0x12, 0x39, 0x0a, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x57, 0x69, 0x74, + 0x68, 0x49, 0x44, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x64, 0x69, 0x73, 0x74, + 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x2e, 0x44, 0x61, 0x74, 0x61, 0x50, 0x61, 0x63, 0x6b, + 0x65, 0x74, 0x48, 0x00, 0x52, 0x0a, 0x64, 0x61, 0x74, 0x61, 0x57, 0x69, 0x74, 0x68, 0x49, 0x44, + 0x42, 0x09, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0x46, 0x0a, 0x0a, 0x44, + 0x61, 0x74, 0x61, 0x50, 0x61, 0x63, 0x6b, 0x65, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, + 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, + 0x72, 0x6f, 0x72, 0x22, 0x60, 0x0a, 0x0b, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x44, 0x75, + 0x6d, 0x70, 0x12, 0x1e, 0x0a, 0x0a, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, 0x49, 0x44, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6e, 0x63, 0x65, + 0x49, 0x44, 0x12, 0x31, 0x0a, 0x07, 0x6d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x18, 0x02, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, + 0x64, 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x44, 0x75, 0x6d, 0x70, 0x52, 0x07, 0x6d, 0x65, + 0x74, 0x72, 0x69, 0x63, 0x73, 0x22, 0x34, 0x0a, 0x0a, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x44, + 0x75, 0x6d, 0x70, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x22, 0x15, 0x0a, 0x13, 0x4d, + 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x44, 0x75, 0x6d, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x32, 0xff, 0x01, 0x0a, 0x0f, 0x44, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, + 0x65, 0x64, 0x54, 0x65, 0x73, 0x74, 0x12, 0x49, 0x0a, 0x08, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, + 0x65, 0x72, 0x12, 0x1c, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, + 0x2e, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x1d, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x2e, 0x52, + 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, + 0x00, 0x12, 0x54, 0x0a, 0x11, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x41, 0x6e, 0x64, 0x43, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x12, 0x19, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, + 0x75, 0x74, 0x65, 0x64, 0x2e, 0x41, 0x67, 0x65, 0x6e, 0x74, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x1a, 0x1e, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x2e, + 0x43, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x6c, 0x65, 0x72, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, + 0x65, 0x22, 0x00, 0x28, 0x01, 0x30, 0x01, 0x12, 0x4b, 0x0a, 0x0b, 0x53, 0x65, 0x6e, 0x64, 0x4d, + 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x12, 0x18, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, + 0x75, 0x74, 0x65, 0x64, 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x44, 0x75, 0x6d, 0x70, + 0x1a, 0x20, 0x2e, 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x2e, 0x4d, + 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x44, 0x75, 0x6d, 0x70, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x00, 0x42, 0x23, 0x5a, 0x21, 0x67, 0x6f, 0x2e, 0x6b, 0x36, 0x2e, 0x69, 0x6f, + 0x2f, 0x6b, 0x36, 0x2f, 0x65, 0x78, 0x65, 0x63, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x64, 0x69, + 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( @@ -633,32 +684,34 @@ func file_distributed_proto_rawDescGZIP() []byte { return file_distributed_proto_rawDescData } -var file_distributed_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_distributed_proto_msgTypes = make([]protoimpl.MessageInfo, 9) var file_distributed_proto_goTypes = []interface{}{ (*RegisterRequest)(nil), // 0: distributed.RegisterRequest (*RegisterResponse)(nil), // 1: distributed.RegisterResponse - (*AgentMessage)(nil), // 2: distributed.AgentMessage - (*ControllerMessage)(nil), // 3: distributed.ControllerMessage - (*DataPacket)(nil), // 4: distributed.DataPacket - (*MetricsDump)(nil), // 5: distributed.MetricsDump - (*MetricDump)(nil), // 6: distributed.MetricDump - (*MetricsDumpResponse)(nil), // 7: distributed.MetricsDumpResponse + (*Test)(nil), // 2: distributed.Test + (*AgentMessage)(nil), // 3: distributed.AgentMessage + (*ControllerMessage)(nil), // 4: distributed.ControllerMessage + (*DataPacket)(nil), // 5: distributed.DataPacket + (*MetricsDump)(nil), // 6: distributed.MetricsDump + (*MetricDump)(nil), // 7: distributed.MetricDump + (*MetricsDumpResponse)(nil), // 8: distributed.MetricsDumpResponse } var file_distributed_proto_depIdxs = []int32{ - 4, // 0: distributed.AgentMessage.createdData:type_name -> distributed.DataPacket - 4, // 1: distributed.ControllerMessage.dataWithID:type_name -> distributed.DataPacket - 6, // 2: distributed.MetricsDump.metrics:type_name -> distributed.MetricDump - 0, // 3: distributed.DistributedTest.Register:input_type -> distributed.RegisterRequest - 2, // 4: distributed.DistributedTest.CommandAndControl:input_type -> distributed.AgentMessage - 5, // 5: distributed.DistributedTest.SendMetrics:input_type -> distributed.MetricsDump - 1, // 6: distributed.DistributedTest.Register:output_type -> distributed.RegisterResponse - 3, // 7: distributed.DistributedTest.CommandAndControl:output_type -> distributed.ControllerMessage - 7, // 8: distributed.DistributedTest.SendMetrics:output_type -> distributed.MetricsDumpResponse - 6, // [6:9] is the sub-list for method output_type - 3, // [3:6] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 2, // 0: distributed.RegisterResponse.tests:type_name -> distributed.Test + 5, // 1: distributed.AgentMessage.createdData:type_name -> distributed.DataPacket + 5, // 2: distributed.ControllerMessage.dataWithID:type_name -> distributed.DataPacket + 7, // 3: distributed.MetricsDump.metrics:type_name -> distributed.MetricDump + 0, // 4: distributed.DistributedTest.Register:input_type -> distributed.RegisterRequest + 3, // 5: distributed.DistributedTest.CommandAndControl:input_type -> distributed.AgentMessage + 6, // 6: distributed.DistributedTest.SendMetrics:input_type -> distributed.MetricsDump + 1, // 7: distributed.DistributedTest.Register:output_type -> distributed.RegisterResponse + 4, // 8: distributed.DistributedTest.CommandAndControl:output_type -> distributed.ControllerMessage + 8, // 9: distributed.DistributedTest.SendMetrics:output_type -> distributed.MetricsDumpResponse + 7, // [7:10] is the sub-list for method output_type + 4, // [4:7] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_distributed_proto_init() } @@ -692,7 +745,7 @@ func file_distributed_proto_init() { } } file_distributed_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AgentMessage); i { + switch v := v.(*Test); i { case 0: return &v.state case 1: @@ -704,7 +757,7 @@ func file_distributed_proto_init() { } } file_distributed_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*ControllerMessage); i { + switch v := v.(*AgentMessage); i { case 0: return &v.state case 1: @@ -716,7 +769,7 @@ func file_distributed_proto_init() { } } file_distributed_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DataPacket); i { + switch v := v.(*ControllerMessage); i { case 0: return &v.state case 1: @@ -728,7 +781,7 @@ func file_distributed_proto_init() { } } file_distributed_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*MetricsDump); i { + switch v := v.(*DataPacket); i { case 0: return &v.state case 1: @@ -740,7 +793,7 @@ func file_distributed_proto_init() { } } file_distributed_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*MetricDump); i { + switch v := v.(*MetricsDump); i { case 0: return &v.state case 1: @@ -752,6 +805,18 @@ func file_distributed_proto_init() { } } file_distributed_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MetricDump); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_distributed_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*MetricsDumpResponse); i { case 0: return &v.state @@ -764,13 +829,13 @@ func file_distributed_proto_init() { } } } - file_distributed_proto_msgTypes[2].OneofWrappers = []interface{}{ + file_distributed_proto_msgTypes[3].OneofWrappers = []interface{}{ (*AgentMessage_InitInstanceID)(nil), (*AgentMessage_SignalAndWaitOnID)(nil), (*AgentMessage_GetOrCreateDataWithID)(nil), (*AgentMessage_CreatedData)(nil), } - file_distributed_proto_msgTypes[3].OneofWrappers = []interface{}{ + file_distributed_proto_msgTypes[4].OneofWrappers = []interface{}{ (*ControllerMessage_DoneWaitWithID)(nil), (*ControllerMessage_CreateDataWithID)(nil), (*ControllerMessage_DataWithID)(nil), @@ -781,7 +846,7 @@ func file_distributed_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_distributed_proto_rawDesc, NumEnums: 0, - NumMessages: 8, + NumMessages: 9, NumExtensions: 0, NumServices: 1, }, diff --git a/execution/distributed/distributed.proto b/execution/distributed/distributed.proto index d0193fdbed55..01748c9028ed 100644 --- a/execution/distributed/distributed.proto +++ b/execution/distributed/distributed.proto @@ -16,8 +16,12 @@ service DistributedTest { message RegisterRequest {} message RegisterResponse { uint32 instanceID = 1; - bytes archive = 2; // TODO: send this with a `stream` of bytes chunks - bytes options = 3; + repeated Test tests = 2; +} + +message Test { + bytes archive = 1; // TODO: send this with a `stream` of bytes chunks + bytes options = 2; } message AgentMessage { diff --git a/execution/distributed/distributed_grpc.pb.go b/execution/distributed/distributed_grpc.pb.go index 8e0694f49cba..f9766229824d 100644 --- a/execution/distributed/distributed_grpc.pb.go +++ b/execution/distributed/distributed_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.2.0 -// - protoc v3.19.4 +// - protoc v3.21.6 // source: distributed.proto package distributed diff --git a/execution/local/controller.go b/execution/local/controller.go index 6189bfeeee64..6e3116bd8af7 100644 --- a/execution/local/controller.go +++ b/execution/local/controller.go @@ -17,6 +17,7 @@ func (c *Controller) Wait(eventId string) func() error { return nil } } + func (c *Controller) Signal(eventId string) error { return nil } diff --git a/execution/scheduler.go b/execution/scheduler.go index d9dcbe68e1c4..9996f4589a54 100644 --- a/execution/scheduler.go +++ b/execution/scheduler.go @@ -375,15 +375,6 @@ func (e *Scheduler) runExecutor( runResults <- err } -func (e *Scheduler) signalAndWait(eventID string) error { - wait := e.controller.Wait(eventID) - err := e.controller.Signal(eventID) - if err != nil { - return err - } - return wait() -} - // Init concurrently initializes all of the planned VUs and then sequentially // initializes all of the configured executors. It also starts the measurement // and emission of the `vus` and `vus_max` metrics. @@ -392,8 +383,8 @@ func (e *Scheduler) Init( ) (stopVUEmission func(), err error) { logger := e.state.Test.Logger.WithField("phase", "execution-scheduler-init") - e.signalAndWait("test-init-start") - defer e.signalAndWait("vus-initialized") + SignalAndWait(e.controller, "test-init-start") + defer SignalAndWait(e.controller, "vus-initialized") execSchedRunCtx, execSchedRunCancel := context.WithCancel(runCtx) waitForVUsMetricPush := e.emitVUsAndVUsMax(execSchedRunCtx, samplesOut) @@ -417,7 +408,6 @@ func (e *Scheduler) Init( return stopVUEmission, e.initVUsAndExecutors(execSchedRunCtx, samplesOut) } - // Run the Scheduler, funneling all generated metric samples through the supplied // out channel. // @@ -425,8 +415,10 @@ func (e *Scheduler) Init( func (e *Scheduler) Run(globalCtx, runCtx context.Context, samplesOut chan<- metrics.SampleContainer) (err error) { logger := e.state.Test.Logger.WithField("phase", "execution-scheduler-run") - e.signalAndWait("test-start") - defer e.signalAndWait("test-done") + // TODO: use constants and namespaces for these + e.initProgress.Modify(pb.WithConstProgress(0, "Waiting to start...")) + SignalAndWait(e.controller, "scheduler-start") + defer SignalAndWait(e.controller, "scheduler-done") defer func() { if interruptErr := GetCancelReasonIfTestAborted(runCtx); interruptErr != nil { @@ -449,7 +441,7 @@ func (e *Scheduler) Run(globalCtx, runCtx context.Context, samplesOut chan<- met } } - e.signalAndWait("test-ready-to-run-setup") + SignalAndWait(e.controller, "test-ready-to-run-setup") e.initProgress.Modify(pb.WithConstProgress(1, "Starting test...")) e.state.MarkStarted() @@ -487,7 +479,7 @@ func (e *Scheduler) Run(globalCtx, runCtx context.Context, samplesOut chan<- met } } - e.signalAndWait("setup-done") + SignalAndWait(e.controller, "setup-done") e.initProgress.Modify(pb.WithHijack(e.getRunStats)) @@ -512,7 +504,7 @@ func (e *Scheduler) Run(globalCtx, runCtx context.Context, samplesOut chan<- met } } - e.signalAndWait("execution-done") + SignalAndWait(e.controller, "execution-done") // Run teardown() after all executors are done, if it's not disabled if !e.state.Test.Options.NoTeardown.Bool { @@ -534,7 +526,7 @@ func (e *Scheduler) Run(globalCtx, runCtx context.Context, samplesOut chan<- met } } - e.signalAndWait("teardown-done") + SignalAndWait(e.controller, "teardown-done") return firstErr } diff --git a/js/runner_test.go b/js/runner_test.go index 103d4146fcb5..c79d70c24a40 100644 --- a/js/runner_test.go +++ b/js/runner_test.go @@ -48,7 +48,6 @@ import ( "go.k6.io/k6/lib/testutils/mockoutput" "go.k6.io/k6/lib/types" "go.k6.io/k6/metrics" - "go.k6.io/k6/metrics/engine" "go.k6.io/k6/output" ) @@ -388,23 +387,17 @@ func TestDataIsolation(t *testing.T) { execScheduler, err := execution.NewScheduler(testRunState, local.NewController()) require.NoError(t, err) - metricsEngine, err := engine.NewMetricsEngine(testRunState, true) - require.NoError(t, err) - globalCtx, globalCancel := context.WithCancel(context.Background()) defer globalCancel() runCtx, runAbort := execution.NewTestRunContext(globalCtx, testRunState.Logger) mockOutput := mockoutput.New() - outputManager := output.NewManager([]output.Output{mockOutput, metricsEngine.CreateIngester()}, testRunState.Logger, runAbort) + outputManager := output.NewManager([]output.Output{mockOutput}, testRunState.Logger, runAbort) samples := make(chan metrics.SampleContainer, 1000) waitForMetricsFlushed, stopOutputs, err := outputManager.Start(samples) require.NoError(t, err) defer stopOutputs(nil) - finalizeThresholds := metricsEngine.StartThresholdCalculations(runAbort, execScheduler.GetState().GetCurrentTestRunDuration) - require.Nil(t, finalizeThresholds) - require.Empty(t, runner.defaultGroup.Groups) stopEmission, err := execScheduler.Init(runCtx, samples) diff --git a/metrics/engine/engine.go b/metrics/engine/engine.go index 48cdad70ec47..ad8c1b180784 100644 --- a/metrics/engine/engine.go +++ b/metrics/engine/engine.go @@ -15,7 +15,6 @@ import ( "go.k6.io/k6/errext/exitcodes" "go.k6.io/k6/lib" "go.k6.io/k6/metrics" - "go.k6.io/k6/output" "gopkg.in/guregu/null.v3" ) @@ -25,13 +24,11 @@ const thresholdsRate = 2 * time.Second // aggregated metric sample values. They are used to generate the end-of-test // summary and to evaluate the test thresholds. type MetricsEngine struct { - logger logrus.FieldLogger - test *lib.TestRunState - outputIngester *outputIngester + registry *metrics.Registry + logger logrus.FieldLogger // These can be both top-level metrics or sub-metrics - metricsWithThresholds []*metrics.Metric - + metricsWithThresholds []*metrics.Metric breachedThresholdsCount uint32 // TODO: completely refactor: @@ -44,32 +41,24 @@ type MetricsEngine struct { } // NewMetricsEngine creates a new metrics Engine with the given parameters. -func NewMetricsEngine(runState *lib.TestRunState, shouldProcessMetrics bool) (*MetricsEngine, error) { +func NewMetricsEngine(registry *metrics.Registry, logger logrus.FieldLogger) (*MetricsEngine, error) { me := &MetricsEngine{ - test: runState, - logger: runState.Logger.WithField("component", "metrics-engine"), + registry: registry, + logger: logger.WithField("component", "metrics-engine"), ObservedMetrics: make(map[string]*metrics.Metric), } - if shouldProcessMetrics { - err := me.initSubMetricsAndThresholds() - if err != nil { - return nil, err - } - } - return me, nil } // CreateIngester returns a pseudo-Output that uses the given metric samples to // update the engine's inner state. -func (me *MetricsEngine) CreateIngester() output.Output { - me.outputIngester = &outputIngester{ +func (me *MetricsEngine) CreateIngester() *OutputIngester { + return &OutputIngester{ logger: me.logger.WithField("component", "metrics-engine-ingester"), metricsEngine: me, cardinality: newCardinalityControl(), } - return me.outputIngester } // TODO: something better? deduplicate code with getThresholdMetricOrSubmetric @@ -80,7 +69,7 @@ func (me *MetricsEngine) ImportMetric(name string, data []byte) error { // TODO: replace with strings.Cut after Go 1.18 nameParts := strings.SplitN(name, "{", 2) - metric := me.test.Registry.Get(nameParts[0]) + metric := me.registry.Get(nameParts[0]) if metric == nil { return fmt.Errorf("metric '%s' does not exist in the script", nameParts[0]) } @@ -106,7 +95,7 @@ func (me *MetricsEngine) getThresholdMetricOrSubmetric(name string) (*metrics.Me // TODO: replace with strings.Cut after Go 1.18 nameParts := strings.SplitN(name, "{", 2) - metric := me.test.Registry.Get(nameParts[0]) + metric := me.registry.Get(nameParts[0]) if metric == nil { return nil, fmt.Errorf("metric '%s' does not exist in the script", nameParts[0]) } @@ -152,14 +141,25 @@ func (me *MetricsEngine) markObserved(metric *metrics.Metric) { if !metric.Observed { metric.Observed = true me.ObservedMetrics[metric.Name] = metric + } else { + // TODO: remove + // + // This is huge HACK to clean up the metrics from a previous test run, + // it will no longer be needed once this issue is resolved: + // https://github.com/grafana/k6/issues/572 + if _, ok := me.ObservedMetrics[metric.Name]; ok { + return // from this run, not a problem + } + metric.Sink.Drain() + me.ObservedMetrics[metric.Name] = metric } } -func (me *MetricsEngine) initSubMetricsAndThresholds() error { - for metricName, thresholds := range me.test.Options.Thresholds { +func (me *MetricsEngine) InitSubMetricsAndThresholds(options lib.Options, onlyLogErrors bool) error { + for metricName, thresholds := range options.Thresholds { metric, err := me.getThresholdMetricOrSubmetric(metricName) - if me.test.RuntimeOptions.NoThresholds.Bool { + if onlyLogErrors { if err != nil { me.logger.WithError(err).Warnf("Invalid metric '%s' in threshold definitions", metricName) } @@ -184,7 +184,7 @@ func (me *MetricsEngine) initSubMetricsAndThresholds() error { // TODO: refactor out of here when https://github.com/grafana/k6/issues/1321 // lands and there is a better way to enable a metric with tag - if me.test.Options.SystemTags.Has(metrics.TagExpectedResponse) { + if options.SystemTags.Has(metrics.TagExpectedResponse) { _, err := me.getThresholdMetricOrSubmetric("http_req_duration{expected_response:true}") if err != nil { return err // shouldn't happen, but ¯\_(ツ)_/¯ @@ -197,10 +197,10 @@ func (me *MetricsEngine) initSubMetricsAndThresholds() error { // StartThresholdCalculations spins up a new goroutine to crunch thresholds and // returns a callback that will stop the goroutine and finalizes calculations. func (me *MetricsEngine) StartThresholdCalculations( - abortRun func(error), - getCurrentTestRunDuration func() time.Duration, -) (finalize func() (breached []string), -) { + ingester *OutputIngester, + abortRun func(error), + getCurrentTestRunDuration func() time.Duration, +) (finalize func() (breached []string)) { if len(me.metricsWithThresholds) == 0 { return nil // no thresholds were defined } @@ -235,9 +235,9 @@ func (me *MetricsEngine) StartThresholdCalculations( }() return func() []string { - if me.outputIngester != nil { + if ingester != nil { // Stop the ingester so we don't get any more metrics - err := me.outputIngester.Stop() + err := ingester.Stop() if err != nil { me.logger.WithError(err).Warnf("There was a problem stopping the output ingester.") } diff --git a/metrics/engine/engine_test.go b/metrics/engine/engine_test.go index 9b132f105414..a941b4671b84 100644 --- a/metrics/engine/engine_test.go +++ b/metrics/engine/engine_test.go @@ -32,10 +32,12 @@ func TestNewMetricsEngineWithThresholds(t *testing.T) { _, err = trs.Registry.NewMetric("metric2", metrics.Counter) require.NoError(t, err) - me, err := NewMetricsEngine(trs, true) + me, err := NewMetricsEngine(trs.Registry, trs.Logger) require.NoError(t, err) require.NotNil(t, me) + require.NoError(t, me.InitSubMetricsAndThresholds(trs.Options, false)) + assert.Len(t, me.metricsWithThresholds, 2) } @@ -57,7 +59,7 @@ func TestMetricsEngineGetThresholdMetricOrSubmetricError(t *testing.T) { t.Parallel() me := newTestMetricsEngine(t) - _, err := me.test.Registry.NewMetric("metric1", metrics.Counter) + _, err := me.registry.NewMetric("metric1", metrics.Counter) require.NoError(t, err) _, err = me.getThresholdMetricOrSubmetric(tc.metricDefinition) @@ -69,16 +71,8 @@ func TestMetricsEngineGetThresholdMetricOrSubmetricError(t *testing.T) { func TestNewMetricsEngineNoThresholds(t *testing.T) { t.Parallel() - trs := &lib.TestRunState{ - TestPreInitState: &lib.TestPreInitState{ - Logger: testutils.NewLogger(t), - }, - } - - me, err := NewMetricsEngine(trs, true) - require.NoError(t, err) + me := newTestMetricsEngine(t) require.NotNil(t, me) - assert.Empty(t, me.metricsWithThresholds) } @@ -113,9 +107,9 @@ func TestMetricsEngineEvaluateThresholdNoAbort(t *testing.T) { t.Parallel() me := newTestMetricsEngine(t) - m1, err := me.test.Registry.NewMetric("m1", metrics.Counter) + m1, err := me.registry.NewMetric("m1", metrics.Counter) require.NoError(t, err) - m2, err := me.test.Registry.NewMetric("m2", metrics.Counter) + m2, err := me.registry.NewMetric("m2", metrics.Counter) require.NoError(t, err) ths := metrics.NewThresholds([]string{tc.threshold}) @@ -138,9 +132,9 @@ func TestMetricsEngineEvaluateIgnoreEmptySink(t *testing.T) { me := newTestMetricsEngine(t) - m1, err := me.test.Registry.NewMetric("m1", metrics.Counter) + m1, err := me.registry.NewMetric("m1", metrics.Counter) require.NoError(t, err) - m2, err := me.test.Registry.NewMetric("m2", metrics.Counter) + m2, err := me.registry.NewMetric("m2", metrics.Counter) require.NoError(t, err) ths := metrics.NewThresholds([]string{"count>5"}) @@ -159,18 +153,10 @@ func TestMetricsEngineEvaluateIgnoreEmptySink(t *testing.T) { assert.Empty(t, breached) } -func newTestMetricsEngine(t *testing.T) MetricsEngine { - trs := &lib.TestRunState{ - TestPreInitState: &lib.TestPreInitState{ - Logger: testutils.NewLogger(t), - Registry: metrics.NewRegistry(), - }, - } - - return MetricsEngine{ - logger: trs.Logger, - test: trs, - } +func newTestMetricsEngine(t *testing.T) *MetricsEngine { + m, err := NewMetricsEngine(metrics.NewRegistry(), testutils.NewLogger(t)) + require.NoError(t, err) + return m } func zeroTestRunDuration() time.Duration { diff --git a/metrics/engine/ingester.go b/metrics/engine/ingester.go index 62ffee8293e6..496b6a6eaa74 100644 --- a/metrics/engine/ingester.go +++ b/metrics/engine/ingester.go @@ -13,16 +13,16 @@ const ( timeSeriesFirstLimit = 100_000 ) -var _ output.Output = &outputIngester{} +var _ output.Output = &OutputIngester{} // IngesterDescription is a short description for ingester. // This variable is used from a function in cmd/ui file for matching this output // and print a special text. const IngesterDescription = "Internal Metrics Ingester" -// outputIngester implements the output.Output interface and can be used to +// OutputIngester implements the output.Output interface and can be used to // "feed" the MetricsEngine data from a `k6 run` test run. -type outputIngester struct { +type OutputIngester struct { output.SampleBuffer logger logrus.FieldLogger @@ -32,12 +32,12 @@ type outputIngester struct { } // Description returns a human-readable description of the output. -func (oi *outputIngester) Description() string { +func (oi *OutputIngester) Description() string { return IngesterDescription } // Start the engine by initializing a new output.PeriodicFlusher -func (oi *outputIngester) Start() error { +func (oi *OutputIngester) Start() error { oi.logger.Debug("Starting...") pf, err := output.NewPeriodicFlusher(collectRate, oi.flushMetrics) @@ -51,7 +51,7 @@ func (oi *outputIngester) Start() error { } // Stop flushes any remaining metrics and stops the goroutine. -func (oi *outputIngester) Stop() error { +func (oi *OutputIngester) Stop() error { oi.logger.Debug("Stopping...") defer oi.logger.Debug("Stopped!") oi.periodicFlusher.Stop() @@ -59,7 +59,7 @@ func (oi *outputIngester) Stop() error { } // flushMetrics Writes samples to the MetricsEngine -func (oi *outputIngester) flushMetrics() { +func (oi *OutputIngester) flushMetrics() { sampleContainers := oi.GetBufferedSamples() if len(sampleContainers) == 0 { return diff --git a/metrics/engine/ingester_test.go b/metrics/engine/ingester_test.go index 091c82c1e3ea..69b906d56c94 100644 --- a/metrics/engine/ingester_test.go +++ b/metrics/engine/ingester_test.go @@ -20,7 +20,7 @@ func TestIngesterOutputFlushMetrics(t *testing.T) { testMetric, err := piState.Registry.NewMetric("test_metric", metrics.Trend) require.NoError(t, err) - ingester := outputIngester{ + ingester := OutputIngester{ logger: piState.Logger, metricsEngine: &MetricsEngine{ ObservedMetrics: make(map[string]*metrics.Metric), @@ -56,9 +56,8 @@ func TestIngesterOutputFlushSubmetrics(t *testing.T) { require.NoError(t, err) me := &MetricsEngine{ - test: &lib.TestRunState{ - TestPreInitState: piState, - }, + logger: piState.Logger, + registry: piState.Registry, ObservedMetrics: make(map[string]*metrics.Metric), } _, err = me.getThresholdMetricOrSubmetric("test_metric{a:1}") @@ -67,7 +66,7 @@ func TestIngesterOutputFlushSubmetrics(t *testing.T) { // assert that observed metrics is empty before to start require.Empty(t, me.ObservedMetrics) - ingester := outputIngester{ + ingester := OutputIngester{ logger: piState.Logger, metricsEngine: me, cardinality: newCardinalityControl(), @@ -108,7 +107,7 @@ func TestOutputFlushMetricsTimeSeriesWarning(t *testing.T) { require.NoError(t, err) logger, hook := testutils.NewLoggerWithHook(nil) - ingester := outputIngester{ + ingester := OutputIngester{ logger: logger, metricsEngine: &MetricsEngine{ ObservedMetrics: make(map[string]*metrics.Metric),