Skip to content

Commit

Permalink
chore: change most of plugins to use LoggerService
Browse files Browse the repository at this point in the history
quite a big PR for this but the changes are pretty stright forward.
hopefully gets merged before most of these plugins move to the community
repository.

Signed-off-by: Heikki Hellgren <heikki.hellgren@op.fi>
  • Loading branch information
drodil committed Apr 12, 2024
1 parent 16ef9e5 commit d5a1fe1
Show file tree
Hide file tree
Showing 285 changed files with 968 additions and 1,043 deletions.
52 changes: 52 additions & 0 deletions .changeset/many-pears-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
'@backstage/plugin-search-backend-module-stack-overflow-collator': patch
'@backstage/plugin-catalog-backend-module-incremental-ingestion': patch
'@backstage/plugin-catalog-backend-module-bitbucket-server': patch
'@backstage/plugin-tech-insights-backend-module-jsonfc': patch
'@backstage/plugin-catalog-backend-module-github-org': patch
'@backstage/plugin-scaffolder-backend-module-github': patch
'@backstage/plugin-catalog-backend-module-puppetdb': patch
'@backstage/plugin-catalog-backend-module-msgraph': patch
'@backstage/plugin-search-backend-module-techdocs': patch
'@backstage/plugin-catalog-backend-module-gerrit': patch
'@backstage/plugin-catalog-backend-module-github': patch
'@backstage/plugin-catalog-backend-module-gitlab': patch
'@backstage/plugin-search-backend-module-explore': patch
'@backstage/plugin-catalog-backend-module-azure': patch
'@backstage/plugin-catalog-backend-module-aws': patch
'@backstage/plugin-catalog-backend-module-gcp': patch
'@backstage/plugin-scaffolder-node-test-utils': patch
'@backstage/plugin-entity-feedback-backend': patch
'@backstage/plugin-code-coverage-backend': patch
'@backstage/plugin-tech-insights-backend': patch
'@backstage/plugin-azure-devops-backend': patch
'@backstage/plugin-azure-sites-backend': patch
'@backstage/plugin-search-backend-node': patch
'@backstage/plugin-kubernetes-backend': patch
'@backstage/plugin-lighthouse-backend': patch
'@backstage/plugin-permission-backend': patch
'@backstage/plugin-tech-insights-node': patch
'@backstage/plugin-sonarqube-backend': patch
'@backstage/backend-app-api': patch
'@backstage/plugin-airbrake-backend': patch
'@backstage/plugin-devtools-backend': patch
'@backstage/plugin-linguist-backend': patch
'@backstage/plugin-periskop-backend': patch
'@backstage/plugin-playlist-backend': patch
'@backstage/plugin-catalog-backend': patch
'@backstage/plugin-explore-backend': patch
'@backstage/plugin-jenkins-backend': patch
'@backstage/plugin-scaffolder-node': patch
'@backstage/backend-tasks': patch
'@backstage/plugin-badges-backend': patch
'@backstage/plugin-bazaar-backend': patch
'@backstage/plugin-search-backend': patch
'@backstage/plugin-kafka-backend': patch
'@backstage/plugin-nomad-backend': patch
'@backstage/plugin-techdocs-node': patch
'@backstage/plugin-todo-backend': patch
'@backstage/plugin-adr-backend': patch
'@backstage/plugin-app-backend': patch
---

