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

Reduce number of logs #947

Merged
merged 1 commit into from
Oct 24, 2023
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
4 changes: 1 addition & 3 deletions .deps/dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
| [`@types/lodash@4.14.197`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #4131 |
| [`@types/minimatch@3.0.5`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | clearlydefined |
| [`@types/minimist@1.2.2`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #10839 |
| [`@types/node-fetch@2.6.4`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | clearlydefined |
| [`@types/node-fetch@2.6.4`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #11004 |
| [`@types/normalize-package-data@2.4.1`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #10792 |
| [`@types/parse-json@4.0.0`](https://www.github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | clearlydefined |
| [`@types/qs@6.9.7`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | clearlydefined |
Expand Down Expand Up @@ -308,7 +308,6 @@
| [`color-name@1.1.4`](git@github.com:colorjs/color-name.git) | MIT | clearlydefined |
| [`color-support@1.1.3`](git+https://github.com/isaacs/color-support.git) | ISC | clearlydefined |
| [`colord@2.9.3`](https://github.com/omgovich/colord.git) | MIT | clearlydefined |
| [`colorette@2.0.20`](https://github.com/jorgebucaran/colorette.git) | MIT | clearlydefined |
| [`columnify@1.6.0`](git://github.com/timoxley/columnify.git) | MIT | clearlydefined |
| [`commander@7.2.0`](https://github.com/tj/commander.js.git) | MIT | clearlydefined |
| [`common-ancestor-path@1.0.1`](git+https://github.com/isaacs/common-ancestor-path) | ISC | clearlydefined |
Expand Down Expand Up @@ -859,7 +858,6 @@
| [`strip-bom@3.0.0`](https://github.com/sindresorhus/strip-bom.git) | MIT | clearlydefined |
| [`strip-final-newline@2.0.0`](https://github.com/sindresorhus/strip-final-newline.git) | MIT | clearlydefined |
| [`strip-indent@3.0.0`](https://github.com/sindresorhus/strip-indent.git) | MIT | clearlydefined |
| [`strip-json-comments@3.1.1`](https://github.com/sindresorhus/strip-json-comments.git) | MIT | clearlydefined |
| [`strong-log-transformer@2.1.0`](git://github.com/strongloop/strong-log-transformer) | Apache-2.0 | #1138 |
| [`style-loader@3.3.3`](https://github.com/webpack-contrib/style-loader.git) | MIT | clearlydefined |
| [`style-search@0.1.0`](git+https://github.com/davidtheclark/style-search.git) | ISC | clearlydefined |
Expand Down
14 changes: 11 additions & 3 deletions .deps/prod.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
| [`@types/js-yaml@4.0.5`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | clearlydefined |
| [`@types/node@20.5.0`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | clearlydefined |
| [`@types/prop-types@15.7.5`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | clearlydefined |
| [`@types/react-redux@7.1.25`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | clearlydefined |
| [`@types/react-redux@7.1.25`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #10970 |
| [`@types/react@18.2.20`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #8234 |
| [`@types/request@2.48.8`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | clearlydefined |
| [`@types/scheduler@0.16.3`](https://github.com/DefinitelyTyped/DefinitelyTyped.git) | MIT | #7582 |
Expand Down Expand Up @@ -109,6 +109,7 @@
| [`codemirror@5.65.15`](https://github.com/codemirror/CodeMirror.git) | MIT | (clearlydefined)[https://clearlydefined.io/definitions/npm/npmjs/-/codemirror/5.65.15] |
| [`color-convert@1.9.3`](https://github.com/Qix-/color-convert.git) | MIT | clearlydefined |
| [`color-name@1.1.3`](git@github.com:dfcreative/color-name.git) | MIT | clearlydefined |
| [`colorette@2.0.20`](https://github.com/jorgebucaran/colorette.git) | MIT | clearlydefined |
| [`combined-stream@1.0.8`](git://github.com/felixge/node-combined-stream.git) | MIT | clearlydefined |
| [`concat-map@0.0.1`](git://github.com/substack/node-concat-map.git) | MIT | clearlydefined |
| [`connected-react-router@6.9.3`](https://github.com/supasate/connected-react-router.git) | MIT | clearlydefined |
Expand All @@ -125,6 +126,7 @@
| [`csstype@3.1.2`](https://github.com/frenic/csstype) | MIT | clearlydefined |
| [`dashdash@1.14.1`](git://github.com/trentm/node-dashdash.git) | MIT | clearlydefined |
| [`date-fns@2.30.0`](https://github.com/date-fns/date-fns) | MIT | clearlydefined |
| [`dateformat@4.6.3`](https://github.com/felixge/node-dateformat.git) | MIT | clearlydefined |
| [`debug@4.3.4`](git://github.com/debug-js/debug.git) | MIT | clearlydefined |
| [`deepmerge@4.3.1`](git://github.com/TehShrike/deepmerge.git) | MIT | #7032 |
| [`delayed-stream@1.0.0`](git://github.com/felixge/node-delayed-stream.git) | MIT | clearlydefined |
Expand All @@ -150,12 +152,14 @@
| [`extend@3.0.2`](https://github.com/justmoon/node-extend.git) | MIT | clearlydefined |
| [`extsprintf@1.3.0`](git://github.com/davepacheco/node-extsprintf.git) | MIT | #1813 |
| [`fast-content-type-parse@1.0.0`](https://github.com/fastify/fast-content-type-parse.git) | MIT | clearlydefined |
| [`fast-copy@3.0.1`](git+https://github.com/planttheidea/fast-copy.git) | MIT | clearlydefined |
| [`fast-decode-uri-component@1.0.1`](git+https://github.com/delvedor/fast-decode-uri-component.git) | MIT | clearlydefined |
| [`fast-deep-equal@3.1.3`](git+https://github.com/epoberezkin/fast-deep-equal.git) | MIT | clearlydefined |
| [`fast-json-stable-stringify@2.1.0`](git://github.com/epoberezkin/fast-json-stable-stringify.git) | MIT | clearlydefined |
| [`fast-json-stringify@5.8.0`](git+https://github.com/fastify/fast-json-stringify.git) | MIT | clearlydefined |
| [`fast-querystring@1.1.2`](git+https://github.com/anonrig/fast-querystring.git) | MIT | clearlydefined |
| [`fast-redact@3.3.0`](git+https://github.com/davidmarkclements/fast-redact.git) | MIT | clearlydefined |
| [`fast-safe-stringify@2.1.1`](git+https://github.com/davidmarkclements/fast-safe-stringify.git) | MIT | clearlydefined |
| [`fast-uri@2.2.0`](https://github.com/fastify/fast-uri) | MIT | (clearlydefined)[https://clearlydefined.io/definitions/npm/npmjs/-/fast-uri/2.2.0] |
| [`fastify-plugin@4.5.1`](git+https://github.com/fastify/fastify-plugin.git) | MIT | clearlydefined |
| [`fastify@4.21.0`](git+https://github.com/fastify/fastify.git) | MIT | (clearlydefined)[https://clearlydefined.io/definitions/npm/npmjs/-/fastify/4.21.0] |
Expand Down Expand Up @@ -186,6 +190,7 @@
| [`has@1.0.3`](git://github.com/tarruda/has.git) | MIT | #10930 |
| [`hash-base@3.1.0`](https://github.com/crypto-browserify/hash-base.git) | MIT | clearlydefined |
| [`hash.js@1.1.7`](git@github.com:indutny/hash.js) | MIT | #1044 |
| [`help-me@4.2.0`](https://github.com/mcollina/help-me.git) | MIT | clearlydefined |
| [`history@4.10.1`](https://github.com/ReactTraining/history.git) | MIT | clearlydefined |
| [`hmac-drbg@1.0.1`](git+ssh://git@github.com/indutny/hmac-drbg.git) | MIT | clearlydefined |
| [`hoist-non-react-statics@3.3.2`](git://github.com/mridgway/hoist-non-react-statics.git) | BSD-3-Clause | clearlydefined |
Expand All @@ -211,6 +216,7 @@
| [`isstream@0.1.2`](https://github.com/rvagg/isstream.git) | MIT | clearlydefined |
| [`joi@17.9.2`](git://github.com/hapijs/joi) | BSD-3-Clause | #7488 |
| [`jose@4.14.4`](https://github.com/panva/jose.git) | MIT | clearlydefined |
| [`joycon@3.1.1`](https://github.com/egoist/joycon.git) | MIT | clearlydefined |
| [`js-tokens@4.0.0`](https://github.com/lydell/js-tokens.git) | MIT | #2401 |
| [`js-yaml@4.1.0`](https://github.com/nodeca/js-yaml.git) | MIT | clearlydefined |
| [`jsbn@0.1.1`](https://github.com/andyperlitch/jsbn.git) | MIT | clearlydefined |
Expand Down Expand Up @@ -269,9 +275,10 @@
| [`pbkdf2@3.1.2`](https://github.com/crypto-browserify/pbkdf2.git) | MIT | clearlydefined |
| [`performance-now@2.1.0`](git://github.com/braveg1rl/performance-now.git) | MIT | clearlydefined |
| [`picocolors@1.0.0`](https://github.com/alexeyraspopov/picocolors.git) | ISC | clearlydefined |
| [`pino-abstract-transport@1.0.0`](git+https://github.com/pinojs/pino-abstract-transport.git) | MIT | clearlydefined |
| [`pino-abstract-transport@1.1.0`](git+https://github.com/pinojs/pino-abstract-transport.git) | MIT | clearlydefined |
| [`pino-pretty@10.2.0`](git+ssh://git@github.com/pinojs/pino-pretty.git) | MIT | clearlydefined |
| [`pino-std-serializers@6.2.2`](git+ssh://git@github.com/pinojs/pino-std-serializers.git) | MIT | clearlydefined |
| [`pino@8.15.0`](git+https://github.com/pinojs/pino.git) | MIT | clearlydefined |
| [`pino@8.15.1`](git+https://github.com/pinojs/pino.git) | MIT | clearlydefined |
| [`popper.js@1.16.1`](git+https://github.com/FezVrasta/popper.js.git) | MIT | [CQ22353](https://dev.eclipse.org/ipzilla/show_bug.cgi?id=22353) |
| [`postcss@8.4.28`](https://github.com/postcss/postcss.git) | MIT | #3545 |
| [`private@0.1.8`](git://github.com/benjamn/private.git) | MIT | clearlydefined |
Expand Down Expand Up @@ -348,6 +355,7 @@
| [`streamsearch@1.1.0`](http://github.com/mscdex/streamsearch.git) | MIT | clearlydefined |
| [`string_decoder@1.3.0`](git://github.com/nodejs/string_decoder.git) | MIT | clearlydefined |
| [`strip-ansi@3.0.1`](https://github.com/chalk/strip-ansi.git) | MIT | clearlydefined |
| [`strip-json-comments@3.1.1`](https://github.com/sindresorhus/strip-json-comments.git) | MIT | clearlydefined |
| [`supports-color@5.5.0`](https://github.com/chalk/supports-color.git) | MIT | clearlydefined |
| [`tabbable@5.3.3`](git+https://github.com/focus-trap/tabbable.git) | MIT | clearlydefined |
| [`tar@6.1.15`](https://github.com/isaacs/node-tar.git) | ISC | #4566 |
Expand Down
3 changes: 3 additions & 0 deletions packages/dashboard-backend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ module.exports = {
...base.collectCoverageFrom,

'!src/localRun/**',
'!src/utils/**',
'!src/server.ts',
],
testEnvironment: 'node',
setupFilesAfterEnv: ['./jest.setup.js'],
coverageThreshold: {
global: {
statements: 81,
Expand Down
13 changes: 13 additions & 0 deletions packages/dashboard-backend/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) 2018-2023 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/

jest.mock('./src/utils/logger');
2 changes: 2 additions & 0 deletions packages/dashboard-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
"js-yaml": "^4.0.0",
"multi-ini": "^2.3.2",
"node-fetch": "^2.6.7",
"pino": "^8.15.1",
"pino-pretty": "^10.2.0",
"querystring": "^0.2.1",
"reflect-metadata": "^0.1.13",
"request": "^2.88.2",
Expand Down
5 changes: 1 addition & 4 deletions packages/dashboard-backend/src/__tests__/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,13 @@

import process from 'process';

import { setup, teardown } from '@/helpers/tests/appBuilder';
import { setup, teardown } from '@/utils/appBuilder';

const mockProcessExit = jest.fn();
(process as any).exit = mockProcessExit.mockImplementation(code => {
throw new Error('exit code ' + code);
});

// mute the output
console.error = jest.fn();

describe('App', () => {
afterEach(() => {
jest.clearAllMocks();
Expand Down
60 changes: 30 additions & 30 deletions packages/dashboard-backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ import { registerYamlResolverRoute } from '@/routes/api/yamlResolver';
import { registerFactoryAcceptanceRedirect } from '@/routes/factoryAcceptanceRedirect';
import { registerWorkspaceRedirect } from '@/routes/workspaceRedirect';

export default async function buildApp(server: FastifyInstance): Promise<void> {
export default async function buildApp(server: FastifyInstance): Promise<unknown> {
const cheHost = process.env.CHE_HOST as string;
if (!cheHost) {
console.error('CHE_HOST environment variable is required');
server.log.fatal('CHE_HOST environment variable is required');
process.exit(1);
}

Expand All @@ -59,60 +59,60 @@ export default async function buildApp(server: FastifyInstance): Promise<void> {
done(null, json);
} catch (e) {
const error = new Error(helpers.errors.getMessage(e));
console.warn(`[WARN] Can't parse the JSON payload:`, body);
server.log.warn(`Can't parse the JSON payload: %s`, body);
done(error, undefined);
}
},
);

registerWebSocket(server);
return Promise.allSettled([
registerWebSocket(server),

if (isLocalRun()) {
registerLocalRun(server);
}
isLocalRun() ? registerLocalRun(server) : Promise.resolve(),

registerCors(isLocalRun(), server);
registerCors(isLocalRun(), server),

registerStaticServer(publicFolder, server);
registerStaticServer(publicFolder, server),

registerFactoryAcceptanceRedirect(server);
registerFactoryAcceptanceRedirect(server),

registerWorkspaceRedirect(server);
registerWorkspaceRedirect(server),

registerWebsocket(server);
registerWebsocket(server),

// swagger and API
registerSwagger(server);
// swagger and API
registerSwagger(server),

registerClusterConfigRoute(server);
registerClusterConfigRoute(server),

registerClusterInfoRoute(server);
registerClusterInfoRoute(server),

registerDevWorkspaceTemplates(server);
registerDevWorkspaceTemplates(server),

registerDevworkspacesRoutes(server);
registerDevworkspacesRoutes(server),

registerDockerConfigRoutes(server);
registerDockerConfigRoutes(server),

registerEventsRoutes(server);
registerEventsRoutes(server),

registerPodsRoutes(server);
registerPodsRoutes(server),

registerKubeConfigRoute(server);
registerKubeConfigRoute(server),

registerPodmanLoginRoute(server);
registerPodmanLoginRoute(server),

registerServerConfigRoute(server);
registerServerConfigRoute(server),

registerUserProfileRoute(server);
registerUserProfileRoute(server),

registerYamlResolverRoute(server);
registerYamlResolverRoute(server),

registerDevworkspaceResourcesRoute(server);
registerDevworkspaceResourcesRoute(server),

registerPersonalAccessTokenRoutes(server);
registerPersonalAccessTokenRoutes(server),

registerGitConfigRoutes(server);
registerGitConfigRoutes(server),

registerGettingStartedSamplesRoutes(isLocalRun(), server);
registerGettingStartedSamplesRoutes(isLocalRun(), server),
]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ import * as mockClient from '@kubernetes/client-node';
import { CoreV1Api, CoreV1Event, V1Status } from '@kubernetes/client-node';

import { EventApiService } from '@/devworkspaceClient/services/eventApi';
import { logger } from '@/utils/logger';

jest.mock('../helpers/prepareCustomObjectWatch');
jest.mock('../helpers/retryableExec');

const namespace = 'user-che';

// mute console.error
console.error = jest.fn();

describe('Event API Service', () => {
let eventApiService: EventApiService;

Expand All @@ -45,6 +44,7 @@ describe('Event API Service', () => {

afterEach(() => {
jest.clearAllMocks();
spyListNamespacedEvent.mockClear();
});

it('should list events', async () => {
Expand All @@ -57,9 +57,10 @@ describe('Event API Service', () => {
const failureReason = 'failed to get events list';
spyListNamespacedEvent.mockRejectedValue(new Error(failureReason));

const list = async () => await eventApiService.listInNamespace(namespace);
expect.assertions(1);

expect(list).rejects.toThrowError(failureReason);
const list = async () => await eventApiService.listInNamespace(namespace);
await expect(list()).rejects.toThrow(failureReason);
});

it('should watch events', async () => {
Expand Down Expand Up @@ -174,7 +175,10 @@ describe('Event API Service', () => {
const error = new Error('watch error');

(eventApiService as any).handleWatchError(error, path);
expect(console.error).toHaveBeenCalledWith(`[ERROR] Stopped watching ${path}. Reason:`, error);
expect(logger.warn).toHaveBeenCalledWith(
error,
'Stopped watching /api/v1/namespaces/user-che/events.',
);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { CoreV1Api, V1PodList } from '@kubernetes/client-node';
import * as helper from '@/devworkspaceClient/services/helpers/exec';
import { KubeConfigApiService } from '@/devworkspaceClient/services/kubeConfigApi';

// mute the output
console.error = jest.fn();

const homeUserDir = '/home/user';
const kubeConfigDir = `${homeUserDir}/.kube`;
const mockExecPrintenvHome = jest.fn().mockReturnValue({
Expand Down Expand Up @@ -79,10 +82,6 @@ describe('Kubernetes Config API Service', () => {
});

test('injecting kubeconfig', async () => {
// mute output
console.error = jest.fn();
console.warn = jest.fn();

await kubeConfigService.injectKubeConfig(namespace, 'wksp-id');
expect(spyExec).toHaveBeenCalledTimes(4);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@ import * as mockClient from '@kubernetes/client-node';
import { CoreV1Api, V1Pod, V1Status } from '@kubernetes/client-node';

import { PodApiService } from '@/devworkspaceClient/services/podApi';
import { logger } from '@/utils/logger';

jest.mock('../helpers/prepareCustomObjectWatch');

const namespace = 'user-che';

// mute console.error
console.error = jest.fn();

describe('Pod API Service', () => {
let podApiService: PodApiService;

Expand Down Expand Up @@ -177,7 +175,7 @@ describe('Pod API Service', () => {
const error = new Error('watch error');

(podApiService as any).handleWatchError(error, path);
expect(console.error).toHaveBeenCalledWith(`[ERROR] Stopped watching ${path}. Reason:`, error);
expect(logger.error).toHaveBeenCalledWith(error, `Stopped watching ${path}.`);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import * as mockClient from '@kubernetes/client-node';
import { CustomObjectsApi } from '@kubernetes/client-node';

import { CustomResourceDefinition, CustomResourceDefinitionList } from '@/devworkspaceClient';
import { CheClusterCustomResource, CustomResourceDefinitionList } from '@/devworkspaceClient';
import { ServerConfigApiService } from '@/devworkspaceClient/services/serverConfigApi';

jest.mock('../../../helpers/getUserName.ts');
Expand Down Expand Up @@ -149,7 +149,7 @@ function buildCustomResourceList(): { body: CustomResourceDefinitionList } {
};
}

function buildCustomResource(): CustomResourceDefinition {
function buildCustomResource(): CheClusterCustomResource {
return {
apiVersion: 'org.eclipse.che/v2',
kind: 'CheCluster',
Expand Down Expand Up @@ -198,5 +198,5 @@ function buildCustomResource(): CustomResourceDefinition {
devfileRegistryURL: 'http://devfile-registry.eclipse-che.svc/devfile-registry',
pluginRegistryURL: 'http://plugin-registry.eclipse-che.svc/v3',
},
} as CustomResourceDefinition;
} as CheClusterCustomResource;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import { prepareCustomObjectWatch } from '@/devworkspaceClient/services/helpers/prepareCustomObjectWatch';
import { IDevWorkspaceApi } from '@/devworkspaceClient/types';
import { MessageListener } from '@/services/types/Observer';
import { logger } from '@/utils/logger';

const DEV_WORKSPACE_API_ERROR_LABEL = 'CUSTOM_OBJECTS_API_ERROR';

Expand Down Expand Up @@ -193,7 +194,7 @@ export class DevWorkspaceApiService implements IDevWorkspaceApi {
}
},
(error: unknown) => {
console.error(`[ERROR] Stopped watching ${path}. Reason:`, error);
logger.warn(error, `Stopped watching ${path}.`);
},
);

Expand Down
Loading
Loading