Skip to content
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
34 changes: 29 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2049,18 +2049,26 @@ func calculateIdentityURL(licenseKey string, staging, fedramp bool) string {
}

func calculateIdentityProductionURL(licenseKey string) string {
// only EU supported
if license.IsRegionEU(licenseKey) {
return defaultIdentityURLEu
}

if license.IsRegionJP(licenseKey) {
return defaultIdentityURLJp
}

return defaultIdentityURL
}

func calculateIdentityStagingURL(licenseKey string) string {
// only EU supported
if license.IsRegionEU(licenseKey) {
return defaultIdentityStagingURLEu
}

if license.IsRegionJP(licenseKey) {
return defaultIdentityStagingURLJp
}

return defaultIdentityStagingURL
}

Expand All @@ -2075,18 +2083,26 @@ func calculateCmdChannelURL(licenseKey string, staging, fedramp bool) string {
}

func calculateCmdChannelProductionURL(licenseKey string) string {
// only EU supported
if license.IsRegionEU(licenseKey) {
return defaultCmdChannelURLEu
}

if license.IsRegionJP(licenseKey) {
return defaultCmdChannelURLJp
}

return defaultCmdChannelURL
}

func calculateCmdChannelStagingURL(licenseKey string) string {
// only EU supported
if license.IsRegionEU(licenseKey) {
return defaultCmdChannelStagingURLEu
}

if license.IsRegionJP(licenseKey) {
return defaultCmdChannelStagingURLJp
}

return defaultCmdChannelStagingURL
}

Expand All @@ -2101,10 +2117,14 @@ func calculateSelfInstrumentationApmHost(licenseKey string, staging bool, fedram
}

func calculateSelfInstrumentationApmProductionHost(licenseKey string) string {
// only EU supported
if license.IsRegionEU(licenseKey) {
return defaultAPMCollectorHostEu
}

if license.IsRegionJP(licenseKey) {
return defaultAPMCollectorHostJp
}

return defaultAPMCollectorHost
}

Expand Down Expand Up @@ -2132,6 +2152,10 @@ func urlRegionPrefix(licenseKey string) string {
return "eu."
}

if license.IsRegionJP(licenseKey) {
return "jp."
}

return ""
}

