Skip to content

Commit

Permalink
Merge branch 'main' into task/dw-beta-badge-sentinel-one-8526
Browse files Browse the repository at this point in the history
  • Loading branch information
ashokaditya authored Feb 12, 2024
2 parents 3e32ee3 + a515c2e commit a6dad82
Show file tree
Hide file tree
Showing 114 changed files with 3,119 additions and 1,437 deletions.
2 changes: 1 addition & 1 deletion .buildkite/pipelines/code_coverage/daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ steps:
depends_on:
- jest
- jest-integration
timeout_in_minutes: 30
timeout_in_minutes: 50
key: ingest
18 changes: 9 additions & 9 deletions .buildkite/scripts/common/activate_service_account.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ set -euo pipefail

source "$(dirname "${BASH_SOURCE[0]}")/vault_fns.sh"

BUCKET_OR_EMAIL="${1:-}"
CALL_ARGUMENT="${1:-}"
GCLOUD_EMAIL_POSTFIX="elastic-kibana-ci.iam.gserviceaccount.com"
GCLOUD_SA_PROXY_EMAIL="kibana-ci-sa-proxy@$GCLOUD_EMAIL_POSTFIX"

if [[ -z "$BUCKET_OR_EMAIL" ]]; then
if [[ -z "$CALL_ARGUMENT" ]]; then
echo "Usage: $0 <bucket_name|email>"
exit 1
elif [[ "$BUCKET_OR_EMAIL" == "--unset-impersonation" ]]; then
elif [[ "$CALL_ARGUMENT" == "--unset-impersonation" ]]; then
echo "Unsetting impersonation"
gcloud config unset auth/impersonate_service_account
exit 0
elif [[ "$BUCKET_OR_EMAIL" == "--logout-gcloud" ]]; then
elif [[ "$CALL_ARGUMENT" == "--logout-gcloud" ]]; then
echo "Logging out of gcloud"
if [[ -x "$(command -v gcloud)" ]] && [[ "$(gcloud auth list 2>/dev/null | grep $GCLOUD_SA_PROXY_EMAIL)" != "" ]]; then
gcloud auth revoke $GCLOUD_SA_PROXY_EMAIL --no-user-output-enabled
Expand Down Expand Up @@ -48,12 +48,12 @@ fi

