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

chore: remove get instance id function #22

Merged
merged 3 commits into from
Apr 13, 2023
Merged
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
15 changes: 0 additions & 15 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,19 +319,4 @@ func Test_Misc(t *testing.T) {

t.Setenv("RELEASE_NAME", "value")
require.Equal(t, "value", GetReleaseName())

t.Setenv("INSTANCE_ID", "allbirds-v0-rudderstack-gw-ha-0-85d66f748f-8w4td")
require.Equal(t, "0", GetInstanceID())

t.Setenv("INSTANCE_ID", "prousmtusmt-v0-rs-gw-0")
require.Equal(t, "0", GetInstanceID())

t.Setenv("INSTANCE_ID", "prousmtusmt-v0-rs")
require.Equal(t, "", GetInstanceID())

t.Setenv("INSTANCE_ID", "prousmtusmt-v0-rs-gw-10")
require.Equal(t, "10", GetInstanceID())

t.Setenv("INSTANCE_ID", "prousmtusmt-v0-rs-gw-ha-12-234234-10")
require.Equal(t, "12", GetInstanceID())
}
22 changes: 0 additions & 22 deletions config/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ package config

import (
"os"
"regexp"
"strings"
)

var (
regexGwHa = regexp.MustCompile(`^.*-gw-ha-\d+-\w+-\w+$`)
regexGwNonHaOrProcessor = regexp.MustCompile(`^.*-\d+$`)
)

// GetWorkspaceToken returns the workspace token provided in the environment variables
Expand Down Expand Up @@ -36,21 +29,6 @@ func GetKubeNamespace() string {
return os.Getenv("KUBE_NAMESPACE")
}

func GetInstanceID() string {
instance := GetString("INSTANCE_ID", "")
instanceArr := strings.Split(instance, "-")
length := len(instanceArr)
// This handles 2 kinds of server instances
// a) Processor OR Gateway running in non HA mod where the instance name ends with the index
// b) Gateway running in HA mode, where the instance name is of the form *-gw-ha-<index>-<statefulset-id>-<pod-id>
if (regexGwHa.MatchString(instance)) && (length > 3) {
return instanceArr[length-3]
} else if (regexGwNonHaOrProcessor.MatchString(instance)) && (length > 1) {
return instanceArr[length-1]
}
return ""
}

func GetReleaseName() string {
return os.Getenv("RELEASE_NAME")
}