Skip to content

Commit

Permalink
Merge pull request #1747 from AmericanAirlines/upgrade-logger
Browse files Browse the repository at this point in the history
feat: upgrading logger
  • Loading branch information
Xantier authored Dec 6, 2024
2 parents e27d32c + 8915f83 commit 3bc10dd
Show file tree
Hide file tree
Showing 42 changed files with 154 additions and 51 deletions.
13 changes: 13 additions & 0 deletions .changeset/two-knives-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@roadiehq/scaffolder-backend-module-http-request': minor
'@roadiehq/scaffolder-backend-argocd': minor
'@roadiehq/backstage-plugin-argo-cd-backend': minor
'@roadiehq/rag-ai-backend-embeddings-openai': minor
'@roadiehq/catalog-backend-module-aws': minor
'@roadiehq/backstage-plugin-aws-auth': minor
'@roadiehq/backstage-plugin-aws-backend': minor
'@roadiehq/rag-ai-backend': minor
'backend': minor
---

We are making the logger compatible with Backstage's LoggerService and winston's Logger so that Roadie can be used with newer and older versions of Backstage.
6 changes: 5 additions & 1 deletion packages/backend/src/plugins/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
import { createRouter } from '@backstage/plugin-proxy-backend';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
import { loggerToWinstonLogger } from '@backstage/backend-common';
import { Logger } from 'winston';

export default async function createPlugin({
logger,
config,
discovery,
}: PluginEnvironment): Promise<Router> {
return await createRouter({ logger, config, discovery });
const winstonLogger =
logger instanceof Logger ? logger : loggerToWinstonLogger(logger);
return await createRouter({ logger: winstonLogger, config, discovery });
}
7 changes: 6 additions & 1 deletion packages/backend/src/plugins/scaffolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import {
ContainerRunner,
DockerContainerRunner,
loggerToWinstonLogger,
} from '@backstage/backend-common';
import { CatalogClient } from '@backstage/catalog-client';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
Expand Down Expand Up @@ -49,6 +50,7 @@ import { ScmIntegrations } from '@backstage/integration';
import { Config } from '@backstage/config';
import { DiscoveryApi } from '@backstage/plugin-permission-common';
import { UrlReaderService } from '@backstage/backend-plugin-api';
import { Logger } from 'winston';