Expand Down
62 changes: 56 additions & 6 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,24 @@ func (s *ConfigSuite) TestCalculateCollectorURL(c *C) {
{license: "0123456789012345678901234567890123456789", expectURL: "https://infra-api.newrelic.com", staging: false, fedramp: false},
// non-region license, staging true
{license: "0123456789012345678901234567890123456789", expectURL: "https://staging-infra-api.newrelic.com", staging: true, fedramp: false},
// four letter region
// four letter region eu
{license: "eu01xx6789012345678901234567890123456789", expectURL: "https://infra-api.eu.newrelic.com", staging: false, fedramp: false},
// four letter region
// four letter region eu, staging
{license: "eu01xx6789012345678901234567890123456789", expectURL: "https://staging-infra-api.eu.newrelic.com", staging: true, fedramp: false},
// four letter region jp
{
license: "jp01xx6789012345678901234567890123456789",
expectURL: "https://infra-api.jp.newrelic.com",
staging: false,
fedramp: false,
},
// four letter region jp, staging
{
license: "jp01xx6789012345678901234567890123456789",
expectURL: "https://staging-infra-api.jp.newrelic.com",
staging: true,
fedramp: false,
},
// non-region license, fedramp true
{license: "0123456789012345678901234567890123456789", expectURL: "https://gov-infra-api.newrelic.com", staging: false, fedramp: true},
}
Expand Down Expand Up @@ -444,6 +458,22 @@ func (s *ConfigSuite) TestCalculateDimensionalMetricURL(c *C) {
false,
"https://staging-metric-api.eu.newrelic.com",
},
{
"Default URL, jp license region, no collector URL",
"jp01xx6789012345678901234567890123456789",
"",
false,
false,
"https://metric-api.jp.newrelic.com",
},
{
"Staging URL, jp license region, no collector URL",
"jp01xx6789012345678901234567890123456789",
"",
true,
false,
"https://staging-metric-api.jp.newrelic.com",
},
{
"Default URL, fedramp flag, no collector URL",
"0123456789012345678901234567890123456789",
Expand Down Expand Up @@ -479,10 +509,20 @@ func (s *ConfigSuite) TestCalculateIdentityURL(c *C) {
{license: "0123456789012345678901234567890123456789", expectURL: defaultIdentityURL, staging: false},
// non-region license
{license: "0123456789012345678901234567890123456789", expectURL: defaultIdentityStagingURL, staging: true},
// four letter region
// four letter region eu
{license: "eu01xx6789012345678901234567890123456789", expectURL: defaultIdentityURLEu, staging: false},
// four letter region
// four letter region eu, staging
{license: "eu01xx6789012345678901234567890123456789", expectURL: defaultIdentityStagingURLEu, staging: true},
// four letter region jp
{
license: "jp01xx6789012345678901234567890123456789", expectURL: defaultIdentityURLJp,
staging: false, fedramp: false,
},
// four letter region jp, staging
{
license: "jp01xx6789012345678901234567890123456789", expectURL: defaultIdentityStagingURLJp,
staging: true, fedramp: false,
},
// five letter region
{license: "gov01x6789012345678901234567890123456789", expectURL: defaultIdentityURL, staging: false},
// five letter region
Expand All @@ -507,10 +547,20 @@ func (s *ConfigSuite) TestCalculateCmdChannelURL(c *C) {
{license: "0123456789012345678901234567890123456789", expectURL: defaultCmdChannelURL, staging: false},
// non-region license
{license: "0123456789012345678901234567890123456789", expectURL: defaultCmdChannelStagingURL, staging: true},
// four letter region
// four letter region eu
{license: "eu01xx6789012345678901234567890123456789", expectURL: defaultCmdChannelURLEu, staging: false},
// four letter region
// four letter region eu, staging
{license: "eu01xx6789012345678901234567890123456789", expectURL: defaultCmdChannelStagingURLEu, staging: true},
// four letter region jp
{
license: "jp01xx6789012345678901234567890123456789", expectURL: defaultCmdChannelURLJp,
staging: false, fedramp: false,
},
// four letter region jp, staging
{
license: "jp01xx6789012345678901234567890123456789", expectURL: defaultCmdChannelStagingURLJp,
staging: true, fedramp: false,
},
// five letter region
{license: "gov01x6789012345678901234567890123456789", expectURL: defaultCmdChannelURL, staging: false},
// five letter region
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const (
defaultIdentityStagingURLEu = "https://staging-identity-api.eu.newrelic.com"
defaultCmdChannelURLEu = "https://infrastructure-command-api.eu.newrelic.com"
defaultCmdChannelStagingURLEu = "https://staging-infrastructure-command-api.eu.newrelic.com"
defaultIdentityURLJp = "https://identity-api.jp.newrelic.com"
defaultIdentityStagingURLJp = "https://staging-identity-api.jp.newrelic.com"
defaultCmdChannelURLJp = "https://infrastructure-command-api.jp.newrelic.com"
defaultCmdChannelStagingURLJp = "https://staging-infrastructure-command-api.jp.newrelic.com"
defaultCmdChannelURL = "https://infrastructure-command-api.newrelic.com"
defaultCmdChannelStagingURL = "https://staging-infrastructure-command-api.newrelic.com"
defaultIdentityURL = "https://identity-api.newrelic.com"
Expand All @@ -29,6 +33,7 @@ const (
defaultSecureFedralCmdChannelURL = "https://gov-infrastructure-command-api.newrelic.com"
defaultAPMCollectorHost = "collector.newrelic.com"
defaultAPMCollectorHostEu = "collector.eu.newrelic.com"
defaultAPMCollectorHostJp = "collector.jp.newrelic.com"
defaultSecureFederalAPMCollectorHost = "gov-collector.newrelic.com"
defaultAPMCollectorHostStaging = "staging-collector.newrelic.com"
)
Expand Down
5 changes: 5 additions & 0 deletions pkg/integrations/v4/logs/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var cfgLogger = log.WithComponent("integrations.Supervisor.Config").WithField("p
// FluentBit default values.
const (
euEndpoint = "https://log-api.eu.newrelic.com/log/v1"
jpEndpoint = "https://log-api.jp.newrelic.com/log/v1"
fedrampEndpoint = "https://gov-log-api.newrelic.com/log/v1"
stagingEndpoint = "https://staging-log-api.newrelic.com/log/v1"
logRecordModifierSource = "nri-agent"
Expand Down Expand Up @@ -751,6 +752,10 @@ func newNROutput(cfg *config.LogForward) FBCfgOutput {
ret.Endpoint = euEndpoint
}

if license.IsRegionJP(cfg.License) {
ret.Endpoint = jpEndpoint
}

return ret
}

Expand Down
33 changes: 33 additions & 0 deletions pkg/integrations/v4/logs/cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ func withFeedramp(cfg config.LogForward) config.LogForward {
return cfg
}

func withJPLicense(cfg config.LogForward) config.LogForward {
cfg.License = "jp01xx6789012345678901234567890123456789"

return cfg
}

var outputBlock = FBCfgOutput{
Name: "newrelic",
Match: "*",
Expand All @@ -78,6 +84,9 @@ var outputBlock = FBCfgOutput{
func TestNewFBConf(t *testing.T) {
outputBlockFedramp := outputBlock
outputBlockFedramp.Endpoint = fedrampEndpoint
outputBlockJP := outputBlock
outputBlockJP.LicenseKey = "jp01xx6789012345678901234567890123456789"
outputBlockJP.Endpoint = jpEndpoint
outputBlockMultipleRetries := outputBlock

logFwdCfgMultipleRetries := logFwdCfg
Expand Down Expand Up @@ -171,6 +180,30 @@ func TestNewFBConf(t *testing.T) {
},
Output: outputBlockFedramp,
}},
{"single input jp", withJPLicense(logFwdCfg), LogsCfg{
{
Name: "log-file",
File: "file.path",
},
}, FBCfg{
Inputs: []FBCfgInput{
{
Name: "tail",
Tag: "log-file",
DB: dbDbPath,
Path: "file.path",
BufferMaxSize: "128k",
MemBufferLimit: "16384k",
SkipLongLines: "On",
PathKey: "filePath",
},
},
Filters: []FBCfgFilter{
inputRecordModifier("tail", "log-file"),
filterEntityBlock,
},
Output: outputBlockJP,
}},
{"input file + filter", logFwdCfg, LogsCfg{
{
Name: "log-file",
Expand Down
11 changes: 10 additions & 1 deletion pkg/license/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,22 @@ func IsValid(licenseKey string) bool {
// IsRegionEU returns true if license region is EU.
func IsRegionEU(license string) bool {
r := GetRegion(license)
// only EU supported
if len(r) > 1 && r[:2] == "eu" {
return true
}
return false
}

// IsRegionJP returns true if license region is JP.
func IsRegionJP(license string) bool {
r := GetRegion(license)
if len(r) > 1 && r[:2] == "jp" {
return true
}

return false
}

// IsFederalCompliance returns true if license is from federal customer.
func IsFederalCompliance(licenseKey string) bool {
r := GetRegion(licenseKey)
Expand Down
21 changes: 17 additions & 4 deletions pkg/license/license_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,32 @@
package license

import (
"gotest.tools/assert"
"testing"

"gotest.tools/assert"
)

const (
basic = "0123456789012345678901234567890123456789"
eu = "eu01xx6789012345678901234567890123456789"
basic = "0123456789012345678901234567890123456789"
euLicense = "eu01xx6789012345678901234567890123456789"
jpLicense = "jp01xx6789012345678901234567890123456789"
)

func TestLicense_GetRegion(t *testing.T) {
region := GetRegion(basic)
assert.Equal(t, region, "")

region = GetRegion(eu)
region = GetRegion(euLicense)
assert.Equal(t, region, "eu")

region = GetRegion(jpLicense)
assert.Equal(t, region, "jp")
}

func TestLicense_IsRegionJP(t *testing.T) {
t.Parallel()

assert.Equal(t, IsRegionJP(jpLicense), true)
assert.Equal(t, IsRegionJP(euLicense), false)
assert.Equal(t, IsRegionJP(basic), false)
}
Loading