# Check if the arg is a service account e-mail or a bucket name
EMAIL=""
if [[ "$BUCKET_OR_EMAIL" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
EMAIL="$BUCKET_OR_EMAIL"
elif [[ "$BUCKET_OR_EMAIL" =~ ^gs://* ]]; then
BUCKET_NAME="${BUCKET_OR_EMAIL:5}"
if [[ "$CALL_ARGUMENT" =~ ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ ]]; then
EMAIL="$CALL_ARGUMENT"
elif [[ "$CALL_ARGUMENT" =~ ^gs://* ]]; then
BUCKET_NAME="${CALL_ARGUMENT:5}"
else
BUCKET_NAME="$BUCKET_OR_EMAIL"
BUCKET_NAME="$CALL_ARGUMENT"
fi

if [[ -z "$EMAIL" ]]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ gsutil -m cp -r gs://elastic-bekitzur-kibana-coverage-live/previous_pointer/prev
# TODO: Activate after the above is removed
#.buildkite/scripts/common/activate_service_account.sh gs://elastic-kibana-coverage-live
#gsutil -m cp -r gs://elastic-kibana-coverage-live/previous_pointer/previous.txt . || echo "### Previous Pointer NOT FOUND?"
#.buildkite/scripts/common/activate_service_account.sh --unset-impersonation

if [ -e ./previous.txt ]; then
mv previous.txt downloaded_previous.txt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ gsutil cp previous.txt gs://elastic-bekitzur-kibana-coverage-live/previous_point

.buildkite/scripts/common/activate_service_account.sh gs://elastic-kibana-coverage-live
gsutil cp previous.txt gs://elastic-kibana-coverage-live/previous_pointer/
.buildkite/scripts/common/activate_service_account.sh --unset-impersonation
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,40 @@ set -euo pipefail

xs=("$@")

# TODO: Safe to remove this after 2024-03-01 (https://github.com/elastic/kibana/issues/175904) - also clean up usages
# TODO: Safe to remove this block after 2024-03-01 (https://github.com/elastic/kibana/issues/175904) - also clean up usages
echo "--- Uploading static site (legacy)"
uploadPrefix_old="gs://elastic-bekitzur-kibana-coverage-live/"
uploadPrefixWithTimeStamp_old="${uploadPrefix_old}${TIME_STAMP}/"
uploadBase_old() {
for x in 'src/dev/code_coverage/www/index.html' 'src/dev/code_coverage/www/404.html'; do
gsutil -m -q cp -r -a public-read -z js,css,html "${x}" "${uploadPrefix_old}"
done
}
uploadRest_old() {
for x in "${xs[@]}"; do
gsutil -m -q cp -r -a public-read -z js,css,html "target/kibana-coverage/${x}-combined" "${uploadPrefixWithTimeStamp_old}"
done
}
.buildkite/scripts/common/activate_service_account.sh --logout-gcloud
uploadBase_old
uploadRest_old

echo "--- Uploading static site"
uploadPrefix="gs://elastic-kibana-coverage-live/"
uploadPrefixWithTimeStamp="${uploadPrefix}${TIME_STAMP}/"

uploadBase() {
for x in 'src/dev/code_coverage/www/index.html' 'src/dev/code_coverage/www/404.html'; do
gsutil -m -q cp -r -z js,css,html "${x}" "${uploadPrefix}"
gsutil -m -q cp -r -a public-read -z js,css,html "${x}" "${uploadPrefix_old}"
done
}

uploadRest() {
for x in "${xs[@]}"; do
gsutil -m -q cp -r -z js,css,html "target/kibana-coverage/${x}-combined" "${uploadPrefixWithTimeStamp}"
gsutil -m -q cp -r -a public-read -z js,css,html "target/kibana-coverage/${x}-combined" "${uploadPrefixWithTimeStamp_old}"
done
}

echo "--- Uploading static site"

.buildkite/scripts/common/activate_service_account.sh gs://elastic-kibana-coverage-live
uploadBase
uploadRest
.buildkite/scripts/common/activate_service_account.sh --unset-impersonation
4 changes: 4 additions & 0 deletions config/kibana.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
# - name: metrics.ops
# level: debug

# Enables debug logging on the browser (dev console)
#logging.browser.root:
# level: debug

# =================== System: Other ===================
# The path where Kibana stores persistent data not saved in Elasticsearch. Defaults to data
#path.data: data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,9 @@ export class AnalyticsClient implements IAnalyticsClient {
properties: eventData as unknown as Record<string, unknown>,
};

// debug-logging before checking the opt-in status to help during development
if (this.initContext.isDev) {
this.initContext.logger.debug<EventDebugLogMeta>(`Report event "${eventType}"`, {
ebt_event: event,
});
}
this.initContext.logger.debug<EventDebugLogMeta>(`Report event "${eventType}"`, {
ebt_event: event,
});

const optInConfig = this.optInConfig$.value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { PluginName, DiscoveredPlugin } from '@kbn/core-base-common';
import type { ThemeVersion } from '@kbn/ui-shared-deps-npm';
import type { EnvironmentMode, PackageInfo } from '@kbn/config';
import type { CustomBranding } from '@kbn/core-custom-branding-common';
import type { BrowserLoggingConfig } from '@kbn/core-logging-common-internal';

/** @internal */
export interface InjectedMetadataClusterInfo {
Expand Down Expand Up @@ -45,6 +46,7 @@ export interface InjectedMetadata {
publicBaseUrl?: string;
assetsHrefBase: string;
clusterInfo: InjectedMetadataClusterInfo;
logging: BrowserLoggingConfig;
env: {
mode: EnvironmentMode;
packageInfo: PackageInfo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"@kbn/config",
"@kbn/ui-shared-deps-npm",
"@kbn/core-base-common",
"@kbn/core-custom-branding-common"
"@kbn/core-custom-branding-common",
"@kbn/core-logging-common-internal"
],
"exclude": [
"target/**/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,29 @@
* Side Public License, v 1.
*/

import type { BrowserLoggingConfig } from '@kbn/core-logging-common-internal';
import { unsafeConsole } from '@kbn/security-hardening';
import { BrowserLoggingSystem } from './logging_system';

describe('', () => {
describe('BrowserLoggingSystem', () => {
const timestamp = new Date(Date.UTC(2012, 1, 1, 14, 33, 22, 11));

let mockConsoleLog: jest.SpyInstance;
let loggingSystem: BrowserLoggingSystem;

const createLoggingConfig = (parts: Partial<BrowserLoggingConfig> = {}): BrowserLoggingConfig => {
return {
root: {
level: 'warn',
},
...parts,
};
};

beforeEach(() => {
mockConsoleLog = jest.spyOn(unsafeConsole, 'log').mockReturnValue(undefined);
jest.spyOn<any, any>(global, 'Date').mockImplementation(() => timestamp);
loggingSystem = new BrowserLoggingSystem({ logLevel: 'warn' });
loggingSystem = new BrowserLoggingSystem(createLoggingConfig());
});

afterEach(() => {
Expand Down Expand Up @@ -74,5 +84,37 @@ describe('', () => {
]
`);
});

it('allows to override the root logger level', () => {
loggingSystem = new BrowserLoggingSystem(createLoggingConfig({ root: { level: 'debug' } }));

const logger = loggingSystem.get('foo.bar');
logger.trace('some trace message');
logger.debug('some debug message');
logger.info('some info message');
logger.warn('some warn message');
logger.error('some error message');
logger.fatal('some fatal message');

expect(mockConsoleLog.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"[2012-01-31T13:33:22.011-05:00][DEBUG][foo.bar] some debug message",
],
Array [
"[2012-01-31T08:33:22.011-05:00][INFO ][foo.bar] some info message",
],
Array [
"[2012-01-31T03:33:22.011-05:00][WARN ][foo.bar] some warn message",
],
Array [
"[2012-01-30T22:33:22.011-05:00][ERROR][foo.bar] some error message",
],
Array [
"[2012-01-30T17:33:22.011-05:00][FATAL][foo.bar] some fatal message",
],
]
`);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@
* Side Public License, v 1.
*/

import { LogLevel, Logger, LoggerFactory, LogLevelId, DisposableAppender } from '@kbn/logging';
import { getLoggerContext } from '@kbn/core-logging-common-internal';
import { LogLevel, Logger, LoggerFactory, DisposableAppender } from '@kbn/logging';
import { getLoggerContext, BrowserLoggingConfig } from '@kbn/core-logging-common-internal';
import type { LoggerConfigType } from './types';
import { BaseLogger } from './logger';
import { PatternLayout } from './layouts';
import { ConsoleAppender } from './appenders';

export interface BrowserLoggingConfig {
logLevel: LogLevelId;
}

const CONSOLE_APPENDER_ID = 'console';

/**
Expand Down Expand Up @@ -54,7 +50,7 @@ export class BrowserLoggingSystem implements IBrowserLoggingSystem {

private getLoggerConfigByContext(context: string): LoggerConfigType {
return {
level: this.loggingConfig.logLevel,
level: this.loggingConfig.root.level,
appenders: [CONSOLE_APPENDER_ID],
name: context,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export {
ROOT_CONTEXT_NAME,
DEFAULT_APPENDER_NAME,
} from './src';
export type { BrowserLoggingConfig, BrowserRootLoggerConfig } from './src/browser_config';
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import type { LogLevelId } from '@kbn/logging';

/**
* @internal
*/
export interface BrowserLoggingConfig {
root: BrowserRootLoggerConfig;
}

/**
* @internal
*/
export interface BrowserRootLoggerConfig {
level: LogLevelId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
export { config } from './src/logging_config';
export type {
LoggingConfigType,
LoggingConfigWithBrowserType,
loggerContextConfigSchema,
loggerSchema,
} from './src/logging_config';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ test('`schema` creates correct schema with defaults.', () => {
expect(config.schema.validate({})).toMatchInlineSnapshot(`
Object {
"appenders": Map {},
"browser": Object {
"root": Object {
"level": "info",
},
},
"loggers": Array [],
"root": Object {
"appenders": Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export const loggerSchema = schema.object({
level: levelSchema,
});

const browserConfig = schema.object({
root: schema.object({
level: levelSchema,
}),
});

export const config = {
path: 'logging',
schema: schema.object({
Expand All @@ -63,6 +69,7 @@ export const config = {
}),
level: levelSchema,
}),
browser: browserConfig,
}),
};

Expand All @@ -71,6 +78,10 @@ export type LoggingConfigType = Pick<TypeOf<typeof config.schema>, 'loggers' | '
appenders: Map<string, AppenderConfigType>;
};

/** @internal */
export type LoggingConfigWithBrowserType = LoggingConfigType &
Pick<TypeOf<typeof config.schema>, 'browser'>;

/**
* Config schema for validating the inputs to the {@link LoggingServiceStart.configure} API.
* See {@link LoggerContextConfigType}.
Expand Down
Loading

0 comments on commit a6dad82

Please sign in to comment.