export const createActions = (options: {
reader: UrlReaderService;
Expand Down Expand Up @@ -98,8 +100,11 @@ export default async function createPlugin({

const catalogClient = new CatalogClient({ discoveryApi: discovery });

const winstonLogger =
logger instanceof Logger ? logger : loggerToWinstonLogger(logger);

return await createRouter({
logger,
logger: winstonLogger,
config,
database,
catalogClient,
Expand Down
7 changes: 6 additions & 1 deletion packages/backend/src/plugins/techdocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import {
Preparers,
Publisher,
} from '@backstage/plugin-techdocs-backend';
import { Logger } from 'winston';
import { loggerToWinstonLogger } from '@backstage/backend-common';
import Docker from 'dockerode';
import { Router } from 'express';
import { PluginEnvironment } from '../types';
Expand Down Expand Up @@ -58,11 +60,14 @@ export default async function createPlugin({
// checks if the publisher is working and logs the result
await publisher.getReadiness();

const winstonLogger =
logger instanceof Logger ? logger : loggerToWinstonLogger(logger);

return await createRouter({
preparers,
generators,
publisher,
logger,
logger: winstonLogger,
config,
discovery,
cache,
Expand Down
3 changes: 2 additions & 1 deletion packages/backend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { Config } from '@backstage/config';
import {
PluginCacheManager,
Expand All @@ -26,7 +27,7 @@ import { PluginTaskScheduler } from '@backstage/backend-tasks';
import { UrlReaderService } from '@backstage/backend-plugin-api';

export type PluginEnvironment = {
logger: Logger;
logger: Logger | LoggerService;
cache: PluginCacheManager;
database: PluginDatabaseManager;
config: Config;
Expand Down
1 change: 1 addition & 0 deletions plugins/backend/backstage-aws-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
},
"dependencies": {
"@backstage/backend-common": "^0.25.0",
"@backstage/backend-plugin-api": "^1.0.1",
"@backstage/catalog-client": "^1.8.0",
"@backstage/config": "^1.3.0",
"@types/express": "^4.17.6",
Expand Down
3 changes: 2 additions & 1 deletion plugins/backend/backstage-aws-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import { Config } from '@backstage/config';
import express, { Request } from 'express';
import Router from 'express-promise-router';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { CloudControl } from '@aws-sdk/client-cloudcontrol';
import { fromTemporaryCredentials } from '@aws-sdk/credential-providers';
import { Account } from '../types';

export interface RouterOptions {
logger: Logger;
logger: Logger | LoggerService;
config: Config;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ import {
} from '@backstage/backend-common';
import { Server } from 'http';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { createRouter } from './router';

export interface ServerOptions {
port: number;
enableCors: boolean;
logger: Logger;
logger: Logger | LoggerService;
}

export async function startStandaloneServer(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Config } from '@backstage/config';
import fetch from 'cross-fetch';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { timer } from './timer.services';

import {
Expand Down Expand Up @@ -45,7 +46,7 @@ export class ArgoService implements ArgoServiceApi {
private readonly username: string,
private readonly password: string,
private readonly config: Config,
private readonly logger: Logger,
private readonly logger: Logger | LoggerService,
) {
this.instanceConfigs = this.config
.getConfigArray('argocd.appLocatorMethods')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from './argocdTestResponses';
import fetchMock from 'jest-fetch-mock';
import { timer } from './timer.services';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { ResourceItem, UpdateArgoProjectAndAppProps } from './types';
import { mocked } from 'jest-mock';

Expand All @@ -18,7 +18,7 @@ jest.mock('./timer.services', () => ({
const loggerMock = {
error: jest.fn(),
info: jest.fn(),
} as unknown as Logger;
} as unknown as LoggerService;

const getConfig = (options: {
token?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { Config } from '@backstage/config';
import express from 'express';
import Router from 'express-promise-router';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { ArgoService } from './argocd.service';
import { getArgoConfigByInstanceName } from '../utils/getArgoConfig';

export interface RouterOptions {
logger: Logger;
logger: Logger | LoggerService;
config: Config;
}
export type Response = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import {
} from '@backstage/backend-common';
import { Server } from 'http';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { createRouter } from './router';

export interface ServerOptions {
port: number;
enableCors: boolean;
logger: Logger;
logger: Logger | LoggerService;
}

export async function startStandaloneServer(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Config } from '@backstage/config';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';

export type getRevisionDataResp = {
author: string;
Expand Down Expand Up @@ -61,7 +62,7 @@ export interface CreateArgoResourcesProps {
sourceRepo: string;
sourcePath: string;
labelValue: string;
logger: Logger;
logger: Logger | LoggerService;
}

export interface UpdateArgoProjectAndAppProps {
Expand Down
1 change: 1 addition & 0 deletions plugins/backend/backstage-plugin-aws-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"dependencies": {
"@backstage/backend-common": "^0.25.0",
"@backstage/backend-plugin-api": "^1.0.1",
"@types/express": "^4.17.11",
"aws-sdk": "^2.902.0",
"cors": "^2.8.5",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import express from 'express';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { generateTemporaryCredentials } from './generateTemporaryCredentials';

export type LambdaData = {
Expand All @@ -35,7 +36,7 @@ export function getAwsApiGenerateTempCredentialsForwarder({
}: {
AWS_ACCESS_KEY_ID?: string;
AWS_ACCESS_KEY_SECRET?: string;
logger: Logger;
logger: Logger | LoggerService;
}) {
return async function forwardRequest(
_: express.Request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
*/

import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import Router from 'express-promise-router';
import express from 'express';
import { getAwsApiGenerateTempCredentialsForwarder } from './aws-api';

export async function createRouter(logger: Logger): Promise<express.Router> {
export async function createRouter(
logger: Logger | LoggerService,
): Promise<express.Router> {
const router = Router();
router.use(express.json());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import cors from 'cors';
import express from 'express';
import helmet from 'helmet';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { createRouter } from './router';

export async function createStandaloneApplication(
logger: Logger,
logger: Logger | LoggerService,
): Promise<express.Application> {
const app = express();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
*/
import { Server } from 'http';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { createStandaloneApplication } from './standaloneApplication';

export async function startStandaloneServer(
parentLogger: Logger,
parentLogger: Logger | LoggerService,
): Promise<Server> {
const logger = parentLogger.child({ service: 'scaffolder-backend' });
logger.debug('Creating application...');
Expand Down
1 change: 1 addition & 0 deletions plugins/backend/catalog-backend-module-aws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@aws-sdk/lib-dynamodb": "^3.696.0",
"@backstage/integration-aws-node": "^0.1.13",
"@backstage/backend-common": "^0.25.0",
"@backstage/backend-plugin-api": "^1.0.1",
"@backstage/catalog-client": "^1.8.0",
"@backstage/plugin-kubernetes-common": "^0.9.0",
"@backstage/catalog-model": "^1.7.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
import { CatalogProcessor } from '@backstage/plugin-catalog-backend';
import { CatalogApi } from '@backstage/catalog-client';
import { Logger } from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';

export abstract class AWSCatalogProcessor implements CatalogProcessor {
protected readonly catalogApi: CatalogApi;
protected readonly logger: Logger;
protected readonly logger: Logger | LoggerService;
public abstract getProcessorName(): string;
constructor({
catalogApi,
logger,
}: {
catalogApi: CatalogApi;
logger: Logger;
logger: Logger | LoggerService;
}) {
this.catalogApi = catalogApi;
this.logger = logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ import {
import { ANNOTATION_AWS_IAM_ROLE_ARN } from '../annotations';
import { Config } from '@backstage/config';
import * as winston from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import { CatalogClient, CatalogApi } from '@backstage/catalog-client';
import { arnToName } from '../utils/arnToName';

export class AWSIAMRoleProcessor extends AWSCatalogProcessor {
static fromConfig(
_config: Config,
options: { logger: winston.Logger; discovery: PluginEndpointDiscovery },
options: {
logger: winston.Logger | LoggerService;
discovery: PluginEndpointDiscovery;
},
) {
const catalogApi: CatalogApi = new CatalogClient({
discoveryApi: options.discovery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';
import { merge } from 'lodash';
import { mapColumnsToEntityValues } from '../utils/columnMapper';
import * as winston from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import {
ANNOTATION_ACCOUNT_ID,
ANNOTATION_AWS_DDB_TABLE_ARN,
Expand All @@ -51,11 +52,14 @@ export class AWSDynamoDbTableDataProvider implements EntityProvider {
private readonly accountId: string;
private readonly roleArn: string;
private readonly tableDataConfig: DdbTableDataConfigOptions;
private readonly logger: winston.Logger;
private readonly logger: winston.Logger | LoggerService;

private connection?: EntityProviderConnection;

static fromConfig(config: Config, options: { logger: winston.Logger }) {
static fromConfig(
config: Config,
options: { logger: winston.Logger | LoggerService },
) {
return new AWSDynamoDbTableDataProvider(
config.getString('accountId'),
config.getString('roleName'),
Expand All @@ -68,7 +72,7 @@ export class AWSDynamoDbTableDataProvider implements EntityProvider {
accountId: string,
roleArn: string,
options: DdbTableDataConfigOptions,
logger: winston.Logger,
logger: winston.Logger | LoggerService,
) {
this.accountId = accountId;
this.roleArn = roleArn;
Expand Down Expand Up @@ -168,7 +172,7 @@ export class AWSDynamoDbTableDataProvider implements EntityProvider {
})),
});
} catch (e) {
this.logger.error(e);
this.logger.error((e as Error).message, e as Error);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { DynamoDB, paginateListTables } from '@aws-sdk/client-dynamodb';
import { Config } from '@backstage/config';
import * as winston from 'winston';
import { LoggerService } from '@backstage/backend-plugin-api';
import { AWSEntityProvider } from './AWSEntityProvider';
import { ResourceEntity } from '@backstage/catalog-model';
import { ANNOTATION_AWS_DDB_TABLE_ARN } from '../annotations';
Expand All @@ -37,7 +38,7 @@ export class AWSDynamoDbTableProvider extends AWSEntityProvider {
static fromConfig(
config: Config,
options: {
logger: winston.Logger;
logger: winston.Logger | LoggerService;
catalogApi?: CatalogApi;
providerId?: string;
ownerTag?: string;
Expand Down
Loading

0 comments on commit 3bc10dd

Please sign in to comment.