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

[7.x] [Ingest Management] main branch uses epr-snapshot. Others production (#73555) #74122

Merged
merged 1 commit into from
Aug 3, 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
1 change: 0 additions & 1 deletion x-pack/plugins/ingest_manager/common/constants/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

export const PACKAGES_SAVED_OBJECT_TYPE = 'epm-packages';
export const INDEX_PATTERN_SAVED_OBJECT_TYPE = 'index-pattern';
export const DEFAULT_REGISTRY_URL = 'https://epr.elastic.co';
export const INDEX_PATTERN_PLACEHOLDER_SUFFIX = '-index_pattern_placeholder';
1 change: 0 additions & 1 deletion x-pack/plugins/ingest_manager/server/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,4 @@ export {
// Defaults
DEFAULT_AGENT_CONFIG,
DEFAULT_OUTPUT,
DEFAULT_REGISTRY_URL,
} from '../../common';
2 changes: 1 addition & 1 deletion x-pack/plugins/ingest_manager/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { schema, TypeOf } from '@kbn/config-schema';
import { PluginInitializerContext } from 'src/core/server';
import { IngestManagerPlugin } from './plugin';
export { AgentService, ESIndexPatternService } from './services';
export { AgentService, ESIndexPatternService, getRegistryUrl } from './services';
export {
IngestManagerSetupContract,
IngestManagerSetupDeps,
Expand Down
12 changes: 6 additions & 6 deletions x-pack/plugins/ingest_manager/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ export interface IngestManagerAppContext {
security?: SecurityPluginSetup;
config$?: Observable<IngestManagerConfigType>;
savedObjects: SavedObjectsServiceStart;
isProductionMode: boolean;
kibanaVersion: string;
kibanaBranch: string;
isProductionMode: PluginInitializerContext['env']['mode']['prod'];
kibanaVersion: PluginInitializerContext['env']['packageInfo']['version'];
kibanaBranch: PluginInitializerContext['env']['packageInfo']['branch'];
cloud?: CloudSetup;
logger?: Logger;
httpSetup?: HttpServiceSetup;
Expand Down Expand Up @@ -144,9 +144,9 @@ export class IngestManagerPlugin
private cloud: CloudSetup | undefined;
private logger: Logger | undefined;

private isProductionMode: boolean;
private kibanaVersion: string;
private kibanaBranch: string;
private isProductionMode: IngestManagerAppContext['isProductionMode'];
private kibanaVersion: IngestManagerAppContext['kibanaVersion'];
private kibanaBranch: IngestManagerAppContext['kibanaBranch'];
private httpSetup: HttpServiceSetup | undefined;
private encryptedSavedObjectsSetup: EncryptedSavedObjectsPluginSetup | undefined;

Expand Down
13 changes: 4 additions & 9 deletions x-pack/plugins/ingest_manager/server/services/app_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
EncryptedSavedObjectsClient,
EncryptedSavedObjectsPluginSetup,
} from '../../../encrypted_saved_objects/server';
import packageJSON from '../../../../../package.json';
import { SecurityPluginSetup } from '../../../security/server';
import { IngestManagerConfigType } from '../../common';
import { ExternalCallback, ExternalCallbacksStorage, IngestManagerAppContext } from '../plugin';
Expand All @@ -22,9 +23,9 @@ class AppContextService {
private config$?: Observable<IngestManagerConfigType>;
private configSubject$?: BehaviorSubject<IngestManagerConfigType>;
private savedObjects: SavedObjectsServiceStart | undefined;
private isProductionMode: boolean = false;
private kibanaVersion: string | undefined;
private kibanaBranch: string | undefined;
private isProductionMode: IngestManagerAppContext['isProductionMode'] = false;
private kibanaVersion: IngestManagerAppContext['kibanaVersion'] = packageJSON.version;
private kibanaBranch: IngestManagerAppContext['kibanaBranch'] = packageJSON.branch;
private cloud?: CloudSetup;
private logger: Logger | undefined;
private httpSetup?: HttpServiceSetup;
Expand Down Expand Up @@ -121,16 +122,10 @@ class AppContextService {
}

public getKibanaVersion() {
if (!this.kibanaVersion) {
throw new Error('Kibana version is not set.');
}
return this.kibanaVersion;
}

public getKibanaBranch() {
if (!this.kibanaBranch) {
throw new Error('Kibana branch is not set.');
}
return this.kibanaBranch;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,43 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { DEFAULT_REGISTRY_URL } from '../../../constants';
import { appContextService, licenseService } from '../../';

// from https://github.com/elastic/package-registry#docker (maybe from OpenAPI one day)
// the unused variables cause a TS warning about unused values
// chose to comment them out vs @ts-ignore or @ts-expect-error on each line

const PRODUCTION_REGISTRY_URL_CDN = 'https://epr.elastic.co';
// const STAGING_REGISTRY_URL_CDN = 'https://epr-staging.elastic.co';
// const EXPERIMENTAL_REGISTRY_URL_CDN = 'https://epr-experimental.elastic.co/';
const SNAPSHOT_REGISTRY_URL_CDN = 'https://epr-snapshot.elastic.co';

// const PRODUCTION_REGISTRY_URL_NO_CDN = 'https://epr.ea-web.elastic.dev';
// const STAGING_REGISTRY_URL_NO_CDN = 'https://epr-staging.ea-web.elastic.dev';
// const EXPERIMENTAL_REGISTRY_URL_NO_CDN = 'https://epr-experimental.ea-web.elastic.dev/';
// const SNAPSHOT_REGISTRY_URL_NO_CDN = 'https://epr-snapshot.ea-web.elastic.dev';

const getDefaultRegistryUrl = (): string => {
const branch = appContextService.getKibanaBranch();
if (branch === 'master') {
return SNAPSHOT_REGISTRY_URL_CDN;
} else {
return PRODUCTION_REGISTRY_URL_CDN;
}
};

export const getRegistryUrl = (): string => {
const license = licenseService.getLicenseInformation();
const customUrl = appContextService.getConfig()?.registryUrl;
const isGoldPlus = license?.isAvailable && license?.isActive && license?.hasAtLeast('gold');

if (
customUrl &&
license &&
license.isAvailable &&
license.hasAtLeast('gold') &&
license.isActive
) {
if (customUrl && isGoldPlus) {
return customUrl;
}

if (customUrl) {
appContextService.getLogger().warn('Gold license is required to use a custom registry url.');
}

return DEFAULT_REGISTRY_URL;
return getDefaultRegistryUrl();
};
2 changes: 2 additions & 0 deletions x-pack/plugins/ingest_manager/server/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import * as settingsService from './settings';

export { ESIndexPatternSavedObjectService } from './es_index_pattern';

export { getRegistryUrl } from './epm/registry/registry_url';

/**
* Service to return the index pattern of EPM packages
*/
Expand Down
6 changes: 3 additions & 3 deletions x-pack/test/security_solution_endpoint/apps/endpoint/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { DEFAULT_REGISTRY_URL } from '../../../../plugins/ingest_manager/common';
import { getRegistryUrl as getRegistryUrlFromIngest } from '../../../../plugins/ingest_manager/server';
import { FtrProviderContext } from '../../ftr_provider_context';
import {
isRegistryEnabled,
getRegistryUrl,
getRegistryUrlFromTestEnv,
} from '../../../security_solution_endpoint_api_int/registry';

export default function (providerContext: FtrProviderContext) {
Expand All @@ -22,7 +22,7 @@ export default function (providerContext: FtrProviderContext) {
log.warning('These tests are being run with an external package registry');
}

const registryUrl = getRegistryUrl() ?? DEFAULT_REGISTRY_URL;
const registryUrl = getRegistryUrlFromTestEnv() ?? getRegistryUrlFromIngest();
log.info(`Package registry URL for tests: ${registryUrl}`);

before(async () => {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/test/security_solution_endpoint_api_int/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { FtrProviderContext } from '../ftr_provider_context';
import { isRegistryEnabled, getRegistryUrl } from '../registry';
import { DEFAULT_REGISTRY_URL } from '../../../plugins/ingest_manager/common';
import { isRegistryEnabled, getRegistryUrlFromTestEnv } from '../registry';
import { getRegistryUrl as getRegistryUrlFromIngest } from '../../../plugins/ingest_manager/server';

export default function endpointAPIIntegrationTests(providerContext: FtrProviderContext) {
const { loadTestFile, getService } = providerContext;
Expand All @@ -20,7 +20,7 @@ export default function endpointAPIIntegrationTests(providerContext: FtrProvider
log.warning('These tests are being run with an external package registry');
}

const registryUrl = getRegistryUrl() ?? DEFAULT_REGISTRY_URL;
const registryUrl = getRegistryUrlFromTestEnv() ?? getRegistryUrlFromIngest();
log.info(`Package registry URL for tests: ${registryUrl}`);

before(async () => {
Expand Down
6 changes: 3 additions & 3 deletions x-pack/test/security_solution_endpoint_api_int/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function createEndpointDockerConfig(
});
}

export function getRegistryUrl(): string | undefined {
export function getRegistryUrlFromTestEnv(): string | undefined {
let registryUrl: string | undefined;
if (dockerRegistryPort !== undefined) {
registryUrl = `--xpack.ingestManager.registryUrl=http://localhost:${dockerRegistryPort}`;
Expand All @@ -68,10 +68,10 @@ export function getRegistryUrl(): string | undefined {
}

export function getRegistryUrlAsArray(): string[] {
const registryUrl: string | undefined = getRegistryUrl();
const registryUrl: string | undefined = getRegistryUrlFromTestEnv();
return registryUrl !== undefined ? [registryUrl] : [];
}

export function isRegistryEnabled() {
return getRegistryUrl() !== undefined;
return getRegistryUrlFromTestEnv() !== undefined;
}