Merged in release/2024-11-01 (pull request #1862)

release/2024-11-01 - Misc fixes
This commit is contained in:
Dave Richer
2024-10-29 15:20:46 +00:00
2 changed files with 16 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ const { defaultProvider } = require("@aws-sdk/credential-provider-node");
const { default: InstanceManager } = require("../utils/instanceMgr"); const { default: InstanceManager } = require("../utils/instanceMgr");
const aws = require("@aws-sdk/client-ses"); const aws = require("@aws-sdk/client-ses");
const nodemailer = require("nodemailer"); const nodemailer = require("nodemailer");
const logger = require("../utils/logger");
const isLocal = isString(process.env?.LOCALSTACK_HOSTNAME) && !isEmpty(process.env?.LOCALSTACK_HOSTNAME); const isLocal = isString(process.env?.LOCALSTACK_HOSTNAME) && !isEmpty(process.env?.LOCALSTACK_HOSTNAME);
@@ -19,7 +20,7 @@ const sesConfig = {
if (isLocal) { if (isLocal) {
sesConfig.endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:4566`; sesConfig.endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:4566`;
console.log(`SES Mailer set to LocalStack end point: ${sesConfig.endpoint}`); logger.logger.debug(`SES Mailer set to LocalStack end point: ${sesConfig.endpoint}`);
} }
const ses = new aws.SES(sesConfig); const ses = new aws.SES(sesConfig);

View File

@@ -8,7 +8,7 @@ const InstanceManager = require("../utils/instanceMgr").default;
const winston = require("winston"); const winston = require("winston");
const WinstonCloudWatch = require("winston-cloudwatch"); const WinstonCloudWatch = require("winston-cloudwatch");
const { isString, isEmpty } = require("lodash"); const { isString, isEmpty } = require("lodash");
const { networkInterfaces } = require("node:os"); const { networkInterfaces, hostname } = require("node:os");
const createLogger = () => { const createLogger = () => {
try { try {
@@ -28,9 +28,6 @@ const createLogger = () => {
if (isLocal) { if (isLocal) {
winstonCloudwatchTransportDefaults.awsOptions.endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:4566`; winstonCloudwatchTransportDefaults.awsOptions.endpoint = `http://${process.env.LOCALSTACK_HOSTNAME}:4566`;
console.log(
`Winston Transports set to LocalStack end point: ${winstonCloudwatchTransportDefaults.awsOptions.endpoint}`
);
} }
const levelFilter = (levels) => { const levelFilter = (levels) => {
@@ -43,19 +40,22 @@ const createLogger = () => {
})(); })();
}; };
const getPrivateIP = () => { const getHostNameOrIP = () => {
// Try to get the hostname first
const hostName = hostname();
if (hostName) return hostName;
const interfaces = networkInterfaces(); const interfaces = networkInterfaces();
for (const name of Object.keys(interfaces)) { for (const name of Object.keys(interfaces)) {
for (const iface of interfaces[name]) { for (const iface of interfaces[name]) {
// Find an IPv4 address that's not internal (like localhost)
if (iface.family === "IPv4" && !iface.internal) { if (iface.family === "IPv4" && !iface.internal) {
return iface.address; return iface.address;
} }
} }
} }
return "127.0.0.1"; return "127.0.0.1";
}; };
const createProductionTransport = (level, logStreamName, filters) => { const createProductionTransport = (level, logStreamName, filters) => {
return new WinstonCloudWatch({ return new WinstonCloudWatch({
level, level,
@@ -65,7 +65,7 @@ const createLogger = () => {
}); });
}; };
const hostname = process.env.HOSTNAME || getPrivateIP(); const hostname = process.env.HOSTNAME || getHostNameOrIP();
const getDevelopmentTransports = () => [ const getDevelopmentTransports = () => [
new winston.transports.Console({ new winston.transports.Console({
@@ -106,6 +106,12 @@ const createLogger = () => {
: [...getDevelopmentTransports(), ...getProductionTransports()] : [...getDevelopmentTransports(), ...getProductionTransports()]
}); });
if (isLocal) {
winstonLogger.debug(
`CloudWatch set to LocalStack end point: ${winstonCloudwatchTransportDefaults.awsOptions.endpoint}`
);
}
const log = (message, type, user, record, meta) => { const log = (message, type, user, record, meta) => {
winstonLogger.log({ winstonLogger.log({
level: type.toLowerCase(), level: type.toLowerCase(),