Skip to content

Commit

Permalink
MM-57355: Moving to a test service env (#724)
Browse files Browse the repository at this point in the history
https://mattermost.atlassian.net/browse/MM-57355

* Expose the service env from CLI

* add documentation
  • Loading branch information
agnivade authored Apr 15, 2024
1 parent 2ac55d1 commit 52ebb51
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
17 changes: 14 additions & 3 deletions cmd/ltctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/mattermost/mattermost-load-test-ng/deployment"
"github.com/mattermost/mattermost-load-test-ng/deployment/terraform"
"github.com/mattermost/mattermost-load-test-ng/logger"
"github.com/mattermost/mattermost/server/public/model"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -171,18 +172,28 @@ func getConfig(cmd *cobra.Command) (deployment.Config, error) {
return *cfg, nil
}

func setServiceEnv(cmd *cobra.Command) {
serviceEnv, _ := cmd.Flags().GetString("service_environment")
// Set it to test if it's neither prod nor test.
if serviceEnv != model.ServiceEnvironmentProduction && serviceEnv != model.ServiceEnvironmentTest {
serviceEnv = model.ServiceEnvironmentTest
}
os.Setenv("MM_SERVICEENVIRONMENT", serviceEnv)
}

func main() {
rootCmd := &cobra.Command{
Use: "ltctl",
SilenceUsage: true,
Short: "Manage and control load-test deployments",
}
rootCmd.PersistentFlags().StringP("config", "c", "", "path to the deployer configuration file to use")
rootCmd.PersistentFlags().StringP("service_environment", "s", model.ServiceEnvironmentTest, "value of the MM_SERVICEENVIRONMENT variable. Valid values are production, test")

deploymentCmd := &cobra.Command{
Use: "deployment",
Short: "Manage a load-test deployment",
PersistentPreRun: func(_ *cobra.Command, _ []string) { os.Setenv("MM_SERVICEENVIRONMENT", "production") },
PersistentPreRun: func(cmd *cobra.Command, _ []string) { setServiceEnv(cmd) },
PersistentPostRun: func(_ *cobra.Command, _ []string) { os.Unsetenv("MM_SERVICEENVIRONMENT") },
}

Expand Down Expand Up @@ -230,7 +241,7 @@ func main() {
loadtestCmd := &cobra.Command{
Use: "loadtest",
Short: "Manage the load-test",
PersistentPreRun: func(_ *cobra.Command, _ []string) { os.Setenv("MM_SERVICEENVIRONMENT", "production") },
PersistentPreRun: func(cmd *cobra.Command, _ []string) { setServiceEnv(cmd) },
PersistentPostRun: func(_ *cobra.Command, _ []string) { os.Unsetenv("MM_SERVICEENVIRONMENT") },
}

Expand Down Expand Up @@ -381,7 +392,7 @@ func main() {
comparisonCmd := &cobra.Command{
Use: "comparison",
Short: "Manage fully automated load-test comparisons environments",
PersistentPreRun: func(_ *cobra.Command, _ []string) { os.Setenv("MM_SERVICEENVIRONMENT", "production") },
PersistentPreRun: func(cmd *cobra.Command, _ []string) { setServiceEnv(cmd) },
PersistentPostRun: func(_ *cobra.Command, _ []string) { os.Unsetenv("MM_SERVICEENVIRONMENT") },
}
comparisonCmd.Flags().StringP("comparison-config", "", "", "path to the comparison config file to use")
Expand Down
2 changes: 1 addition & 1 deletion deployment/terraform/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ func (t *Terraform) setupAppServer(extAgent *ssh.ExtAgent, ip, siteURL, serviceF
// Upload files
batch := []uploadInfo{
{srcData: strings.TrimPrefix(serverSysctlConfig, "\n"), dstPath: "/etc/sysctl.conf"},
{srcData: strings.TrimSpace(serviceFile), dstPath: "/lib/systemd/system/mattermost.service"},
{srcData: strings.TrimSpace(fmt.Sprintf(serviceFile, os.Getenv("MM_SERVICEENVIRONMENT"))), dstPath: "/lib/systemd/system/mattermost.service"},
{srcData: strings.TrimPrefix(limitsConfig, "\n"), dstPath: "/etc/security/limits.conf"},
}

Expand Down
2 changes: 2 additions & 0 deletions deployment/terraform/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Group=ubuntu
LimitNOFILE=49152
Environment=MM_FEATUREFLAGS_POSTPRIORITY=true
Environment=MM_FEATUREFLAGS_WEBSOCKETEVENTSCOPE=true
Environment=MM_SERVICEENVIRONMENT=%s
[Install]
WantedBy=multi-user.target
Expand Down Expand Up @@ -344,6 +345,7 @@ WorkingDirectory=/opt/mattermost
User=ubuntu
Group=ubuntu
LimitNOFILE=49152
Environment=MM_SERVICEENVIRONMENT=%s
[Install]
WantedBy=multi-user.target
Expand Down
4 changes: 4 additions & 0 deletions docs/terraform_loadtest.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Once done, it will output information about the entire cluster. Everything will

If you see an error when running `deployment create` mentioning a "resource already exists", it is most likely because your `ClusterName` is not a unique value within your AWS account. Run `go run ./cmd/ltctl deployment destroy` to clean up the half created deployment. Then change the `ClusterName` to something more unique for your loadtest and try again.

NOTE: If you are not a Mattermost staff, then most likely you would want to set the `--service_environment` flag to `production` so that the right license type is picked up. Internally, we use test licenses.

### Get information on the current deployment

```sh
Expand Down Expand Up @@ -108,6 +110,8 @@ go run ./cmd/ltctl loadtest start

This will begin to run the load-test across the whole cluster of load-test agents.

NOTE: If you are not a Mattermost staff, then most likely you would want to set the `--service_environment` flag to `production` so that the right license type is picked up. Internally, we use test licenses.

### Show the load-test status

```sh
Expand Down

0 comments on commit 52ebb51

Please sign in to comment.