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

♻️[RUMF-471] rename version #382

Merged
merged 3 commits into from
Apr 29, 2020
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
8 changes: 4 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ deploy-staging:
image: $CI_IMAGE
script:
- yarn
- TARGET_DATACENTER=eu TARGET_ENV=staging VERSION=staging yarn build:bundle
- TARGET_DATACENTER=eu TARGET_ENV=staging BUILD_MODE=staging yarn build:bundle
- ./scripts/deploy.sh staging eu
- TARGET_DATACENTER=us TARGET_ENV=staging VERSION=staging yarn build:bundle
- TARGET_DATACENTER=us TARGET_ENV=staging BUILD_MODE=staging yarn build:bundle
- ./scripts/deploy.sh staging us

deploy-release:
Expand All @@ -168,9 +168,9 @@ deploy-release:
image: $CI_IMAGE
script:
- yarn
- TARGET_DATACENTER=us TARGET_ENV=production VERSION=release yarn build:bundle
- TARGET_DATACENTER=us TARGET_ENV=production BUILD_MODE=release yarn build:bundle
- ./scripts/deploy.sh prod us
- TARGET_DATACENTER=eu TARGET_ENV=production VERSION=release yarn build:bundle
- TARGET_DATACENTER=eu TARGET_ENV=production BUILD_MODE=release yarn build:bundle
- ./scripts/deploy.sh prod eu

########################################################################################################################
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
"dev": "ENV=development node test/server/server.js",
"release": "lerna version --exact",
"version": "node ./scripts/generate-changelog.js",
"publish:npm": "TARGET_DATACENTER=us TARGET_ENV=production VERSION=release yarn build && lerna publish from-package",
"publish:npm": "TARGET_DATACENTER=us TARGET_ENV=production BUILD_MODE=release yarn build && lerna publish from-package",
"fail": "./scripts/fail.sh",
"test": "yarn test:unit",
"test:unit": "karma start ./test/unit/karma.local.conf.js",
"test:unit:bs": "node ./scripts/bs-wrapper.js karma start test/unit/karma.bs.conf.js",
"test:e2e": "yarn run test:e2e:bundle",
"test:e2e:bundle": "TARGET_ENV=e2e-test yarn build && E2E_MODE=bundle wdio test/e2e/wdio.local.conf.js",
"test:e2e:npm": "TARGET_ENV=e2e-test yarn build && (cd test/app && rm -rf node_modules && yarn && yarn build) && E2E_MODE=npm wdio test/e2e/wdio.local.conf.js",
"test:e2e:async": "TARGET_ENV=e2e-test yarn build && E2E_MODE=async wdio test/e2e/wdio.local.conf.js",
"test:e2e:bs": "TARGET_ENV=e2e-test yarn build && node ./scripts/bs-wrapper.js wdio test/e2e/wdio.bs.conf.js",
"test:e2e:bundle": "BUILD_MODE=e2e-test yarn build && E2E_MODE=bundle wdio test/e2e/wdio.local.conf.js",
"test:e2e:npm": "BUILD_MODE=e2e-test yarn build && (cd test/app && rm -rf node_modules && yarn && yarn build) && E2E_MODE=npm wdio test/e2e/wdio.local.conf.js",
"test:e2e:async": "BUILD_MODE=e2e-test yarn build && E2E_MODE=async wdio test/e2e/wdio.local.conf.js",
"test:e2e:bs": "BUILD_MODE=e2e-test yarn build && node ./scripts/bs-wrapper.js wdio test/e2e/wdio.bs.conf.js",
"test:compat:tsc": "yarn build && (cd test/app && rm -rf node_modules && yarn && yarn compat:tsc) || yarn fail 'typescript 3.0 compatibility broken'",
"test:compat:ssr": "yarn build && (cd test/app && rm -rf node_modules && yarn && yarn compat:ssr) || yarn fail 'server side rendering compatibility broken'"
},
Expand Down
14 changes: 8 additions & 6 deletions packages/core/src/configuration.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BuildEnv, Datacenter, Environment } from './init'
import { BuildEnv, BuildMode, Datacenter, Environment } from './init'
import { includes, ONE_KILO_BYTE, ONE_SECOND } from './utils'