Replaced winston logger with `LoggerService`
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import { loggerToWinstonLogger } from '@backstage/backend-common';
import {
coreServices,
createServiceFactory,
Expand All @@ -33,7 +32,7 @@ export const schedulerServiceFactory = createServiceFactory({
return TaskScheduler.forPlugin({
pluginId: plugin.getId(),
databaseManager,
logger: loggerToWinstonLogger(logger),
logger,
});
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { loggerToWinstonLogger, UrlReaders } from '@backstage/backend-common';
import { UrlReaders } from '@backstage/backend-common';
import {
coreServices,
createServiceFactory,
Expand All @@ -30,7 +30,7 @@ export const urlReaderServiceFactory = createServiceFactory({
async factory({ config, logger }) {
return UrlReaders.default({
config,
logger: loggerToWinstonLogger(logger),
logger,
});
},
});
11 changes: 7 additions & 4 deletions packages/backend-tasks/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Duration } from 'luxon';
import { HumanDuration as HumanDuration_2 } from '@backstage/types';
import { JsonObject } from '@backstage/types';
import { LegacyRootDatabaseService } from '@backstage/backend-common';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { PluginDatabaseManager } from '@backstage/backend-common';

// @public @deprecated
Expand Down Expand Up @@ -83,20 +83,23 @@ export interface TaskScheduleDefinitionConfig {

// @public
export class TaskScheduler {
constructor(databaseManager: LegacyRootDatabaseService, logger: Logger);
constructor(
databaseManager: LegacyRootDatabaseService,
logger: LoggerService,
);
forPlugin(pluginId: string): PluginTaskScheduler;
// (undocumented)
static forPlugin(opts: {
pluginId: string;
databaseManager: PluginDatabaseManager;
logger: Logger;
logger: LoggerService;
}): PluginTaskScheduler;
// (undocumented)
static fromConfig(
config: Config,
options?: {
databaseManager?: LegacyRootDatabaseService;
logger?: Logger;
logger?: LoggerService;
},
): TaskScheduler;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-tasks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"dependencies": {
"@backstage/backend-common": "workspace:^",
"@backstage/backend-plugin-api": "workspace:^",
"@backstage/config": "workspace:^",
"@backstage/errors": "workspace:^",
"@backstage/types": "workspace:^",
Expand All @@ -43,7 +44,6 @@
"lodash": "^4.17.21",
"luxon": "^3.0.0",
"uuid": "^9.0.0",
"winston": "^3.2.1",
"zod": "^3.22.4"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/backend-tasks/src/tasks/LocalTaskWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import { ConflictError } from '@backstage/errors';
import { CronTime } from 'cron';
import { DateTime, Duration } from 'luxon';
import { Logger } from 'winston';
import { TaskFunction, TaskSettingsV2 } from './types';
import { delegateAbortController, sleep } from './util';
import { LoggerService } from '@backstage/backend-plugin-api';

/**
* Implements tasks that run locally without cross-host collaboration.
Expand All @@ -32,7 +32,7 @@ export class LocalTaskWorker {
constructor(
private readonly taskId: string,
private readonly fn: TaskFunction,
private readonly logger: Logger,
private readonly logger: LoggerService,
) {}

start(settings: TaskSettingsV2, options?: { signal?: AbortSignal }) {
Expand Down
8 changes: 4 additions & 4 deletions packages/backend-tasks/src/tasks/PluginTaskSchedulerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@

import { Knex } from 'knex';
import { Duration } from 'luxon';
import { Logger } from 'winston';
import { LocalTaskWorker } from './LocalTaskWorker';
import { TaskWorker } from './TaskWorker';
import {
PluginTaskScheduler,
TaskDescriptor,
TaskFunction,
TaskInvocationDefinition,
TaskRunner,
TaskScheduleDefinition,
TaskSettingsV2,
} from './types';
import { validateId } from './util';
import { TaskFunction } from './types';
import { metrics, Counter, Histogram } from '@opentelemetry/api';
import { Counter, Histogram, metrics } from '@opentelemetry/api';
import { LoggerService } from '@backstage/backend-plugin-api';

/**
* Implements the actual task management.
Expand All @@ -43,7 +43,7 @@ export class PluginTaskSchedulerImpl implements PluginTaskScheduler {

constructor(
private readonly databaseFactory: () => Promise<Knex>,
private readonly logger: Logger,
private readonly logger: LoggerService,
) {
const meter = metrics.getMeter('default');
this.counter = meter.createCounter('backend_tasks.task.runs.count', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import { Knex } from 'knex';
import { Duration } from 'luxon';
import { Logger } from 'winston';
import { DbTasksRow, DB_TASKS_TABLE } from '../database/tables';
import { DB_TASKS_TABLE, DbTasksRow } from '../database/tables';
import { sleep } from './util';
import { LoggerService } from '@backstage/backend-plugin-api';

/**
* Makes sure to auto-expire and clean up things that time out or for other
Expand All @@ -27,12 +27,12 @@ import { sleep } from './util';
export class PluginTaskSchedulerJanitor {
private readonly knex: Knex;
private readonly waitBetweenRuns: Duration;
private readonly logger: Logger;
private readonly logger: LoggerService;

constructor(options: {
knex: Knex;
waitBetweenRuns: Duration;
logger: Logger;
logger: LoggerService;
}) {
this.knex = options.knex;
this.waitBetweenRuns = options.waitBetweenRuns;
Expand Down
8 changes: 4 additions & 4 deletions packages/backend-tasks/src/tasks/TaskScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import {
import { Config } from '@backstage/config';
import { once } from 'lodash';
import { Duration } from 'luxon';
import { Logger } from 'winston';
import { migrateBackendTasks } from '../database/migrateBackendTasks';
import { PluginTaskSchedulerImpl } from './PluginTaskSchedulerImpl';
import { PluginTaskSchedulerJanitor } from './PluginTaskSchedulerJanitor';
import { PluginTaskScheduler } from './types';
import { LoggerService } from '@backstage/backend-plugin-api';

/**
* Deals with the scheduling of distributed tasks.
Expand All @@ -39,7 +39,7 @@ export class TaskScheduler {
config: Config,
options?: {
databaseManager?: LegacyRootDatabaseService;
logger?: Logger;
logger?: LoggerService;
},
): TaskScheduler {
const databaseManager =
Expand All @@ -52,7 +52,7 @@ export class TaskScheduler {

constructor(
private readonly databaseManager: LegacyRootDatabaseService,
private readonly logger: Logger,
private readonly logger: LoggerService,
) {}

/**
Expand All @@ -72,7 +72,7 @@ export class TaskScheduler {
static forPlugin(opts: {
pluginId: string;
databaseManager: PluginDatabaseManager;
logger: Logger;
logger: LoggerService;
}): PluginTaskScheduler {
const databaseFactory = once(async () => {
const knex = await opts.databaseManager.getClient();
Expand Down
6 changes: 3 additions & 3 deletions packages/backend-tasks/src/tasks/TaskWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ import { CronTime } from 'cron';
import { Knex } from 'knex';
import { DateTime, Duration } from 'luxon';
import { v4 as uuid } from 'uuid';
import { Logger } from 'winston';
import { DbTasksRow, DB_TASKS_TABLE } from '../database/tables';
import { DB_TASKS_TABLE, DbTasksRow } from '../database/tables';
import { TaskFunction, TaskSettingsV2, taskSettingsV2Schema } from './types';
import { delegateAbortController, nowPlus, sleep } from './util';
import { LoggerService } from '@backstage/backend-plugin-api';

const DEFAULT_WORK_CHECK_FREQUENCY = Duration.fromObject({ seconds: 5 });

Expand All @@ -36,7 +36,7 @@ export class TaskWorker {
private readonly taskId: string,
private readonly fn: TaskFunction,
private readonly knex: Knex,
private readonly logger: Logger,
private readonly logger: LoggerService,
private readonly workCheckFrequency: Duration = DEFAULT_WORK_CHECK_FREQUENCY,
) {}

Expand Down
6 changes: 3 additions & 3 deletions plugins/adr-backend/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Config } from '@backstage/config';
import { DocumentCollatorFactory } from '@backstage/plugin-search-common';
import { Entity } from '@backstage/catalog-model';
import express from 'express';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { PluginCacheManager } from '@backstage/backend-common';
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import { Readable } from 'stream';
Expand All @@ -29,7 +29,7 @@ export type AdrCollatorFactoryOptions = {
config: Config;
catalogClient?: CatalogApi;
discovery: PluginEndpointDiscovery;
logger: Logger;
logger: LoggerService;
parser?: AdrParser;
reader: UrlReader;
tokenManager: TokenManager;
Expand All @@ -54,7 +54,7 @@ export default adrPlugin;
export type AdrRouterOptions = {
reader: UrlReader;
cacheClient: CacheClient;
logger: Logger;
logger: LoggerService;
};

// @public
Expand Down
1 change: 0 additions & 1 deletion plugins/adr-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"luxon": "^3.0.0",
"marked": "^12.0.0",
"node-fetch": "^2.6.5",
"winston": "^3.2.1",
"yn": "^4.0.0"
},
"devDependencies": {
Expand Down
3 changes: 1 addition & 2 deletions plugins/adr-backend/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { loggerToWinstonLogger } from '@backstage/backend-common';
import {
coreServices,
createBackendPlugin,
Expand All @@ -38,7 +37,7 @@ export const adrPlugin = createBackendPlugin({
async init({ httpRouter, logger, reader, cache }) {
httpRouter.use(
await createRouter({
logger: loggerToWinstonLogger(logger),
logger,
reader,
cacheClient: cache,
}),
Expand Down
11 changes: 5 additions & 6 deletions plugins/adr-backend/src/search/DefaultAdrCollatorFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@
*/

import { Readable } from 'stream';
import { Logger } from 'winston';
import {
CacheClient,
createLegacyAuthAdapters,
PluginCacheManager,
PluginEndpointDiscovery,
TokenManager,
UrlReader,
createLegacyAuthAdapters,
} from '@backstage/backend-common';
import {
CATALOG_FILTER_EXISTS,
CatalogApi,
CatalogClient,
CATALOG_FILTER_EXISTS,
} from '@backstage/catalog-client';
import { stringifyEntityRef } from '@backstage/catalog-model';
import { Config } from '@backstage/config';
Expand All @@ -47,7 +46,7 @@ import { DocumentCollatorFactory } from '@backstage/plugin-search-common';

import { createMadrParser } from './createMadrParser';
import { AdrParser } from './types';
import { AuthService } from '@backstage/backend-plugin-api';
import { AuthService, LoggerService } from '@backstage/backend-plugin-api';

/**
* Options to configure the AdrCollatorFactory
Expand Down Expand Up @@ -78,7 +77,7 @@ export type AdrCollatorFactoryOptions = {
/**
* Logger
*/
logger: Logger;
logger: LoggerService;
/**
* ADR content parser. Defaults to built in MADR parser.
*/
Expand Down Expand Up @@ -106,7 +105,7 @@ export class DefaultAdrCollatorFactory implements DocumentCollatorFactory {
private readonly adrFilePathFilterFn: AdrFilePathFilterFn;
private readonly cacheClient: CacheClient;
private readonly catalogClient: CatalogApi;
private readonly logger: Logger;
private readonly logger: LoggerService;
private readonly parser: AdrParser;
private readonly reader: UrlReader;
private readonly auth: AuthService;
Expand Down

0 comments on commit d5a1fe1

Please sign in to comment.