Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-61277] Allow selecting between private and public connection types #881

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cmd/ltctl/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func createClients(output *terraform.Output) (map[string]*ssh.Client, error) {
clients := make(map[string]*ssh.Client)
if output.HasProxy() {
for i, inst := range output.Proxies {
sshc, err := extAgent.NewClient(inst.PublicIP)
sshc, err := extAgent.NewClient(inst.GetConnectionIP())
if err != nil {
return nil, fmt.Errorf("error in getting ssh connection %w", err)
}
Expand All @@ -131,15 +131,15 @@ func createClients(output *terraform.Output) (map[string]*ssh.Client, error) {
}

for i, instance := range output.Instances {
sshc, err := extAgent.NewClient(instance.PublicIP)
sshc, err := extAgent.NewClient(instance.GetConnectionIP())
if err != nil {
return nil, fmt.Errorf("error in getting ssh connection %w", err)
}
clients[fmt.Sprintf("app%d", i)] = sshc
}

for i, agent := range output.Agents {
sshc, err := extAgent.NewClient(agent.PublicIP)
sshc, err := extAgent.NewClient(agent.GetConnectionIP())
if err != nil {
return nil, fmt.Errorf("error in getting ssh connection %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/ltctl/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func RunLoadTestStatusCmdF(cmd *cobra.Command, args []string) error {
return err
}

prometheusURL := fmt.Sprintf("http://%s:9090", tfOutput.MetricsServer.PublicIP)
prometheusURL := fmt.Sprintf("http://%s:9090", tfOutput.MetricsServer.GetConnectionIP())
helper, err := prometheus.NewHelper(prometheusURL)
if err != nil {
return fmt.Errorf("failed to create prometheus.Helper: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/ltctl/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func RunGenerateReportCmdF(cmd *cobra.Command, args []string) error {
return fmt.Errorf("no active deployment found, use the `--prometheus-url` flag if you have a local or manually deployed Prometheus server running")
}

promURL = "http://" + output.MetricsServer.PublicIP + ":9090"
promURL = "http://" + output.MetricsServer.GetConnectionIP() + ":9090"
}

helper, err := prometheus.NewHelper(promURL)
Expand Down
4 changes: 2 additions & 2 deletions cmd/ltctl/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ func RunResetCmdF(cmd *cobra.Command, args []string) error {

appClients := make([]*ssh.Client, len(output.Instances))
for i, instance := range output.Instances {
client, err := extAgent.NewClient(instance.PublicIP)
client, err := extAgent.NewClient(instance.GetConnectionIP())
if err != nil {
return fmt.Errorf("error in getting ssh connection %w", err)
}
defer client.Close()
appClients[i] = client
}

agentClient, err := extAgent.NewClient(output.Agents[0].PublicIP)
agentClient, err := extAgent.NewClient(output.Agents[0].GetConnectionIP())
if err != nil {
return fmt.Errorf("error in getting ssh connection %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/ltkeycloak/from_mattermost.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,10 @@ func RunSyncFromMattermostCommandF(cmd *cobra.Command, _ []string) error {
if err != nil {
return fmt.Errorf("failed to get terraform output: %w", err)
}
if terraformOutput.KeycloakServer.PublicDNS == "" {
if terraformOutput.KeycloakServer.GetConnectionDNS() == "" {
return fmt.Errorf("keycloak database cluster not found in terraform output")
}
keycloakHost = terraformOutput.KeycloakServer.PublicDNS
keycloakHost = terraformOutput.KeycloakServer.GetConnectionDNS()
}

keycloakRealm, err := cmd.Flags().GetString("keycloak-realm")
Expand Down
2 changes: 1 addition & 1 deletion comparison/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func provisionFiles(t *terraform.Terraform, dpConfig *deploymentConfig, baseBuil
}
clients := make([]*ssh.Client, len(output.Instances))
for i, instance := range output.Instances {
client, err := extAgent.NewClient(instance.PublicIP)
client, err := extAgent.NewClient(instance.GetConnectionIP())
if err != nil {
return fmt.Errorf("error in getting ssh connection %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions comparison/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ func initLoadTest(t *terraform.Terraform, buildCfg BuildConfig, dumpFilename str
return err
}

agentClient, err := extAgent.NewClient(tfOutput.Agents[0].PublicIP)
agentClient, err := extAgent.NewClient(tfOutput.Agents[0].GetConnectionIP())
if err != nil {
return fmt.Errorf("error in getting ssh connection %w", err)
}
defer agentClient.Close()

appClients := make([]*ssh.Client, len(tfOutput.Instances))
for i, instance := range tfOutput.Instances {
client, err := extAgent.NewClient(instance.PublicIP)
client, err := extAgent.NewClient(instance.GetConnectionIP())
if err != nil {
return fmt.Errorf("error in getting ssh connection %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions comparison/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (c *Comparison) getResults(resultsCh <-chan Result) []Result {
return
}

promURL := "http://" + output.MetricsServer.PublicIP + ":9090"
promURL := "http://" + output.MetricsServer.GetConnectionIP() + ":9090"
helper, err := prometheus.NewHelper(promURL)
if err != nil {
mlog.Error("Failed to create prometheus.Helper", mlog.String("deployment ID", res.deploymentID), mlog.Err(err))
Expand Down Expand Up @@ -158,7 +158,7 @@ func (c *Comparison) getResults(resultsCh <-chan Result) []Result {
mlog.Error("Failed to upload dashboard", mlog.String("deployment ID", res.deploymentID), mlog.Err(err))
return
}
res.DashboardURL = fmt.Sprintf("http://%s:3000%s", output.MetricsServer.PublicIP, url)
res.DashboardURL = fmt.Sprintf("http://%s:3000%s", output.MetricsServer.GetConnectionIP(), url)
}

resCh <- res
Expand Down
1 change: 1 addition & 0 deletions config/deployer.sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"Proxy": [],
"Redis": []
},
"ConnectionType": "public",
"AppInstanceCount": 1,
"AppInstanceType": "c7i.xlarge",
"AppAttachIAMProfile": "",
Expand Down
1 change: 1 addition & 0 deletions config/deployer.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ AWSAMI = 'ami-003d3d03cfe1b0468'
AWSProfile = 'mm-loadtest'
AWSRegion = 'us-east-1'
AWSAvailabilityZone = 'us-east-1c'
ConnectionType = 'public'

# Mattermost configuration
AdminEmail = '[email protected]'
Expand Down
2 changes: 2 additions & 0 deletions deployment/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type Config struct {
ClusterVpcID string
// ClusterSubnetIDs is the ids of the subnets associated to each resource type.
ClusterSubnetIDs ClusterSubnetIDs
// ConnectionType defines how instances should be accessed, either "public" or "private"
ConnectionType string `default:"public" validate:"oneof:{public,private}"`
// Number of application instances.
AppInstanceCount int `default:"1" validate:"range:[0,)"`
// Type of the EC2 instance for app.
Expand Down
6 changes: 3 additions & 3 deletions deployment/terraform/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ func (t *Terraform) configureAndRunAgents(extAgent *ssh.ExtAgent) error {
go func() {
defer wg.Done()

sshc, err := extAgent.NewClient(instance.PublicIP)
sshc, err := extAgent.NewClient(instance.GetConnectionIP())
if err != nil {
mlog.Error("error creating ssh client", mlog.Err(err), mlog.Int("agent", agentNumber))
foundErr.Store(true)
return
}
mlog.Info("Configuring agent", mlog.String("ip", instance.PublicIP), mlog.Int("agent", agentNumber))
mlog.Info("Configuring agent", mlog.String("ip", instance.GetConnectionIP()), mlog.Int("agent", agentNumber))
if uploadBinary {
dstFilePath := "/home/ubuntu/tmp.tar.gz"
mlog.Info("Uploading binary", mlog.String("file", packagePath), mlog.Int("agent", agentNumber))
Expand Down Expand Up @@ -211,7 +211,7 @@ func (t *Terraform) initLoadtest(extAgent *ssh.ExtAgent, initData bool) error {
if len(t.output.Agents) == 0 {
return errors.New("there are no agents to initialize load-test")
}
ip := t.output.Agents[0].PublicIP
ip := t.output.Agents[0].GetConnectionIP()
sshc, err := extAgent.NewClient(ip)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions deployment/terraform/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (t *Terraform) StartCoordinator(config *coordinator.Config) error {
if len(t.output.Agents) == 0 {
return errors.New("there are no agent instances to run the coordinator")
}
ip := t.output.Agents[0].PublicIP
ip := t.output.Agents[0].GetConnectionIP()

var loadAgentConfigs []cluster.LoadAgentConfig
for _, val := range t.output.Agents {
Expand Down Expand Up @@ -159,7 +159,7 @@ func (t *Terraform) StopCoordinator() (coordinator.Status, error) {
if len(t.output.Agents) == 0 {
return status, errors.New("there are no agents to initialize load-test")
}
ip := t.output.Agents[0].PublicIP
ip := t.output.Agents[0].GetConnectionIP()

mlog.Info("Stopping the coordinator", mlog.String("ip", ip))

Expand Down Expand Up @@ -190,7 +190,7 @@ func (t *Terraform) GetCoordinatorStatus() (coordinator.Status, error) {
if len(t.output.Agents) == 0 {
return status, errors.New("there are no agents to initialize load-test")
}
ip := t.output.Agents[0].PublicIP
ip := t.output.Agents[0].GetConnectionIP()

id := t.config.ClusterName + "-coordinator-0"
coord, err := client.New(id, "http://"+ip+":4000", nil)
Expand All @@ -216,7 +216,7 @@ func (t *Terraform) InjectAction(actionID string) (coordinator.Status, error) {
if len(t.output.Agents) == 0 {
return status, errors.New("there are no agents to inject the action")
}
ip := t.output.Agents[0].PublicIP
ip := t.output.Agents[0].GetConnectionIP()

id := t.config.ClusterName + "-coordinator-0"
coord, err := client.New(id, "http://"+ip+":4000", nil)
Expand Down
20 changes: 10 additions & 10 deletions deployment/terraform/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ func (t *Terraform) Create(extAgent *ssh.ExtAgent, initData bool) error {
// This case will only succeed if siteURL is empty.
// And it's an error to have siteURL empty and set multiple proxies. (see (c *Config) validateProxyConfig)
// So we can safely take the DNS of the first entry.
siteURL = "http://" + t.output.Proxies[0].PublicDNS
siteURL = "http://" + t.output.Proxies[0].GetConnectionDNS()
// SiteURL not defined, single app node: we use the app node's public DNS plus port
default:
siteURL = "http://" + t.output.Instances[0].PublicDNS + ":8065"
siteURL = "http://" + t.output.Instances[0].GetConnectionDNS() + ":8065"
}

// Updating the config.json for each instance of app server
Expand All @@ -235,14 +235,14 @@ func (t *Terraform) Create(extAgent *ssh.ExtAgent, initData bool) error {

// The URL to ping cannot be the same as the site URL, since that one could contain a
// hostname that only instances know how to resolve
pingURL := t.output.Instances[0].PublicDNS + ":8065"
pingURL := t.output.Instances[0].GetConnectionDNS() + ":8065"
if t.output.HasProxy() {
for _, inst := range t.output.Proxies {
// Updating the nginx config on proxy server
t.setupProxyServer(extAgent, inst)
}
// We can ping the server through any of the proxies, doesn't matter here.
pingURL = t.output.Proxies[0].PublicDNS
pingURL = t.output.Proxies[0].GetConnectionDNS()
}

if err := pingServer("http://" + pingURL); err != nil {
Expand All @@ -261,7 +261,7 @@ func (t *Terraform) Create(extAgent *ssh.ExtAgent, initData bool) error {
defer wg.Done()
if t.output.HasElasticSearch() {
mlog.Info("Setting up Elasticsearch")
err := t.setupElasticSearchServer(extAgent, t.output.Instances[0].PublicIP)
err := t.setupElasticSearchServer(extAgent, t.output.Instances[0].GetConnectionIP())

if err != nil {
errorsChan <- fmt.Errorf("unable to setup Elasticsearch server: %w", err)
Expand Down Expand Up @@ -356,14 +356,14 @@ func (t *Terraform) PostProcessDatabase(extAgent *ssh.ExtAgent) error {

func (t *Terraform) setupAppServers(extAgent *ssh.ExtAgent, uploadBinary bool, uploadRelease bool, uploadPath string, siteURL string) error {
for _, val := range t.output.Instances {
err := t.setupMMServer(extAgent, val.PublicIP, siteURL, uploadBinary, uploadRelease, uploadPath, val.Tags.Name)
err := t.setupMMServer(extAgent, val.GetConnectionIP(), siteURL, uploadBinary, uploadRelease, uploadPath, val.Tags.Name)
if err != nil {
return err
}
}

for _, val := range t.output.JobServers {
err := t.setupJobServer(extAgent, val.PublicIP, siteURL, uploadBinary, uploadRelease, uploadPath, val.Tags.Name)
err := t.setupJobServer(extAgent, val.GetConnectionIP(), siteURL, uploadBinary, uploadRelease, uploadPath, val.Tags.Name)
if err != nil {
return err
}
Expand Down Expand Up @@ -776,7 +776,7 @@ func (t *Terraform) getProxyInstanceInfo() (*types.InstanceTypeInfo, error) {
}

func (t *Terraform) setupProxyServer(extAgent *ssh.ExtAgent, instance Instance) {
ip := instance.PublicDNS
ip := instance.GetConnectionDNS()

sshc, err := extAgent.NewClient(ip)
if err != nil {
Expand Down Expand Up @@ -880,7 +880,7 @@ func (t *Terraform) createAdminUser(extAgent *ssh.ExtAgent) error {
t.config.AdminPassword,
)
mlog.Info("Creating admin user:", mlog.String("cmd", cmd))
sshc, err := extAgent.NewClient(t.output.Instances[0].PublicIP)
sshc, err := extAgent.NewClient(t.output.Instances[0].GetConnectionIP())
if err != nil {
return err
}
Expand All @@ -906,7 +906,7 @@ func (t *Terraform) updatePostgresSettings(extAgent *ssh.ExtAgent) error {
return errors.New("no instances found in Terraform output")
}

sshc, err := extAgent.NewClient(t.output.Instances[0].PublicIP)
sshc, err := extAgent.NewClient(t.output.Instances[0].GetConnectionIP())
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions deployment/terraform/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (t *Terraform) ClearLicensesData() error {

appClients := make([]*ssh.Client, len(output.Instances))
for i, instance := range output.Instances {
client, err := extAgent.NewClient(instance.PublicIP)
client, err := extAgent.NewClient(instance.GetConnectionIP())
if err != nil {
return fmt.Errorf("error in getting ssh connection %w", err)
}
Expand Down Expand Up @@ -98,7 +98,7 @@ func (t *Terraform) IngestDump() error {

appClients := make([]*ssh.Client, len(output.Instances))
for i, instance := range output.Instances {
client, err := extAgent.NewClient(instance.PublicIP)
client, err := extAgent.NewClient(instance.GetConnectionIP())
if err != nil {
return fmt.Errorf("error in getting ssh connection %w", err)
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func (t *Terraform) ExecuteCustomSQL() error {
return fmt.Errorf("no app instances deployed")
}

client, err := extAgent.NewClient(output.Instances[0].PublicIP)
client, err := extAgent.NewClient(output.Instances[0].GetConnectionIP())
if err != nil {
return fmt.Errorf("error in getting ssh connection %w", err)
}
Expand Down Expand Up @@ -219,7 +219,7 @@ func (t *Terraform) executeDatabaseCommands(extraCommands []deployment.Cmd) erro

appClients := make([]*ssh.Client, len(output.Instances))
for i, instance := range output.Instances {
client, err := extAgent.NewClient(instance.PublicIP)
client, err := extAgent.NewClient(instance.GetConnectionIP())
if err != nil {
return fmt.Errorf("error in getting ssh connection %w", err)
}
Expand Down
24 changes: 12 additions & 12 deletions deployment/terraform/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@ func displayInfo(output *Output) {

if output.HasAppServers() {
if output.HasProxy() {
fmt.Println("Mattermost URL: http://" + output.Proxies[0].PublicDNS)
fmt.Println("Mattermost URL: http://" + output.Proxies[0].GetConnectionDNS())
} else {
fmt.Println("Mattermost URL: http://" + output.Instances[0].PublicDNS + ":8065")
fmt.Println("Mattermost URL: http://" + output.Instances[0].GetConnectionDNS() + ":8065")
}
fmt.Println("App Server(s):")
for _, instance := range output.Instances {
fmt.Println("- " + instance.Tags.Name + ": " + instance.PublicIP)
fmt.Println("- " + instance.Tags.Name + ": " + instance.GetConnectionIP())
}
}

if output.HasJobServer() {
fmt.Println("Job Server(s):")
for _, instance := range output.JobServers {
fmt.Println("- " + instance.Tags.Name + ": " + instance.PublicIP)
fmt.Println("- " + instance.Tags.Name + ": " + instance.GetConnectionIP())
}
}

if output.HasAgents() {
fmt.Println("Load Agent(s):")
for _, agent := range output.Agents {
fmt.Println("- " + agent.Tags.Name + ": " + agent.PublicIP)
fmt.Println("- " + agent.Tags.Name + ": " + agent.GetConnectionIP())
}

fmt.Println("Coordinator: " + output.Agents[0].PublicIP)
fmt.Println("Coordinator: " + output.Agents[0].GetConnectionIP())
}

if output.HasProxy() {
Expand All @@ -60,18 +60,18 @@ func displayInfo(output *Output) {
fmt.Println("Proxy:")
}
for _, inst := range output.Proxies {
fmt.Println("- " + inst.Tags.Name + ": " + inst.PublicIP)
fmt.Println("- " + inst.Tags.Name + ": " + inst.GetConnectionIP())
}
}

if output.HasMetrics() {
fmt.Println("Grafana URL: http://" + output.MetricsServer.PublicIP + ":3000")
fmt.Println("Prometheus URL: http://" + output.MetricsServer.PublicIP + ":9090")
fmt.Println("Pyroscope URL: http://" + output.MetricsServer.PublicIP + ":4040")
fmt.Println("Grafana URL: http://" + output.MetricsServer.GetConnectionIP() + ":3000")
fmt.Println("Prometheus URL: http://" + output.MetricsServer.GetConnectionIP() + ":9090")
fmt.Println("Pyroscope URL: http://" + output.MetricsServer.GetConnectionIP() + ":4040")
}
if output.HasKeycloak() {
fmt.Println("Keycloak server IP: " + output.KeycloakServer.PublicIP)
fmt.Println("Keycloak URL: http://" + output.KeycloakServer.PublicDNS + ":8080/")
fmt.Println("Keycloak server IP: " + output.KeycloakServer.GetConnectionIP())
fmt.Println("Keycloak URL: http://" + output.KeycloakServer.GetConnectionDNS() + ":8080/")
if len(output.KeycloakDatabaseCluster.Instances) > 0 {
fmt.Printf("Keycloak DB Cluster: %v\n", output.KeycloakDatabaseCluster.Instances[0].Endpoint)
}
Expand Down
Loading
Loading