Skip to content

Commit

Permalink
chore: remove get instance id function (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
cisse21 authored Apr 13, 2023
1 parent 7de3a1a commit dfd9478
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 37 deletions.
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")
}

0 comments on commit dfd9478

Please sign in to comment.