export const DEFAULT_CONFIGURATION = {
Expand Down Expand Up @@ -45,7 +45,7 @@ export interface UserConfiguration {
silentMultipleInit?: boolean
proxyHost?: string

// Below is only taken into account for e2e-test bundle.
// Below is only taken into account for e2e-test build mode.
internalMonitoringEndpoint?: string
logsEndpoint?: string
rumEndpoint?: string
Expand All @@ -64,17 +64,19 @@ interface TransportConfiguration {
clientToken: string
datacenter: Datacenter
env: Environment
version: string
buildMode: BuildMode
sdkVersion: string
proxyHost?: string
}

export function buildConfiguration(userConfiguration: UserConfiguration, buildEnv: BuildEnv): Configuration {
const transportConfiguration: TransportConfiguration = {
buildMode: buildEnv.buildMode,
clientToken: userConfiguration.clientToken,
datacenter: userConfiguration.datacenter || buildEnv.datacenter,
env: buildEnv.env,
proxyHost: userConfiguration.proxyHost,
version: buildEnv.version,
sdkVersion: buildEnv.sdkVersion,
}

const enableExperimentalFeatures = Array.isArray(userConfiguration.enableExperimentalFeatures)
Expand Down Expand Up @@ -110,7 +112,7 @@ export function buildConfiguration(userConfiguration: UserConfiguration, buildEn
configuration.resourceSampleRate = userConfiguration.resourceSampleRate!
}

if (transportConfiguration.env === 'e2e-test') {
if (transportConfiguration.buildMode === 'e2e-test') {
if (userConfiguration.internalMonitoringEndpoint !== undefined) {
configuration.internalMonitoringEndpoint = userConfiguration.internalMonitoringEndpoint
}
Expand All @@ -128,7 +130,7 @@ export function buildConfiguration(userConfiguration: UserConfiguration, buildEn
function getEndpoint(type: string, conf: TransportConfiguration, source?: string) {
const tld = conf.datacenter === 'us' ? 'com' : 'eu'
const domain = conf.env === 'production' ? `datadoghq.${tld}` : `datad0g.${tld}`
const tags = `version:${conf.version}`
const tags = `sdk_version:${conf.sdkVersion}`
const datadogHost = `${type}-http-intake.logs.${domain}`
const host = conf.proxyHost ? conf.proxyHost : datadogHost
const proxyParameter = conf.proxyHost ? `ddhost=${datadogHost}&` : ''
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ export function makeGlobal<T>(stub: T): T {
}

export type Datacenter = 'eu' | 'us'
export type Environment = 'production' | 'staging' | 'e2e-test'
export type Environment = 'production' | 'staging'
export type BuildMode = 'release' | 'staging' | 'e2e-test'

export interface BuildEnv {
datacenter: Datacenter
env: Environment
version: string
buildMode: BuildMode
sdkVersion: string
}

export function commonInit(userConfiguration: UserConfiguration, buildEnv: BuildEnv) {
Expand Down
10 changes: 6 additions & 4 deletions packages/core/test/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { buildConfiguration } from '../src/configuration'
describe('configuration', () => {
const clientToken = 'some_client_token'
const prodEnv = {
buildMode: 'release' as 'release',
datacenter: 'us' as 'us',
env: 'production' as 'production',
version: 'some_version',
sdkVersion: 'some_version',
}

describe('internal monitoring endpoint', () => {
Expand All @@ -30,12 +31,13 @@ describe('configuration', () => {
expect(configuration.internalMonitoringEndpoint).not.toEqual(endpoint)
})

it('should be available for e2e-test env', () => {
it('should be available for e2e-test build mode', () => {
const endpoint = 'bbbbbbbbbbbbbbb'
const e2eEnv = {
buildMode: 'e2e-test' as 'e2e-test',
datacenter: 'us' as 'us',
env: 'e2e-test' as 'e2e-test',
version: 'some_version',
env: 'staging' as 'staging',
sdkVersion: 'some_version',
}
const configuration = buildConfiguration(
{ clientToken, rumEndpoint: endpoint, logsEndpoint: endpoint, internalMonitoringEndpoint: endpoint },
Expand Down
3 changes: 2 additions & 1 deletion packages/logs/src/buildEnv.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { BuildEnv, Datacenter, Environment } from '@datadog/browser-core'

export const buildEnv: BuildEnv = {
buildMode: '<<< BUILD_MODE >>>' as BuildEnv['buildMode'],
datacenter: '<<< TARGET_DATACENTER >>>' as Datacenter,
env: '<<< TARGET_ENV >>>' as Environment,
version: '<<< VERSION >>>',
sdkVersion: '<<< SDK_VERSION >>>',
}
3 changes: 2 additions & 1 deletion packages/rum/src/buildEnv.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { BuildEnv } from '@datadog/browser-core'

export const buildEnv: BuildEnv = {
buildMode: '<<< BUILD_MODE >>>' as BuildEnv['buildMode'],
datacenter: '<<< TARGET_DATACENTER >>>' as BuildEnv['datacenter'],
env: '<<< TARGET_ENV >>>' as BuildEnv['env'],
version: '<<< VERSION >>>',
sdkVersion: '<<< SDK_VERSION >>>',
}
13 changes: 7 additions & 6 deletions scripts/build-env.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
const execSync = require('child_process').execSync
const lernaJson = require('../lerna.json')

let version
switch (process.env.VERSION) {
let sdkVersion
switch (process.env.BUILD_MODE) {
case 'release':
version = lernaJson.version
sdkVersion = lernaJson.version
break
case 'staging':
const commitSha1 = execSync('git rev-parse HEAD')
.toString()
.trim()
version = `${lernaJson.version}+${commitSha1}`
sdkVersion = `${lernaJson.version}+${commitSha1}`
break
default:
version = 'dev'
sdkVersion = 'dev'
break
}

module.exports = {
TARGET_DATACENTER: process.env.TARGET_DATACENTER || 'us',
TARGET_ENV: process.env.TARGET_ENV || 'staging',
VERSION: version,
BUILD_MODE: process.env.BUILD_MODE,
SDK_VERSION: sdkVersion,
}
2 changes: 1 addition & 1 deletion scripts/replace-build-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const buildEnv = require('./build-env')
/**
* Replace BuildEnv in build files
* Usage:
* TARGET_DATACENTER=xxx TARGET_ENV=yyy VERSION=zzz node replace-build-env.js /path/to/build/directory
* TARGET_DATACENTER=xxx TARGET_ENV=yyy BUILD_MODE=zzz node replace-build-env.js /path/to/build/directory
*/

const buildDirectory = process.argv[2]
Expand Down