Skip to content

Commit

Permalink
Merge pull request #92 from osstotalsoft/feature/new-packages
Browse files Browse the repository at this point in the history
Use new packages for logging and dependencies
  • Loading branch information
alexandra-c committed Sep 20, 2022
2 parents 9f8b6a2 + 9fd07f4 commit 27aefab
Show file tree
Hide file tree
Showing 42 changed files with 294 additions and 387 deletions.
10 changes: 0 additions & 10 deletions __tests__/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,6 @@ describe('generator-graphql-rocket:app', () => {
assert.file(path.join(__dirname, `${tempRoot}/${projectName}/helm`))
}))

it('GraphQL logging plugin is added', () =>
helpers
.create(path.join(__dirname, '../generators/app'))
.inDir(path.join(__dirname, tempRoot))
.withPrompts(defaultAnswers)
.run()
.then(() => {
assert.fileContent(path.join(__dirname, `${tempRoot}/${projectName}/package.json`), `"@totalsoft/apollo-logger": `)
}))

it('Permissions and rights are ready to be used', () =>
helpers
.create(path.join(__dirname, '../generators/app'))
Expand Down
2 changes: 0 additions & 2 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ module.exports = class extends Generator {
if (dataLayer === 'knex' && withMultiTenancy)
ignoreFiles = concat(
[
'**/multiTenancy/tenantContextAccessor.js',
'**/multiTenancy/index.js',
'**/db/dbInstanceFactory.js',
'**/startup/middleware'
],
Expand Down
9 changes: 7 additions & 2 deletions generators/app/templates/infrastructure/.env
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ KNEX_LOGGING=true
KNEX_DEBUG=false
<%_}_%>

# DEBUG, ERROR, INFO
APOLLO_LOGGING_LEVEL=DEBUG
# trace, debug, info, warn, error, fatal
LOG_MIN_LEVEL=info
LOG_DATABASE="Server=servername,1433;Database=databasName;User Id=user;Password=pass"
LOG_DATABASE_MINLEVEL=info
LOG_DATABASE_ENABLED=true
LOG_OPENTRACING_MINLEVEL=info
LOG_OPENTRACING_ENABLED=true

IDENTITY_API_URL=
IDENTITY_AUTHORITY=
Expand Down
3 changes: 3 additions & 0 deletions generators/app/templates/infrastructure/.env.development
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ MultiTenancy__Tenants__tenant1__ConnectionStrings__MyDatabase__UserName=
MultiTenancy__Tenants__tenant1__ConnectionStrings__MyDatabase__Password=
MultiTenancy__Tenants__tenant1__TenantId=
<%_}_%>

LOG_MIN_LEVEL=debug
LOG_DATABASE_ENABLED=false
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ metadata:
<%_ if(addTracing){ _%>
{{- if $global.jaeger.enabled | and $global.jaeger.agentAutoInject }}
annotations:
sidecar.jaegertracing.io/inject: "true"
sidecar.jaegertracing.io/inject: "{{ $global.jaeger.agentAutoInject }}"
{{- end }}
<%_}_%>
spec:
Expand Down
3 changes: 1 addition & 2 deletions generators/app/templates/infrastructure/helm/gql/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ global:
<%_ if(addTracing){ _%>
jaeger:
enabled: true
agentAutoInject: false
agentAutoInject: "false"
agentHost: localhost
agentPort: 6832
agentImageTag: 1.16.0
Expand Down Expand Up @@ -100,7 +100,6 @@ gql:
<%_}_%>
IDENTITY_API_URL: "[IDENTITY_API_URI]"
IDENTITY_AUTHORITY: "[IDENTITY_AUTHORITY_URL]"
APOLLO_LOGGING_LEVEL: "ERROR"
<%_ if(dataLayer == "prisma"){ _%>
DATABASE_URL: "sqlserver://{server}:{port};database={database};user={user};password={password};trustServerCertificate=true"
<%_ if(withMultiTenancy && !hasSharedDb){ _%>
Expand Down
28 changes: 21 additions & 7 deletions generators/app/templates/infrastructure/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
"main": "src/index.js",
"type": "commonjs",
"engines": {
"node": ">=14.15.0",
"node": ">=16.0.0",
"<%=packageManager%>": ">= <%= packageManagerVersion %>"
},
"scripts": {
"postinstall": "npx sort-package-json",
"start": "cross-env NODE_ENV=development nodemon src/index.js",
"setcodepage": "run-script-os",
"setcodepage:linux": "",
"setcodepage:windows": "chcp 65001",
"start": "npm run setcodepage && npm run lint && cross-env NODE_ENV=development nodemon src/index.js",
"start:production": "cross-env NODE_ENV=production node src/index.js",
"test": "jest --collectCoverage --passWithNoTests",
"test:watchAll": "<%=packageManager%> run test -- --watchAll",
Expand Down Expand Up @@ -40,14 +43,20 @@
<%_} _%>
"@opentelemetry/exporter-prometheus": "^0.27.0",
"@opentelemetry/sdk-metrics-base": "^0.27.0",
"@totalsoft/key-per-file-configuration": "1.0.0",
"@totalsoft/key-per-file-configuration": "^1.1.0",
"@totalsoft/graceful-shutdown": "^1.1.0",
"@totalsoft/correlation": "^1.1.0",
"@totalsoft/pino-apollo": "^1.1.0",
"@totalsoft/pino-correlation": "^1.1.0",
"@totalsoft/pino-mssqlserver": "^1.1.0",
<%_ if(withMultiTenancy) {_%>
"object-path": "^0.11.8",
"koa-ignore": "^1.0.1",
<%_ if(addQuickStart) {_%>
"datasource-sql": "^2.0.1",
<%_}_%>
"@totalsoft/tenant-configuration": "1.0.0",
"@totalsoft/multitenancy-core": "^1.1.0",
"@totalsoft/pino-multitenancy": "^1.1.0",
<%_}_%>
<%_ if(dataLayer === "knex") {_%>
"dataloader": "^2.1.0",
Expand All @@ -62,7 +71,6 @@
"@totalsoft/message-bus": "^2.4.2",
"@totalsoft/messaging-host": "^2.4.2",
<%_}_%>
"@totalsoft/apollo-logger": "^1.0.7",
"apollo-datasource": "^3.3.2",
"apollo-datasource-rest": "^3.6.1",
"apollo-server": "^3.10.0",
Expand Down Expand Up @@ -91,6 +99,8 @@
"jaeger-client": "^3.19.0",
"opentracing": "^0.14.7",
"apollo-opentracing": "^2.1.76",
"@totalsoft/opentracing": "^1.1.0",
"@totalsoft/pino-opentracing": "^1.1.0",
<%_}_%>
"jsonwebtoken": "8.5.1",
"jwks-rsa": "^2.1.4",
Expand All @@ -102,7 +112,10 @@
"path": "^0.12.7",
"ramda": "^0.28.0",
"tedious": "^14.7.0",
"uuid": "^8.3.2"
"uuid": "^8.3.2",
"pino": "^7.6.3",
"pino-abstract-transport": "^1.0.0",
"pino-pretty": "^8.1.0"
},
"devDependencies": {
"cross-env": "7.0.3",
Expand All @@ -116,7 +129,8 @@
"jest-junit": "^14.0.0",
"lint-staged": "^13.0.3",
"nodemon": "^2.0.19",
"prettier": "^2.7.1"
"prettier": "^2.7.1",
"run-script-os": "^1.1.6"
},
"jest": {
"setupFilesAfterEnv": [
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { postProcessDbResponse, sanitizeConnectionInfo} = require("../utils/functions")
<%_ if(withMultiTenancy){ _%>
const { tenantConfiguration } = require('@totalsoft/tenant-configuration')
const { tenantConfiguration } = require('@totalsoft/multitenancy-core')
const isMultiTenant = JSON.parse(process.env.IS_MULTITENANT || 'false')
<%_}_%>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ const { Mutex } = require('async-mutex')
const mutex = new Mutex()
const { KNEX_LOGGING, KNEX_DEBUG } = process.env

const logger = (_format, duration, query) => {
console.log(`${duration} ${query}`)
const knexLogger = logger => (_format, duration, query) => {
logger.debug(`${duration} ${query}`)
}

let cachedDbInstance
const dbInstanceFactory = async () => {
const dbInstanceFactory = async ({ logger = console } = {}) => {
return await dbInstanceGetOrAdd(() => {
const {
DB_HOST: server,
Expand All @@ -39,7 +39,7 @@ const dbInstanceFactory = async () => {
}

if (JSON.parse(KNEX_LOGGING)) {
knexTinyLogger(dbInstance, { logger })
knexTinyLogger(dbInstance, { logger: knexLogger(logger) })
}
<%_ if(addTracing){ _%>
if (!JSON.parse(JAEGER_DISABLED)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const dbInstanceCache = new Map();
const mutex = new Mutex();
const { KNEX_LOGGING, KNEX_DEBUG } = process.env;

const logger = (_format, duration, query) => {
console.log(`${duration} ${query}`)
const knexLogger = logger => (_format, duration, query) => {
logger.debug(`${duration} ${query}`)
}

const tenantDbInstanceFactory = async tenantId => {
const tenantDbInstanceFactory = async (tenantId, { logger = console } = {}) => {

return await dbInstanceGetOrAdd(tenantId, async () => {
const dbConfig = await dbConfigService.getDbConfig(tenantId);
Expand All @@ -35,7 +35,7 @@ const tenantDbInstanceFactory = async tenantId => {
}

if (JSON.parse(KNEX_LOGGING)) {
knexTinyLogger(dbInstance, { logger });
knexTinyLogger(dbInstance, { logger: knexLogger(logger) })
}
<%_ if(addTracing){ _%>
if (!JSON.parse(JAEGER_DISABLED)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { tenantService } = require('@totalsoft/tenant-configuration')
const { tenantService } = require('@totalsoft/multitenancy-core')
const isMultiTenant = JSON.parse(process.env.IS_MULTITENANT || 'false')

const tenantResolvers = {
Expand Down
Loading

0 comments on commit 27aefab

Please sign in to comment.