Skip to content

Commit

Permalink
client: support EU environments
Browse files Browse the repository at this point in the history
  • Loading branch information
gdvalle committed Feb 12, 2024
1 parent e010bb1 commit 1cb3b0b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ The `exporter` utility is built-in to the provider binary and requires certain e
For the LIGHTSTEP_ENV variable:

- public = app.lightstep.com
- eu-public = app.eu.lightstep.com
- meta = app-meta.lightstep.com
- staging = app-staging.lightstep.com
- eu-staging = app.eu-staging.lightstep.com

```
$ export LIGHTSTEP_API_KEY=....
Expand Down
12 changes: 11 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func NewClient(apiKey string, orgName string, env string) *Client {
return NewClientWithUserAgent(apiKey, orgName, env, fmt.Sprintf("%s/%s", DefaultUserAgent, version.ProviderVersion))
}

func NewClientWithUserAgent(apiKey string, orgName string, env string, userAgent string) *Client {
func resolveBaseURL(env string) string {
// Let the user override the API base URL.
// e.g. http://localhost:8080
envBaseURL := os.Getenv("LIGHTSTEP_API_BASE_URL")
Expand All @@ -89,10 +89,20 @@ func NewClientWithUserAgent(apiKey string, orgName string, env string, userAgent
baseURL = envBaseURL
} else if env == "public" {
baseURL = "https://api.lightstep.com"
} else if env == "eu-public" {
baseURL = "https://api.eu.lightstep.com"
} else if env == "eu-staging" {
baseURL = "https://api.eu-staging.lightstep.com"
} else {
baseURL = fmt.Sprintf("https://api-%v.lightstep.com", env)
}

return baseURL
}

func NewClientWithUserAgent(apiKey string, orgName string, env string, userAgent string) *Client {
baseURL := resolveBaseURL(env)

fullBaseURL := fmt.Sprintf("%s/public/v0.2/%v", baseURL, orgName)

rateLimitStr := os.Getenv("LIGHTSTEP_API_RATE_LIMIT")
Expand Down
12 changes: 11 additions & 1 deletion client/client_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package client

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/stretchr/testify/assert"
)

func TestNew_public(t *testing.T) {
Expand All @@ -24,3 +25,12 @@ func TestNew_env_var_provided_baseURL(t *testing.T) {
c := NewClient("api-key", "org-name", "public")
assert.Equal(t, "http://localhost:8080/public/v0.2/org-name", c.baseURL)
}

func Test_resolveBaseURL(t *testing.T) {
t.Parallel()
assert.Equal(t, "https://api.lightstep.com", resolveBaseURL("public"))
assert.Equal(t, "https://api-meta.lightstep.com", resolveBaseURL("meta"))
assert.Equal(t, "https://api.eu.lightstep.com", resolveBaseURL("eu-public"))
assert.Equal(t, "https://api.eu-staging.lightstep.com", resolveBaseURL("eu-staging"))
assert.Equal(t, "https://api-other.lightstep.com", resolveBaseURL("other"))
}
5 changes: 3 additions & 2 deletions exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ func Run(args ...string) error {

// default to public API environment
lightstepEnv := "public"
if len(os.Getenv("LIGHTSTEP_ENV")) > 0 {
lightstepEnv = os.Getenv("LIGHTSTEP_ENV")
userEnv := os.Getenv("LIGHTSTEP_ENV")
if len(userEnv) > 0 {
lightstepEnv = userEnv
}

if len(args) < 4 {
Expand Down

0 comments on commit 1cb3b0b

Please sign in to comment.