diff --git a/pkg/config/config.go b/pkg/config/config.go index c0694da82..b3506d696 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -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 } @@ -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 } @@ -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 } @@ -2132,6 +2152,10 @@ func urlRegionPrefix(licenseKey string) string { return "eu." } + if license.IsRegionJP(licenseKey) { + return "jp." + } + return "" } diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index 3dbf60dd6..466c5e9d2 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -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}, } @@ -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", @@ -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 @@ -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 diff --git a/pkg/config/defaults.go b/pkg/config/defaults.go index be6a21706..e6541f215 100644 --- a/pkg/config/defaults.go +++ b/pkg/config/defaults.go @@ -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" @@ -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" ) diff --git a/pkg/integrations/v4/logs/cfg.go b/pkg/integrations/v4/logs/cfg.go index c3ab2ce0a..6659d3851 100644 --- a/pkg/integrations/v4/logs/cfg.go +++ b/pkg/integrations/v4/logs/cfg.go @@ -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" @@ -751,6 +752,10 @@ func newNROutput(cfg *config.LogForward) FBCfgOutput { ret.Endpoint = euEndpoint } + if license.IsRegionJP(cfg.License) { + ret.Endpoint = jpEndpoint + } + return ret } diff --git a/pkg/integrations/v4/logs/cfg_test.go b/pkg/integrations/v4/logs/cfg_test.go index a85d6f36b..efed48bb0 100644 --- a/pkg/integrations/v4/logs/cfg_test.go +++ b/pkg/integrations/v4/logs/cfg_test.go @@ -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: "*", @@ -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 @@ -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", diff --git a/pkg/license/license.go b/pkg/license/license.go index 1af873069..06a1387a1 100644 --- a/pkg/license/license.go +++ b/pkg/license/license.go @@ -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) diff --git a/pkg/license/license_test.go b/pkg/license/license_test.go index 93700abc3..acc39be0f 100644 --- a/pkg/license/license_test.go +++ b/pkg/license/license_test.go @@ -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) }