Compare commits

...

22 Commits

Author SHA1 Message Date
standardci
6ba1867781 chore(release): publish new version
- @standardnotes/home-server@1.16.47
 - @standardnotes/revisions-server@1.43.4
 - @standardnotes/syncing-server@1.115.3
2023-10-10 12:30:01 +00:00
Karol Sójko
1026ce383c fix: add transition keyword to logs for better searching 2023-10-10 14:11:46 +02:00
standardci
2795cefc1b chore(release): publish new version
- @standardnotes/analytics@2.28.9
 - @standardnotes/api-gateway@1.78.6
 - @standardnotes/auth-server@1.155.1
 - @standardnotes/files-server@1.28.5
 - @standardnotes/home-server@1.16.46
 - @standardnotes/revisions-server@1.43.3
 - @standardnotes/scheduler-server@1.22.9
 - @standardnotes/websockets-server@1.14.5
2023-10-10 11:49:13 +00:00
Karol Sójko
637593c1bc fix(revisions): order by for identical created at date 2023-10-10 13:26:18 +02:00
Karol Sójko
08f7c5447b fix: opentelemetry instantiation 2023-10-10 13:19:51 +02:00
standardci
051b6e3093 chore(release): publish new version
- @standardnotes/home-server@1.16.45
 - @standardnotes/revisions-server@1.43.2
 - @standardnotes/syncing-server@1.115.2
2023-10-10 10:53:45 +00:00
Karol Sójko
250c1f069b fix(syncing-server): elevate otel sdk before the winston import 2023-10-10 12:32:20 +02:00
Karol Sójko
3e4a1e9645 fix(syncing-server): elevate otel sdk before the container starts 2023-10-10 12:25:09 +02:00
Karol Sójko
4629580650 fix(revisions): check for duplicates during transition 2023-10-10 12:10:45 +02:00
standardci
c29f6b9c6f chore(release): publish new version
- @standardnotes/home-server@1.16.44
 - @standardnotes/revisions-server@1.43.1
 - @standardnotes/syncing-server@1.115.1
2023-10-10 09:02:09 +00:00
Karol Sójko
036317e333 fix: transition logs to be more verbose 2023-10-10 10:44:58 +02:00
standardci
4afe32650f chore(release): publish new version
- @standardnotes/analytics@2.28.8
 - @standardnotes/api-gateway@1.78.5
 - @standardnotes/auth-server@1.155.0
 - @standardnotes/domain-events-infra@1.16.4
 - @standardnotes/event-store@1.12.18
 - @standardnotes/files-server@1.28.4
 - @standardnotes/home-server@1.16.43
 - @standardnotes/revisions-server@1.43.0
 - @standardnotes/scheduler-server@1.22.8
 - @standardnotes/syncing-server@1.115.0
 - @standardnotes/websockets-server@1.14.4
2023-10-10 06:32:17 +00:00
Karol Sójko
c021bb3d7c fix(syncing-server): add option to define otel ratio 2023-10-10 08:16:00 +02:00
Karol Sójko
783fd9e2c6 feat: add more logs to transition 2023-10-10 08:16:00 +02:00
standardci
d789c67649 chore(release): publish new version
- @standardnotes/analytics@2.28.7
 - @standardnotes/api-gateway@1.78.4
 - @standardnotes/auth-server@1.154.3
 - @standardnotes/domain-events-infra@1.16.3
 - @standardnotes/event-store@1.12.17
 - @standardnotes/files-server@1.28.3
 - @standardnotes/home-server@1.16.42
 - @standardnotes/revisions-server@1.42.3
 - @standardnotes/scheduler-server@1.22.7
 - @standardnotes/syncing-server@1.114.3
 - @standardnotes/websockets-server@1.14.3
2023-10-09 18:10:27 +00:00
Karol Sójko
3ab29569db fix(syncing-server): add opentelemetry starting info in logs 2023-10-09 19:50:02 +02:00
Karol Sójko
099c6e10c6 fix(domain-events-infra): add parent context on internal span 2023-10-09 19:38:35 +02:00
Karol Sójko
76ae6f5a88 Revert "Revert "fix: setting parent span on workers""
This reverts commit 3fc07a5b60.
2023-10-09 19:13:43 +02:00
standardci
9bd2b0c953 chore(release): publish new version
- @standardnotes/analytics@2.28.6
 - @standardnotes/api-gateway@1.78.3
 - @standardnotes/auth-server@1.154.2
 - @standardnotes/domain-events-infra@1.16.2
 - @standardnotes/event-store@1.12.16
 - @standardnotes/files-server@1.28.2
 - @standardnotes/home-server@1.16.41
 - @standardnotes/revisions-server@1.42.2
 - @standardnotes/scheduler-server@1.22.6
 - @standardnotes/syncing-server@1.114.2
 - @standardnotes/websockets-server@1.14.2
2023-10-09 14:04:36 +00:00
Karol Sójko
3fc07a5b60 Revert "fix: setting parent span on workers"
This reverts commit 1c54d18c3c.
2023-10-09 15:46:10 +02:00
standardci
94e18ab36b chore(release): publish new version
- @standardnotes/analytics@2.28.5
 - @standardnotes/api-gateway@1.78.2
 - @standardnotes/auth-server@1.154.1
 - @standardnotes/domain-events-infra@1.16.1
 - @standardnotes/event-store@1.12.15
 - @standardnotes/files-server@1.28.1
 - @standardnotes/home-server@1.16.40
 - @standardnotes/revisions-server@1.42.1
 - @standardnotes/scheduler-server@1.22.5
 - @standardnotes/syncing-server@1.114.1
 - @standardnotes/websockets-server@1.14.1
2023-10-09 13:30:07 +00:00
Karol Sójko
1c54d18c3c fix: setting parent span on workers 2023-10-09 15:13:07 +02:00
60 changed files with 666 additions and 228 deletions

View File

@@ -3,6 +3,28 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [2.28.9](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.28.8...@standardnotes/analytics@2.28.9) (2023-10-10)
### Bug Fixes
* opentelemetry instantiation ([08f7c54](https://github.com/standardnotes/server/commit/08f7c5447b020fee71a1e49d382db32082bb9044))
## [2.28.8](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.28.7...@standardnotes/analytics@2.28.8) (2023-10-10)
**Note:** Version bump only for package @standardnotes/analytics
## [2.28.7](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.28.6...@standardnotes/analytics@2.28.7) (2023-10-09)
**Note:** Version bump only for package @standardnotes/analytics
## [2.28.6](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.28.5...@standardnotes/analytics@2.28.6) (2023-10-09)
**Note:** Version bump only for package @standardnotes/analytics
## [2.28.5](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.28.4...@standardnotes/analytics@2.28.5) (2023-10-09)
**Note:** Version bump only for package @standardnotes/analytics
## [2.28.4](https://github.com/standardnotes/server/compare/@standardnotes/analytics@2.28.3...@standardnotes/analytics@2.28.4) (2023-10-09)
**Note:** Version bump only for package @standardnotes/analytics

View File

@@ -1,5 +1,11 @@
import 'reflect-metadata'
import { OpenTelemetrySDK } from '@standardnotes/domain-events-infra'
import { ServiceIdentifier } from '@standardnotes/domain-core'
const sdk = new OpenTelemetrySDK(ServiceIdentifier.NAMES.AnalyticsWorker)
sdk.start()
import { Logger } from 'winston'
import { DomainEventSubscriberFactoryInterface } from '@standardnotes/domain-events'
import * as dayjs from 'dayjs'

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/analytics",
"version": "2.28.4",
"version": "2.28.9",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -6,7 +6,7 @@ import {
DomainEventMessageHandlerInterface,
DomainEventSubscriberFactoryInterface,
} from '@standardnotes/domain-events'
import { MapperInterface } from '@standardnotes/domain-core'
import { MapperInterface, ServiceIdentifier } from '@standardnotes/domain-core'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Mixpanel = require('mixpanel')
@@ -17,7 +17,7 @@ import { DomainEventFactory } from '../Domain/Event/DomainEventFactory'
import {
SNSDomainEventPublisher,
SQSDomainEventSubscriberFactory,
SQSEventMessageHandler,
SQSOpenTelemetryEventMessageHandler,
} from '@standardnotes/domain-events-infra'
import { Timer, TimerInterface } from '@standardnotes/time'
import { PeriodKeyGeneratorInterface } from '../Domain/Time/PeriodKeyGeneratorInterface'
@@ -243,7 +243,13 @@ export class ContainerConfigLoader {
container
.bind<DomainEventMessageHandlerInterface>(TYPES.DomainEventMessageHandler)
.toConstantValue(new SQSEventMessageHandler(eventHandlers, container.get(TYPES.Logger)))
.toConstantValue(
new SQSOpenTelemetryEventMessageHandler(
ServiceIdentifier.NAMES.AnalyticsWorker,
eventHandlers,
container.get(TYPES.Logger),
),
)
container
.bind<DomainEventSubscriberFactoryInterface>(TYPES.DomainEventSubscriberFactory)
.toConstantValue(

View File

@@ -3,6 +3,28 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.78.6](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.78.5...@standardnotes/api-gateway@1.78.6) (2023-10-10)
### Bug Fixes
* opentelemetry instantiation ([08f7c54](https://github.com/standardnotes/api-gateway/commit/08f7c5447b020fee71a1e49d382db32082bb9044))
## [1.78.5](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.78.4...@standardnotes/api-gateway@1.78.5) (2023-10-10)
**Note:** Version bump only for package @standardnotes/api-gateway
## [1.78.4](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.78.3...@standardnotes/api-gateway@1.78.4) (2023-10-09)
**Note:** Version bump only for package @standardnotes/api-gateway
## [1.78.3](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.78.2...@standardnotes/api-gateway@1.78.3) (2023-10-09)
**Note:** Version bump only for package @standardnotes/api-gateway
## [1.78.2](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.78.1...@standardnotes/api-gateway@1.78.2) (2023-10-09)
**Note:** Version bump only for package @standardnotes/api-gateway
## [1.78.1](https://github.com/standardnotes/api-gateway/compare/@standardnotes/api-gateway@1.78.0...@standardnotes/api-gateway@1.78.1) (2023-10-09)
**Note:** Version bump only for package @standardnotes/api-gateway

View File

@@ -1,5 +1,11 @@
import 'reflect-metadata'
import { OpenTelemetrySDK } from '@standardnotes/domain-events-infra'
import { ServiceIdentifier } from '@standardnotes/domain-core'
const sdk = new OpenTelemetrySDK(ServiceIdentifier.NAMES.ApiGateway)
sdk.start()
import '../src/Controller/LegacyController'
import '../src/Controller/HealthCheckController'
@@ -36,7 +42,6 @@ import { InversifyExpressServer } from 'inversify-express-utils'
import { ContainerConfigLoader } from '../src/Bootstrap/Container'
import { TYPES } from '../src/Bootstrap/Types'
import { Env } from '../src/Bootstrap/Env'
import { OpenTelemetrySDKInterface } from '@standardnotes/domain-events-infra'
const container = new ContainerConfigLoader()
void container.load().then((container) => {
@@ -105,11 +110,6 @@ void container.load().then((container) => {
const serverInstance = server.build()
if (!container.get<boolean>(TYPES.ApiGateway_IS_CONFIGURED_FOR_HOME_SERVER_OR_SELF_HOSTING)) {
const openTelemetrySDK = container.get<OpenTelemetrySDKInterface>(TYPES.ApiGateway_OpenTelemetrySDK)
openTelemetrySDK.start()
}
serverInstance.listen(env.get('PORT'))
logger.info(`Server started on port ${process.env.PORT}`)

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/api-gateway",
"version": "1.78.1",
"version": "1.78.6",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -16,13 +16,12 @@ import { RedisCrossServiceTokenCache } from '../Infra/Redis/RedisCrossServiceTok
import { WebSocketAuthMiddleware } from '../Controller/WebSocketAuthMiddleware'
import { InMemoryCrossServiceTokenCache } from '../Infra/InMemory/InMemoryCrossServiceTokenCache'
import { DirectCallServiceProxy } from '../Service/Proxy/DirectCallServiceProxy'
import { ServiceContainerInterface, ServiceIdentifier } from '@standardnotes/domain-core'
import { ServiceContainerInterface } from '@standardnotes/domain-core'
import { EndpointResolverInterface } from '../Service/Resolver/EndpointResolverInterface'
import { EndpointResolver } from '../Service/Resolver/EndpointResolver'
import { RequiredCrossServiceTokenMiddleware } from '../Controller/RequiredCrossServiceTokenMiddleware'
import { OptionalCrossServiceTokenMiddleware } from '../Controller/OptionalCrossServiceTokenMiddleware'
import { Transform } from 'stream'
import { OpenTelemetrySDK, OpenTelemetrySDKInterface } from '@standardnotes/domain-events-infra'
export class ContainerConfigLoader {
async load(configuration?: {
@@ -44,12 +43,6 @@ export class ContainerConfigLoader {
.bind<boolean>(TYPES.ApiGateway_IS_CONFIGURED_FOR_HOME_SERVER_OR_SELF_HOSTING)
.toConstantValue(isConfiguredForHomeServerOrSelfHosting)
if (!isConfiguredForHomeServerOrSelfHosting) {
container
.bind<OpenTelemetrySDKInterface>(TYPES.ApiGateway_OpenTelemetrySDK)
.toConstantValue(new OpenTelemetrySDK(ServiceIdentifier.NAMES.ApiGateway))
}
const winstonFormatters = [winston.format.splat(), winston.format.json()]
if (env.get('NEW_RELIC_ENABLED', true) === 'true') {
await import('newrelic')

View File

@@ -28,5 +28,4 @@ export const TYPES = {
ApiGateway_CrossServiceTokenCache: Symbol.for('ApiGateway_CrossServiceTokenCache'),
ApiGateway_Timer: Symbol.for('ApiGateway_Timer'),
ApiGateway_EndpointResolver: Symbol.for('ApiGateway_EndpointResolver'),
ApiGateway_OpenTelemetrySDK: Symbol.for('ApiGateway_OpenTelemetrySDK'),
}

View File

@@ -3,6 +3,36 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.155.1](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.155.0...@standardnotes/auth-server@1.155.1) (2023-10-10)
### Bug Fixes
* opentelemetry instantiation ([08f7c54](https://github.com/standardnotes/server/commit/08f7c5447b020fee71a1e49d382db32082bb9044))
# [1.155.0](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.154.3...@standardnotes/auth-server@1.155.0) (2023-10-10)
### Features
* add more logs to transition ([783fd9e](https://github.com/standardnotes/server/commit/783fd9e2c6350a7f0f1e8d009d01a3328564aca0))
## [1.154.3](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.154.2...@standardnotes/auth-server@1.154.3) (2023-10-09)
### Reverts
* Revert "Revert "fix: setting parent span on workers"" ([76ae6f5](https://github.com/standardnotes/server/commit/76ae6f5a882a82ab5f635452e3bc7b2b16709531))
## [1.154.2](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.154.1...@standardnotes/auth-server@1.154.2) (2023-10-09)
### Reverts
* Revert "fix: setting parent span on workers" ([3fc07a5](https://github.com/standardnotes/server/commit/3fc07a5b60c26b583efd88e8a80d4c4321e71efb))
## [1.154.1](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.154.0...@standardnotes/auth-server@1.154.1) (2023-10-09)
### Bug Fixes
* setting parent span on workers ([1c54d18](https://github.com/standardnotes/server/commit/1c54d18c3ca75353701ba921492a5ecfaa2e3572))
# [1.154.0](https://github.com/standardnotes/server/compare/@standardnotes/auth-server@1.153.0...@standardnotes/auth-server@1.154.0) (2023-10-09)
### Features

View File

@@ -1,5 +1,11 @@
import 'reflect-metadata'
import { OpenTelemetrySDK } from '@standardnotes/domain-events-infra'
import { ServiceIdentifier } from '@standardnotes/domain-core'
const sdk = new OpenTelemetrySDK(ServiceIdentifier.NAMES.Auth)
sdk.start()
import '../src/Infra/InversifyExpressUtils/AnnotatedAuthController'
import '../src/Infra/InversifyExpressUtils/AnnotatedAuthenticatorsController'
import '../src/Infra/InversifyExpressUtils/AnnotatedSessionsController'
@@ -29,7 +35,6 @@ import { InversifyExpressServer } from 'inversify-express-utils'
import { ContainerConfigLoader } from '../src/Bootstrap/Container'
import TYPES from '../src/Bootstrap/Types'
import { Env } from '../src/Bootstrap/Env'
import { OpenTelemetrySDKInterface } from '@standardnotes/domain-events-infra'
const container = new ContainerConfigLoader()
void container.load().then((container) => {
@@ -67,11 +72,6 @@ void container.load().then((container) => {
const serverInstance = server.build()
if (!container.get<boolean>(TYPES.Auth_IS_CONFIGURED_FOR_HOME_SERVER_OR_SELF_HOSTING)) {
const openTelemetrySDK = container.get<OpenTelemetrySDKInterface>(TYPES.Auth_OpenTelemetrySDK)
openTelemetrySDK.start()
}
serverInstance.listen(env.get('PORT'))
logger.info(`Server started on port ${process.env.PORT}`)

View File

@@ -17,6 +17,7 @@ import { RoleName, TransitionStatus } from '@standardnotes/domain-core'
const inputArgs = process.argv.slice(2)
const startDateString = inputArgs[0]
const endDateString = inputArgs[1]
const forceRunParam = inputArgs[2]
const requestTransition = async (
transitionStatusRepository: TransitionStatusRepositoryInterface,
@@ -38,6 +39,7 @@ const requestTransition = async (
)
let usersTriggered = 0
const forceRun = forceRunParam === 'true'
for (const user of users) {
const itemsTransitionStatus = await transitionStatusRepository.getStatus(user.uuid, 'items')
const revisionsTransitionStatus = await transitionStatusRepository.getStatus(user.uuid, 'revisions')
@@ -55,7 +57,11 @@ const requestTransition = async (
let wasTransitionRequested = false
if (itemsTransitionStatus === null || itemsTransitionStatus.value === TransitionStatus.STATUSES.Failed) {
if (
itemsTransitionStatus === null ||
itemsTransitionStatus.value === TransitionStatus.STATUSES.Failed ||
(itemsTransitionStatus.value === TransitionStatus.STATUSES.InProgress && forceRun)
) {
wasTransitionRequested = true
await transitionStatusRepository.remove(user.uuid, 'items')
@@ -68,7 +74,11 @@ const requestTransition = async (
)
}
if (revisionsTransitionStatus === null || revisionsTransitionStatus.value === TransitionStatus.STATUSES.Failed) {
if (
revisionsTransitionStatus === null ||
revisionsTransitionStatus.value === TransitionStatus.STATUSES.Failed ||
(revisionsTransitionStatus.value === TransitionStatus.STATUSES.InProgress && forceRun)
) {
wasTransitionRequested = true
await transitionStatusRepository.remove(user.uuid, 'revisions')

View File

@@ -1,5 +1,11 @@
import 'reflect-metadata'
import { OpenTelemetrySDK } from '@standardnotes/domain-events-infra'
import { ServiceIdentifier } from '@standardnotes/domain-core'
const sdk = new OpenTelemetrySDK(ServiceIdentifier.NAMES.AuthWorker)
sdk.start()
import { Logger } from 'winston'
import { ContainerConfigLoader } from '../src/Bootstrap/Container'
@@ -8,7 +14,6 @@ import { Env } from '../src/Bootstrap/Env'
import { DomainEventSubscriberFactoryInterface } from '@standardnotes/domain-events'
import * as dayjs from 'dayjs'
import * as utc from 'dayjs/plugin/utc'
import { OpenTelemetrySDKInterface } from '@standardnotes/domain-events-infra'
const container = new ContainerConfigLoader('worker')
void container.load().then((container) => {
@@ -21,11 +26,6 @@ void container.load().then((container) => {
logger.info('Starting worker...')
if (!container.get<boolean>(TYPES.Auth_IS_CONFIGURED_FOR_HOME_SERVER_OR_SELF_HOSTING)) {
const openTelemetrySDK = container.get<OpenTelemetrySDKInterface>(TYPES.Auth_OpenTelemetrySDK)
openTelemetrySDK.start()
}
const subscriberFactory: DomainEventSubscriberFactoryInterface = container.get(
TYPES.Auth_DomainEventSubscriberFactory,
)

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/auth-server",
"version": "1.154.0",
"version": "1.155.1",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -89,8 +89,6 @@ import { ExtensionKeyGrantedEventHandler } from '../Domain/Handler/ExtensionKeyG
import {
DirectCallDomainEventPublisher,
DirectCallEventMessageHandler,
OpenTelemetrySDK,
OpenTelemetrySDKInterface,
SNSDomainEventPublisher,
SQSDomainEventSubscriberFactory,
SQSEventMessageHandler,
@@ -331,16 +329,6 @@ export class ContainerConfigLoader {
.bind<boolean>(TYPES.Auth_IS_CONFIGURED_FOR_HOME_SERVER_OR_SELF_HOSTING)
.toConstantValue(isConfiguredForHomeServerOrSelfHosting)
if (!isConfiguredForHomeServerOrSelfHosting) {
container
.bind<OpenTelemetrySDKInterface>(TYPES.Auth_OpenTelemetrySDK)
.toConstantValue(
new OpenTelemetrySDK(
this.mode === 'server' ? ServiceIdentifier.NAMES.Auth : ServiceIdentifier.NAMES.AuthWorker,
),
)
}
if (!isConfiguredForInMemoryCache) {
const redisUrl = env.get('REDIS_URL')
const isRedisInClusterMode = redisUrl.indexOf(',') > 0
@@ -1246,7 +1234,11 @@ export class ContainerConfigLoader {
.toConstantValue(
isConfiguredForHomeServerOrSelfHosting
? new SQSEventMessageHandler(eventHandlers, container.get(TYPES.Auth_Logger))
: new SQSOpenTelemetryEventMessageHandler(eventHandlers, container.get(TYPES.Auth_Logger)),
: new SQSOpenTelemetryEventMessageHandler(
ServiceIdentifier.NAMES.AuthWorker,
eventHandlers,
container.get(TYPES.Auth_Logger),
),
)
container

View File

@@ -3,7 +3,6 @@ const TYPES = {
Auth_Redis: Symbol.for('Auth_Redis'),
Auth_SNS: Symbol.for('Auth_SNS'),
Auth_SQS: Symbol.for('Auth_SQS'),
Auth_OpenTelemetrySDK: Symbol.for('Auth_OpenTelemetrySDK'),
// Mapping
Auth_SessionTracePersistenceMapper: Symbol.for('Auth_SessionTracePersistenceMapper'),
Auth_AuthenticatorChallengePersistenceMapper: Symbol.for('Auth_AuthenticatorChallengePersistenceMapper'),

View File

@@ -3,6 +3,34 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.16.4](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.16.3...@standardnotes/domain-events-infra@1.16.4) (2023-10-10)
### Bug Fixes
* **syncing-server:** add option to define otel ratio ([c021bb3](https://github.com/standardnotes/server/commit/c021bb3d7ca90179292e7c75f5a84bf2b941ce86))
## [1.16.3](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.16.2...@standardnotes/domain-events-infra@1.16.3) (2023-10-09)
### Bug Fixes
* **domain-events-infra:** add parent context on internal span ([099c6e1](https://github.com/standardnotes/server/commit/099c6e10c69b6b81006f59bcdb35325b545ab39c))
### Reverts
* Revert "Revert "fix: setting parent span on workers"" ([76ae6f5](https://github.com/standardnotes/server/commit/76ae6f5a882a82ab5f635452e3bc7b2b16709531))
## [1.16.2](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.16.1...@standardnotes/domain-events-infra@1.16.2) (2023-10-09)
### Reverts
* Revert "fix: setting parent span on workers" ([3fc07a5](https://github.com/standardnotes/server/commit/3fc07a5b60c26b583efd88e8a80d4c4321e71efb))
## [1.16.1](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.16.0...@standardnotes/domain-events-infra@1.16.1) (2023-10-09)
### Bug Fixes
* setting parent span on workers ([1c54d18](https://github.com/standardnotes/server/commit/1c54d18c3ca75353701ba921492a5ecfaa2e3572))
# [1.16.0](https://github.com/standardnotes/server/compare/@standardnotes/domain-events-infra@1.15.0...@standardnotes/domain-events-infra@1.16.0) (2023-10-09)
### Features

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/domain-events-infra",
"version": "1.16.0",
"version": "1.16.4",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -17,7 +17,10 @@ import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express'
export class OpenTelemetrySDK implements OpenTelemetrySDKInterface {
private declare sdk: OpenTelemetrySDKNode.NodeSDK
constructor(private serviceName: string) {
constructor(
private serviceName: string,
private spanRatio?: number,
) {
this.build()
}
@@ -41,8 +44,10 @@ export class OpenTelemetrySDK implements OpenTelemetrySDKInterface {
},
})
const ratio = this.spanRatio ?? 0.01
this.sdk = new OpenTelemetrySDKNode.NodeSDK({
sampler: new OpenTelemetrySDKNode.tracing.TraceIdRatioBasedSampler(0.01),
sampler: new OpenTelemetrySDKNode.tracing.TraceIdRatioBasedSampler(ratio),
textMapPropagator: new AWSXRayPropagator(),
instrumentations: [
new HttpInstrumentation({

View File

@@ -9,8 +9,10 @@ import {
export class SQSOpenTelemetryEventMessageHandler implements DomainEventMessageHandlerInterface {
private currentSpan: OpenTelemetryApi.Span | undefined
private internalSpan: OpenTelemetryApi.Span | undefined
constructor(
private serviceName: string,
private handlers: Map<string, DomainEventHandlerInterface>,
private logger: Logger,
) {}
@@ -35,18 +37,29 @@ export class SQSOpenTelemetryEventMessageHandler implements DomainEventMessageHa
const tracer = OpenTelemetryApi.trace.getTracer('sqs-handler')
this.currentSpan = tracer.startSpan(domainEvent.type)
this.currentSpan = tracer.startSpan(this.serviceName, { kind: OpenTelemetryApi.SpanKind.CONSUMER })
const ctx = OpenTelemetryApi.trace.setSpan(OpenTelemetryApi.context.active(), this.currentSpan)
this.internalSpan = tracer.startSpan(domainEvent.type, { kind: OpenTelemetryApi.SpanKind.INTERNAL }, ctx)
await handler.handle(domainEvent)
this.internalSpan.end()
this.currentSpan.end()
this.internalSpan = undefined
this.currentSpan = undefined
}
async handleError(error: Error): Promise<void> {
if (this.internalSpan) {
this.internalSpan.recordException(error)
this.internalSpan.end()
this.internalSpan = undefined
}
if (this.currentSpan) {
this.currentSpan.recordException(error)
this.currentSpan.end()
this.currentSpan = undefined
}

View File

@@ -3,6 +3,22 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.12.18](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.12.17...@standardnotes/event-store@1.12.18) (2023-10-10)
**Note:** Version bump only for package @standardnotes/event-store
## [1.12.17](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.12.16...@standardnotes/event-store@1.12.17) (2023-10-09)
**Note:** Version bump only for package @standardnotes/event-store
## [1.12.16](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.12.15...@standardnotes/event-store@1.12.16) (2023-10-09)
**Note:** Version bump only for package @standardnotes/event-store
## [1.12.15](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.12.14...@standardnotes/event-store@1.12.15) (2023-10-09)
**Note:** Version bump only for package @standardnotes/event-store
## [1.12.14](https://github.com/standardnotes/server/compare/@standardnotes/event-store@1.12.13...@standardnotes/event-store@1.12.14) (2023-10-09)
**Note:** Version bump only for package @standardnotes/event-store

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/event-store",
"version": "1.12.14",
"version": "1.12.18",
"description": "Event Store Service",
"private": true,
"main": "dist/src/index.js",

View File

@@ -3,6 +3,34 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.28.5](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.28.4...@standardnotes/files-server@1.28.5) (2023-10-10)
### Bug Fixes
* opentelemetry instantiation ([08f7c54](https://github.com/standardnotes/files/commit/08f7c5447b020fee71a1e49d382db32082bb9044))
## [1.28.4](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.28.3...@standardnotes/files-server@1.28.4) (2023-10-10)
**Note:** Version bump only for package @standardnotes/files-server
## [1.28.3](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.28.2...@standardnotes/files-server@1.28.3) (2023-10-09)
### Reverts
* Revert "Revert "fix: setting parent span on workers"" ([76ae6f5](https://github.com/standardnotes/files/commit/76ae6f5a882a82ab5f635452e3bc7b2b16709531))
## [1.28.2](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.28.1...@standardnotes/files-server@1.28.2) (2023-10-09)
### Reverts
* Revert "fix: setting parent span on workers" ([3fc07a5](https://github.com/standardnotes/files/commit/3fc07a5b60c26b583efd88e8a80d4c4321e71efb))
## [1.28.1](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.28.0...@standardnotes/files-server@1.28.1) (2023-10-09)
### Bug Fixes
* setting parent span on workers ([1c54d18](https://github.com/standardnotes/files/commit/1c54d18c3ca75353701ba921492a5ecfaa2e3572))
# [1.28.0](https://github.com/standardnotes/files/compare/@standardnotes/files-server@1.27.0...@standardnotes/files-server@1.28.0) (2023-10-09)
### Features

View File

@@ -1,5 +1,11 @@
import 'reflect-metadata'
import { OpenTelemetrySDK } from '@standardnotes/domain-events-infra'
import { ServiceIdentifier } from '@standardnotes/domain-core'
const sdk = new OpenTelemetrySDK(ServiceIdentifier.NAMES.Files)
sdk.start()
import * as busboy from 'connect-busboy'
import '../src/Infra/InversifyExpress/AnnotatedHealthCheckController'
@@ -17,7 +23,6 @@ import { InversifyExpressServer } from 'inversify-express-utils'
import { ContainerConfigLoader } from '../src/Bootstrap/Container'
import TYPES from '../src/Bootstrap/Types'
import { Env } from '../src/Bootstrap/Env'
import { OpenTelemetrySDKInterface } from '@standardnotes/domain-events-infra'
const container = new ContainerConfigLoader()
void container.load().then((container) => {
@@ -91,11 +96,6 @@ void container.load().then((container) => {
const serverInstance = server.build()
if (!container.get<boolean>(TYPES.Files_IS_CONFIGURED_FOR_HOME_SERVER_OR_SELF_HOSTING)) {
const openTelemetrySDK = container.get<OpenTelemetrySDKInterface>(TYPES.Files_OpenTelemetrySDK)
openTelemetrySDK.start()
}
serverInstance.listen(env.get('PORT'))
logger.info(`Server started on port ${process.env.PORT}`)

View File

@@ -1,5 +1,11 @@
import 'reflect-metadata'
import { OpenTelemetrySDK } from '@standardnotes/domain-events-infra'
import { ServiceIdentifier } from '@standardnotes/domain-core'
const sdk = new OpenTelemetrySDK(ServiceIdentifier.NAMES.FilesWorker)
sdk.start()
import { Logger } from 'winston'
import { ContainerConfigLoader } from '../src/Bootstrap/Container'
@@ -8,9 +14,8 @@ import { Env } from '../src/Bootstrap/Env'
import { DomainEventSubscriberFactoryInterface } from '@standardnotes/domain-events'
import * as dayjs from 'dayjs'
import * as utc from 'dayjs/plugin/utc'
import { OpenTelemetrySDKInterface } from '@standardnotes/domain-events-infra'
const container = new ContainerConfigLoader('worker')
const container = new ContainerConfigLoader()
void container.load().then((container) => {
dayjs.extend(utc)
@@ -21,11 +26,6 @@ void container.load().then((container) => {
logger.info('Starting worker...')
if (!container.get<boolean>(TYPES.Files_IS_CONFIGURED_FOR_HOME_SERVER_OR_SELF_HOSTING)) {
const openTelemetrySDK = container.get<OpenTelemetrySDKInterface>(TYPES.Files_OpenTelemetrySDK)
openTelemetrySDK.start()
}
const subscriberFactory: DomainEventSubscriberFactoryInterface = container.get(
TYPES.Files_DomainEventSubscriberFactory,
)

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/files-server",
"version": "1.28.0",
"version": "1.28.5",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -16,8 +16,6 @@ import { DomainEventFactory } from '../Domain/Event/DomainEventFactory'
import {
DirectCallDomainEventPublisher,
DirectCallEventMessageHandler,
OpenTelemetrySDK,
OpenTelemetrySDKInterface,
SNSDomainEventPublisher,
SQSDomainEventSubscriberFactory,
SQSEventMessageHandler,
@@ -58,8 +56,6 @@ import { SharedVaultValetTokenAuthMiddleware } from '../Infra/InversifyExpress/M
import { ServiceIdentifier } from '@standardnotes/domain-core'
export class ContainerConfigLoader {
constructor(private mode: 'server' | 'worker' = 'server') {}
async load(configuration?: {
directCallDomainEventPublisher?: DirectCallDomainEventPublisher
logger?: Transform
@@ -96,16 +92,6 @@ export class ContainerConfigLoader {
.bind<boolean>(TYPES.Files_IS_CONFIGURED_FOR_HOME_SERVER_OR_SELF_HOSTING)
.toConstantValue(isConfiguredForHomeServerOrSelfHosting)
if (!isConfiguredForHomeServerOrSelfHosting) {
container
.bind<OpenTelemetrySDKInterface>(TYPES.Files_OpenTelemetrySDK)
.toConstantValue(
new OpenTelemetrySDK(
this.mode === 'server' ? ServiceIdentifier.NAMES.Files : ServiceIdentifier.NAMES.FilesWorker,
),
)
}
let logger: winston.Logger
if (configuration?.logger) {
logger = configuration.logger as winston.Logger
@@ -316,7 +302,11 @@ export class ContainerConfigLoader {
.toConstantValue(
isConfiguredForHomeServerOrSelfHosting
? new SQSEventMessageHandler(eventHandlers, container.get(TYPES.Files_Logger))
: new SQSOpenTelemetryEventMessageHandler(eventHandlers, container.get(TYPES.Files_Logger)),
: new SQSOpenTelemetryEventMessageHandler(
ServiceIdentifier.NAMES.FilesWorker,
eventHandlers,
container.get(TYPES.Files_Logger),
),
)
container
.bind<DomainEventSubscriberFactoryInterface>(TYPES.Files_DomainEventSubscriberFactory)

View File

@@ -5,7 +5,6 @@ const TYPES = {
Files_S3: Symbol.for('Files_S3'),
Files_SNS: Symbol.for('Files_SNS'),
Files_SQS: Symbol.for('Files_SQS'),
Files_OpenTelemetrySDK: Symbol.for('Files_OpenTelemetrySDK'),
// use cases
Files_UploadFileChunk: Symbol.for('Files_UploadFileChunk'),

View File

@@ -3,6 +3,38 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.16.47](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.16.46...@standardnotes/home-server@1.16.47) (2023-10-10)
**Note:** Version bump only for package @standardnotes/home-server
## [1.16.46](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.16.45...@standardnotes/home-server@1.16.46) (2023-10-10)
**Note:** Version bump only for package @standardnotes/home-server
## [1.16.45](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.16.44...@standardnotes/home-server@1.16.45) (2023-10-10)
**Note:** Version bump only for package @standardnotes/home-server
## [1.16.44](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.16.43...@standardnotes/home-server@1.16.44) (2023-10-10)
**Note:** Version bump only for package @standardnotes/home-server
## [1.16.43](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.16.42...@standardnotes/home-server@1.16.43) (2023-10-10)
**Note:** Version bump only for package @standardnotes/home-server
## [1.16.42](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.16.41...@standardnotes/home-server@1.16.42) (2023-10-09)
**Note:** Version bump only for package @standardnotes/home-server
## [1.16.41](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.16.40...@standardnotes/home-server@1.16.41) (2023-10-09)
**Note:** Version bump only for package @standardnotes/home-server
## [1.16.40](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.16.39...@standardnotes/home-server@1.16.40) (2023-10-09)
**Note:** Version bump only for package @standardnotes/home-server
## [1.16.39](https://github.com/standardnotes/server/compare/@standardnotes/home-server@1.16.38...@standardnotes/home-server@1.16.39) (2023-10-09)
**Note:** Version bump only for package @standardnotes/home-server

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/home-server",
"version": "1.16.39",
"version": "1.16.47",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -3,6 +3,55 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.43.4](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.43.3...@standardnotes/revisions-server@1.43.4) (2023-10-10)
### Bug Fixes
* add transition keyword to logs for better searching ([1026ce3](https://github.com/standardnotes/server/commit/1026ce383c178086400bfe5a46e520e18b54e1bc))
## [1.43.3](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.43.2...@standardnotes/revisions-server@1.43.3) (2023-10-10)
### Bug Fixes
* opentelemetry instantiation ([08f7c54](https://github.com/standardnotes/server/commit/08f7c5447b020fee71a1e49d382db32082bb9044))
* **revisions:** order by for identical created at date ([637593c](https://github.com/standardnotes/server/commit/637593c1bcd0fb3ae35586c79bb044cb24b37c6b))
## [1.43.2](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.43.1...@standardnotes/revisions-server@1.43.2) (2023-10-10)
### Bug Fixes
* **revisions:** check for duplicates during transition ([4629580](https://github.com/standardnotes/server/commit/4629580650f2b70e736ed4464b311241c563074c))
## [1.43.1](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.43.0...@standardnotes/revisions-server@1.43.1) (2023-10-10)
### Bug Fixes
* transition logs to be more verbose ([036317e](https://github.com/standardnotes/server/commit/036317e33347f121fa799cbd409f85759798369d))
# [1.43.0](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.42.3...@standardnotes/revisions-server@1.43.0) (2023-10-10)
### Features
* add more logs to transition ([783fd9e](https://github.com/standardnotes/server/commit/783fd9e2c6350a7f0f1e8d009d01a3328564aca0))
## [1.42.3](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.42.2...@standardnotes/revisions-server@1.42.3) (2023-10-09)
### Reverts
* Revert "Revert "fix: setting parent span on workers"" ([76ae6f5](https://github.com/standardnotes/server/commit/76ae6f5a882a82ab5f635452e3bc7b2b16709531))
## [1.42.2](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.42.1...@standardnotes/revisions-server@1.42.2) (2023-10-09)
### Reverts
* Revert "fix: setting parent span on workers" ([3fc07a5](https://github.com/standardnotes/server/commit/3fc07a5b60c26b583efd88e8a80d4c4321e71efb))
## [1.42.1](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.42.0...@standardnotes/revisions-server@1.42.1) (2023-10-09)
### Bug Fixes
* setting parent span on workers ([1c54d18](https://github.com/standardnotes/server/commit/1c54d18c3ca75353701ba921492a5ecfaa2e3572))
# [1.42.0](https://github.com/standardnotes/server/compare/@standardnotes/revisions-server@1.41.0...@standardnotes/revisions-server@1.42.0) (2023-10-09)
### Features

View File

@@ -1,5 +1,11 @@
import 'reflect-metadata'
import { OpenTelemetrySDK } from '@standardnotes/domain-events-infra'
import { ServiceIdentifier } from '@standardnotes/domain-core'
const sdk = new OpenTelemetrySDK(ServiceIdentifier.NAMES.Revisions)
sdk.start()
import * as cors from 'cors'
import { urlencoded, json, Request, Response, NextFunction } from 'express'
import * as winston from 'winston'
@@ -11,7 +17,6 @@ import { ContainerConfigLoader } from '../src/Bootstrap/Container'
import '../src/Infra/InversifyExpress/AnnotatedRevisionsController'
import '../src/Infra/InversifyExpress/AnnotatedHealthCheckController'
import { OpenTelemetrySDKInterface } from '@standardnotes/domain-events-infra'
const container = new ContainerConfigLoader()
void container.load().then((container) => {
@@ -46,11 +51,6 @@ void container.load().then((container) => {
const serverInstance = server.build()
if (!container.get<boolean>(TYPES.Revisions_IS_CONFIGURED_FOR_HOME_SERVER_OR_SELF_HOSTING)) {
const openTelemetrySDK = container.get<OpenTelemetrySDKInterface>(TYPES.Revisions_OpenTelemetrySDK)
openTelemetrySDK.start()
}
serverInstance.listen(env.get('PORT'))
logger.info(`Server started on port ${process.env.PORT}`)

View File

@@ -1,12 +1,17 @@
import 'reflect-metadata'
import { OpenTelemetrySDK } from '@standardnotes/domain-events-infra'
import { ServiceIdentifier } from '@standardnotes/domain-core'
const sdk = new OpenTelemetrySDK(ServiceIdentifier.NAMES.RevisionsWorker)
sdk.start()
import { Logger } from 'winston'
import TYPES from '../src/Bootstrap/Types'
import { Env } from '../src/Bootstrap/Env'
import { DomainEventSubscriberFactoryInterface } from '@standardnotes/domain-events'
import { ContainerConfigLoader } from '../src/Bootstrap/Container'
import { OpenTelemetrySDKInterface } from '@standardnotes/domain-events-infra'
const container = new ContainerConfigLoader('worker')
void container.load().then((container) => {
@@ -17,11 +22,6 @@ void container.load().then((container) => {
logger.info('Starting worker...')
if (!container.get<boolean>(TYPES.Revisions_IS_CONFIGURED_FOR_HOME_SERVER_OR_SELF_HOSTING)) {
const openTelemetrySDK = container.get<OpenTelemetrySDKInterface>(TYPES.Revisions_OpenTelemetrySDK)
openTelemetrySDK.start()
}
const subscriberFactory: DomainEventSubscriberFactoryInterface = container.get(
TYPES.Revisions_DomainEventSubscriberFactory,
)

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/revisions-server",
"version": "1.42.0",
"version": "1.43.4",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -40,8 +40,6 @@ import {
DirectCallEventMessageHandler,
DirectCallDomainEventPublisher,
SNSDomainEventPublisher,
OpenTelemetrySDKInterface,
OpenTelemetrySDK,
SQSOpenTelemetryEventMessageHandler,
} from '@standardnotes/domain-events-infra'
import { DumpRepositoryInterface } from '../Domain/Dump/DumpRepositoryInterface'
@@ -159,16 +157,6 @@ export class ContainerConfigLoader {
container.bind(TYPES.Revisions_NEW_RELIC_ENABLED).toConstantValue(env.get('NEW_RELIC_ENABLED', true))
container.bind(TYPES.Revisions_VERSION).toConstantValue(env.get('VERSION', true) ?? 'development')
if (!isConfiguredForHomeServerOrSelfHosting) {
container
.bind<OpenTelemetrySDKInterface>(TYPES.Revisions_OpenTelemetrySDK)
.toConstantValue(
new OpenTelemetrySDK(
this.mode === 'server' ? ServiceIdentifier.NAMES.Revisions : ServiceIdentifier.NAMES.RevisionsWorker,
),
)
}
if (!isConfiguredForHomeServer) {
// env vars
container.bind(TYPES.Revisions_SNS_TOPIC_ARN).toConstantValue(env.get('SNS_TOPIC_ARN'))
@@ -533,7 +521,11 @@ export class ContainerConfigLoader {
.toConstantValue(
isConfiguredForHomeServerOrSelfHosting
? new SQSEventMessageHandler(eventHandlers, container.get(TYPES.Revisions_Logger))
: new SQSOpenTelemetryEventMessageHandler(eventHandlers, container.get(TYPES.Revisions_Logger)),
: new SQSOpenTelemetryEventMessageHandler(
ServiceIdentifier.NAMES.RevisionsWorker,
eventHandlers,
container.get(TYPES.Revisions_Logger),
),
)
container

View File

@@ -5,7 +5,6 @@ const TYPES = {
Revisions_SQS: Symbol.for('Revisions_SQS'),
Revisions_SNS: Symbol.for('Revisions_SNS'),
Revisions_S3: Symbol.for('Revisions_S3'),
Revisions_OpenTelemetrySDK: Symbol.for('Revisions_OpenTelemetrySDK'),
Revisions_Env: Symbol.for('Revisions_Env'),
// Map
Revisions_SQLLegacyRevisionMetadataPersistenceMapper: Symbol.for(

View File

@@ -13,5 +13,6 @@ export interface RevisionRepositoryInterface {
updateUserUuid(itemUuid: Uuid, userUuid: Uuid): Promise<void>
findByUserUuid(dto: { userUuid: Uuid; offset?: number; limit?: number }): Promise<Array<Revision>>
insert(revision: Revision): Promise<boolean>
update(revision: Revision): Promise<boolean>
clearSharedVaultAndKeySystemAssociations(dto: { itemUuid?: Uuid; sharedVaultUuid: Uuid }): Promise<void>
}

View File

@@ -22,7 +22,7 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
) {}
async execute(dto: TransitionRevisionsFromPrimaryToSecondaryDatabaseForUserDTO): Promise<Result<void>> {
this.logger.info(`[${dto.userUuid}] Transitioning revisions for user`)
this.logger.info(`[TRANSITION][${dto.userUuid}] Transitioning revisions for user`)
if (this.secondRevisionsRepository === null) {
return Result.fail('Secondary revision repository is not set')
@@ -39,7 +39,7 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
const userUuid = userUuidOrError.getValue()
if (await this.isAlreadyMigrated(userUuid)) {
this.logger.info(`[${userUuid.value}] User already migrated.`)
this.logger.info(`[TRANSITION][${userUuid.value}] User already migrated.`)
await this.updateTransitionStatus(userUuid, TransitionStatus.STATUSES.Verified, dto.timestamp)
@@ -50,7 +50,7 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
const migrationTimeStart = this.timer.getTimestampInMicroseconds()
this.logger.info(`[${dto.userUuid}] Migrating revisions`)
this.logger.info(`[TRANSITION][${dto.userUuid}] Migrating revisions`)
const migrationResult = await this.migrateRevisionsForUser(userUuid, dto.timestamp)
if (migrationResult.isFailed()) {
@@ -59,11 +59,11 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
return Result.fail(migrationResult.getError())
}
this.logger.info(`[${dto.userUuid}] Revisions migrated`)
this.logger.info(`[TRANSITION][${dto.userUuid}] Revisions migrated`)
await this.allowForPrimaryDatabaseToCatchUp()
this.logger.info(`[${dto.userUuid}] Checking integrity between primary and secondary database`)
this.logger.info(`[TRANSITION][${dto.userUuid}] Checking integrity between primary and secondary database`)
const integrityCheckResult = await this.checkIntegrityBetweenPrimaryAndSecondaryDatabase(userUuid)
if (integrityCheckResult.isFailed()) {
@@ -83,7 +83,7 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
await this.updateTransitionStatus(userUuid, TransitionStatus.STATUSES.Failed, dto.timestamp)
this.logger.error(
`[${dto.userUuid}] Failed to clean up secondary database revisions: ${cleanupResult.getError()}`,
`[TRANSITION][${dto.userUuid}] Failed to clean up secondary database revisions: ${cleanupResult.getError()}`,
)
}
@@ -93,7 +93,7 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
const migrationDurationTimeStructure = this.timer.convertMicrosecondsToTimeStructure(migrationDuration)
this.logger.info(
`[${dto.userUuid}] Transitioned revisions in ${migrationDurationTimeStructure.hours}h ${migrationDurationTimeStructure.minutes}m ${migrationDurationTimeStructure.seconds}s ${migrationDurationTimeStructure.milliseconds}ms`,
`[TRANSITION][${dto.userUuid}] Transitioned revisions in ${migrationDurationTimeStructure.hours}h ${migrationDurationTimeStructure.minutes}m ${migrationDurationTimeStructure.seconds}s ${migrationDurationTimeStructure.milliseconds}ms`,
)
await this.updateTransitionStatus(userUuid, TransitionStatus.STATUSES.Verified, dto.timestamp)
@@ -107,20 +107,31 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
userUuid.value,
)
this.logger.info(`[${userUuid.value}] Migrating from page ${initialPage}`)
this.logger.info(`[TRANSITION][${userUuid.value}] Migrating from page ${initialPage}`)
const totalRevisionsCountForUser = await (
this.secondRevisionsRepository as RevisionRepositoryInterface
).countByUserUuid(userUuid)
this.logger.info(`[TRANSITION][${userUuid.value}] Total revisions count for user: ${totalRevisionsCountForUser}`)
const totalPages = Math.ceil(totalRevisionsCountForUser / this.pageSize)
this.logger.info(`[TRANSITION][${userUuid.value}] Total pages: ${totalPages}`)
let insertedCount = 0
let newerCount = 0
let identicalCount = 0
let updatedCount = 0
let duplicatedCount = 0
const processedUuids = new Set<string>()
for (let currentPage = initialPage; currentPage <= totalPages; currentPage++) {
const isPageInEvery10Percent = currentPage % Math.ceil(totalPages / 10) === 0
if (isPageInEvery10Percent) {
this.logger.info(
`[${userUuid.value}] Migrating revisions for user: ${Math.round(
`[TRANSITION][${userUuid.value}] Migrating revisions for user: ${Math.round(
(currentPage / totalPages) * 100,
)}% completed`,
)
this.logger.info(
`[TRANSITION][${userUuid.value}] Inserted ${insertedCount} revisions so far. Skipped ${newerCount} revisions because they were newer in primary database. Skipped ${identicalCount} revisions because they were identical in primary and secondary database. Updated ${updatedCount} revisions because they were older in primary database.`,
)
await this.updateTransitionStatus(userUuid, TransitionStatus.STATUSES.InProgress, timestamp)
}
@@ -138,51 +149,66 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
const revisions = await (this.secondRevisionsRepository as RevisionRepositoryInterface).findByUserUuid(query)
for (const revision of revisions) {
try {
if (processedUuids.has(revision.id.toString())) {
this.logger.warn(
`[TRANSITION][${userUuid.value}] Revision ${revision.id.toString()} was already processed`,
)
duplicatedCount++
} else {
processedUuids.add(revision.id.toString())
}
const revisionInPrimary = await this.primaryRevisionsRepository.findOneByUuid(
Uuid.create(revision.id.toString()).getValue(),
revision.props.userUuid as Uuid,
[],
)
if (revisionInPrimary !== null) {
if (!revisionInPrimary) {
await this.primaryRevisionsRepository.insert(revision)
insertedCount++
} else {
if (revisionInPrimary.props.dates.updatedAt > revision.props.dates.updatedAt) {
this.logger.info(
`[${
`[TRANSITION][${
userUuid.value
}] Revision ${revision.id.toString()} is older in secondary than revision in primary database`,
)
newerCount++
continue
}
if (revisionInPrimary.isIdenticalTo(revision)) {
identicalCount++
continue
}
this.logger.info(
`[${userUuid.value}] Removing revision ${revision.id.toString()} in primary database: ${JSON.stringify(
revisionInPrimary,
)} as it is not identical to revision in secondary database: ${JSON.stringify(revision)}`,
)
await this.primaryRevisionsRepository.update(revision)
await this.primaryRevisionsRepository.removeOneByUuid(
Uuid.create(revisionInPrimary.id.toString()).getValue(),
revisionInPrimary.props.userUuid as Uuid,
)
await this.allowForPrimaryDatabaseToCatchUp()
}
const didSave = await this.primaryRevisionsRepository.insert(revision)
if (!didSave) {
this.logger.error(`Failed to save revision ${revision.id.toString()} to primary database`)
updatedCount++
}
} catch (error) {
this.logger.error(
`Errored when saving revision ${revision.id.toString()} to primary database: ${(error as Error).message}`,
`[TRANSITION][${
userUuid.value
}] Errored when saving revision ${revision.id.toString()} to primary database: ${
(error as Error).message
}`,
)
}
}
}
this.logger.info(
`[TRANSITION][${userUuid.value}] Inserted ${insertedCount} revisions. Skipped ${newerCount} revisions because they were newer in primary database. Skipped ${identicalCount} revisions because they were identical in primary and secondary database. Updated ${updatedCount} revisions because they were older in primary database.`,
)
if (duplicatedCount > 0) {
this.logger.warn(`[TRANSITION][${userUuid.value}] Skipped ${duplicatedCount} duplicated revisions`)
}
return Result.ok()
} catch (error) {
return Result.fail(`Errored when migrating revisions for user ${userUuid.value}: ${(error as Error).message}`)
@@ -194,7 +220,7 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
revisionRepository: RevisionRepositoryInterface,
): Promise<Result<void>> {
try {
this.logger.info(`[${userUuid.value}] Deleting all revisions from secondary database`)
this.logger.info(`[TRANSITION][${userUuid.value}] Deleting all revisions from secondary database`)
await revisionRepository.removeByUserUuid(userUuid)
@@ -215,7 +241,7 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
userUuid.value,
)
this.logger.info(`[${userUuid.value}] Checking integrity from page ${initialPage}`)
this.logger.info(`[TRANSITION][${userUuid.value}] Checking integrity from page ${initialPage}`)
const totalRevisionsCountForUserInSecondary = await (
this.secondRevisionsRepository as RevisionRepositoryInterface
@@ -258,7 +284,7 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
if (revisionInPrimary.props.dates.updatedAt > revision.props.dates.updatedAt) {
this.logger.info(
`[${
`[TRANSITION][${
userUuid.value
}] Integrity check of revision ${revision.id.toString()} - is older in secondary than revision in primary database`,
)
@@ -304,7 +330,7 @@ export class TransitionRevisionsFromPrimaryToSecondaryDatabaseForUser implements
if (totalRevisionsCountForUserInSecondary > 0) {
this.logger.info(
`[${userUuid.value}] User has ${totalRevisionsCountForUserInSecondary} revisions in secondary database.`,
`[TRANSITION][${userUuid.value}] User has ${totalRevisionsCountForUserInSecondary} revisions in secondary database.`,
)
}

View File

@@ -46,6 +46,7 @@ export class MongoDBRevisionRepository implements RevisionRepositoryInterface {
where: { userUuid: { $eq: dto.userUuid.value } },
order: {
createdAt: 'ASC',
_id: 'ASC',
},
skip: dto.offset,
take: dto.limit,
@@ -146,6 +147,7 @@ export class MongoDBRevisionRepository implements RevisionRepositoryInterface {
},
order: {
createdAt: 'DESC',
_id: 'DESC',
},
})
} else {
@@ -156,6 +158,7 @@ export class MongoDBRevisionRepository implements RevisionRepositoryInterface {
},
order: {
createdAt: 'DESC',
_id: 'DESC',
},
})
}
@@ -193,4 +196,14 @@ export class MongoDBRevisionRepository implements RevisionRepositoryInterface {
return insertResult.acknowledged
}
async update(revision: Revision): Promise<boolean> {
const persistence = this.revisionMapper.toProjection(revision)
const { _id, ...rest } = persistence
const updateResult = await this.mongoRepository.updateOne({ _id: _id }, { $set: rest })
return updateResult.acknowledged
}
}

View File

@@ -111,9 +111,19 @@ export class SQLLegacyRevisionRepository implements RevisionRepositoryInterface
}
async insert(revision: Revision): Promise<boolean> {
const SQLLegacyRevision = this.revisionMapper.toProjection(revision)
const projection = this.revisionMapper.toProjection(revision)
await this.ormRepository.insert(SQLLegacyRevision)
await this.ormRepository.insert(projection)
return true
}
async update(revision: Revision): Promise<boolean> {
const projection = this.revisionMapper.toProjection(revision)
const { uuid, ...rest } = projection
await this.ormRepository.update({ uuid: uuid }, rest)
return true
}

View File

@@ -3,6 +3,28 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.22.9](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.22.8...@standardnotes/scheduler-server@1.22.9) (2023-10-10)
### Bug Fixes
* opentelemetry instantiation ([08f7c54](https://github.com/standardnotes/server/commit/08f7c5447b020fee71a1e49d382db32082bb9044))
## [1.22.8](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.22.7...@standardnotes/scheduler-server@1.22.8) (2023-10-10)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.22.7](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.22.6...@standardnotes/scheduler-server@1.22.7) (2023-10-09)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.22.6](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.22.5...@standardnotes/scheduler-server@1.22.6) (2023-10-09)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.22.5](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.22.4...@standardnotes/scheduler-server@1.22.5) (2023-10-09)
**Note:** Version bump only for package @standardnotes/scheduler-server
## [1.22.4](https://github.com/standardnotes/server/compare/@standardnotes/scheduler-server@1.22.3...@standardnotes/scheduler-server@1.22.4) (2023-10-09)
**Note:** Version bump only for package @standardnotes/scheduler-server

View File

@@ -1,5 +1,11 @@
import 'reflect-metadata'
import { OpenTelemetrySDK } from '@standardnotes/domain-events-infra'
import { ServiceIdentifier } from '@standardnotes/domain-core'
const sdk = new OpenTelemetrySDK(ServiceIdentifier.NAMES.SchedulerWorker)
sdk.start()
import { Logger } from 'winston'
import { DomainEventSubscriberFactoryInterface } from '@standardnotes/domain-events'
import * as dayjs from 'dayjs'

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/scheduler-server",
"version": "1.22.4",
"version": "1.22.9",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -16,7 +16,7 @@ import { DomainEventFactory } from '../Domain/Event/DomainEventFactory'
import {
SNSDomainEventPublisher,
SQSDomainEventSubscriberFactory,
SQSEventMessageHandler,
SQSOpenTelemetryEventMessageHandler,
} from '@standardnotes/domain-events-infra'
import { Timer, TimerInterface } from '@standardnotes/time'
import { PredicateRepositoryInterface } from '../Domain/Predicate/PredicateRepositoryInterface'
@@ -34,6 +34,7 @@ import { VerifyPredicates } from '../Domain/UseCase/VerifyPredicates/VerifyPredi
import { UserRegisteredEventHandler } from '../Domain/Handler/UserRegisteredEventHandler'
import { SubscriptionCancelledEventHandler } from '../Domain/Handler/SubscriptionCancelledEventHandler'
import { ExitDiscountAppliedEventHandler } from '../Domain/Handler/ExitDiscountAppliedEventHandler'
import { ServiceIdentifier } from '@standardnotes/domain-core'
export class ContainerConfigLoader {
async load(): Promise<Container> {
@@ -153,7 +154,13 @@ export class ContainerConfigLoader {
container
.bind<DomainEventMessageHandlerInterface>(TYPES.DomainEventMessageHandler)
.toConstantValue(new SQSEventMessageHandler(eventHandlers, container.get(TYPES.Logger)))
.toConstantValue(
new SQSOpenTelemetryEventMessageHandler(
ServiceIdentifier.NAMES.SchedulerWorker,
eventHandlers,
container.get(TYPES.Logger),
),
)
container
.bind<DomainEventSubscriberFactoryInterface>(TYPES.DomainEventSubscriberFactory)
.toConstantValue(

View File

@@ -3,6 +3,57 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.115.3](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.115.2...@standardnotes/syncing-server@1.115.3) (2023-10-10)
### Bug Fixes
* add transition keyword to logs for better searching ([1026ce3](https://github.com/standardnotes/syncing-server-js/commit/1026ce383c178086400bfe5a46e520e18b54e1bc))
## [1.115.2](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.115.1...@standardnotes/syncing-server@1.115.2) (2023-10-10)
### Bug Fixes
* **syncing-server:** elevate otel sdk before the container starts ([3e4a1e9](https://github.com/standardnotes/syncing-server-js/commit/3e4a1e9645d0c8909caca77bd87e6fc3bf3f9b1f))
* **syncing-server:** elevate otel sdk before the winston import ([250c1f0](https://github.com/standardnotes/syncing-server-js/commit/250c1f069be361b47552c10f1dc7c1f1eb5f07af))
## [1.115.1](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.115.0...@standardnotes/syncing-server@1.115.1) (2023-10-10)
### Bug Fixes
* transition logs to be more verbose ([036317e](https://github.com/standardnotes/syncing-server-js/commit/036317e33347f121fa799cbd409f85759798369d))
# [1.115.0](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.114.3...@standardnotes/syncing-server@1.115.0) (2023-10-10)
### Bug Fixes
* **syncing-server:** add option to define otel ratio ([c021bb3](https://github.com/standardnotes/syncing-server-js/commit/c021bb3d7ca90179292e7c75f5a84bf2b941ce86))
### Features
* add more logs to transition ([783fd9e](https://github.com/standardnotes/syncing-server-js/commit/783fd9e2c6350a7f0f1e8d009d01a3328564aca0))
## [1.114.3](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.114.2...@standardnotes/syncing-server@1.114.3) (2023-10-09)
### Bug Fixes
* **syncing-server:** add opentelemetry starting info in logs ([3ab2956](https://github.com/standardnotes/syncing-server-js/commit/3ab29569dbe23e9d546136c336b39ee1accb513f))
### Reverts
* Revert "Revert "fix: setting parent span on workers"" ([76ae6f5](https://github.com/standardnotes/syncing-server-js/commit/76ae6f5a882a82ab5f635452e3bc7b2b16709531))
## [1.114.2](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.114.1...@standardnotes/syncing-server@1.114.2) (2023-10-09)
### Reverts
* Revert "fix: setting parent span on workers" ([3fc07a5](https://github.com/standardnotes/syncing-server-js/commit/3fc07a5b60c26b583efd88e8a80d4c4321e71efb))
## [1.114.1](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.114.0...@standardnotes/syncing-server@1.114.1) (2023-10-09)
### Bug Fixes
* setting parent span on workers ([1c54d18](https://github.com/standardnotes/syncing-server-js/commit/1c54d18c3ca75353701ba921492a5ecfaa2e3572))
# [1.114.0](https://github.com/standardnotes/syncing-server-js/compare/@standardnotes/syncing-server@1.113.0...@standardnotes/syncing-server@1.114.0) (2023-10-09)
### Features

View File

@@ -1,5 +1,11 @@
import 'reflect-metadata'
import { OpenTelemetrySDK } from '@standardnotes/domain-events-infra'
import { ServiceIdentifier } from '@standardnotes/domain-core'
const sdk = new OpenTelemetrySDK(ServiceIdentifier.NAMES.SyncingServer)
sdk.start()
import '../src/Infra/InversifyExpressUtils/AnnotatedHealthCheckController'
import '../src/Infra/InversifyExpressUtils/AnnotatedItemsController'
import '../src/Infra/InversifyExpressUtils/AnnotatedMessagesController'
@@ -11,12 +17,11 @@ import helmet from 'helmet'
import * as cors from 'cors'
import { urlencoded, json, Request, Response, NextFunction } from 'express'
import * as winston from 'winston'
import { InversifyExpressServer } from 'inversify-express-utils'
import TYPES from '../src/Bootstrap/Types'
import { Env } from '../src/Bootstrap/Env'
import { ContainerConfigLoader } from '../src/Bootstrap/Container'
import { OpenTelemetrySDKInterface } from '@standardnotes/domain-events-infra'
const container = new ContainerConfigLoader()
void container.load().then((container) => {
@@ -74,11 +79,6 @@ void container.load().then((container) => {
const serverInstance = server.build()
if (!container.get<boolean>(TYPES.Sync_IS_CONFIGURED_FOR_HOME_SERVER_OR_SELF_HOSTING)) {
const openTelemetrySDK = container.get<OpenTelemetrySDKInterface>(TYPES.Sync_OpenTelemetrySDK)
openTelemetrySDK.start()
}
serverInstance.listen(env.get('PORT'))
logger.info(`Server started on port ${process.env.PORT}`)

View File

@@ -1,12 +1,17 @@
import 'reflect-metadata'
import { OpenTelemetrySDK } from '@standardnotes/domain-events-infra'
import { ServiceIdentifier } from '@standardnotes/domain-core'
const sdk = new OpenTelemetrySDK(ServiceIdentifier.NAMES.SyncingServerWorker)
sdk.start()
import { Logger } from 'winston'
import TYPES from '../src/Bootstrap/Types'
import { Env } from '../src/Bootstrap/Env'
import { DomainEventSubscriberFactoryInterface } from '@standardnotes/domain-events'
import { ContainerConfigLoader } from '../src/Bootstrap/Container'
import { OpenTelemetrySDKInterface } from '@standardnotes/domain-events-infra'
const container = new ContainerConfigLoader('worker')
void container.load().then((container) => {
@@ -15,15 +20,11 @@ void container.load().then((container) => {
const logger: Logger = container.get(TYPES.Sync_Logger)
logger.info('Starting worker...')
if (!container.get<boolean>(TYPES.Sync_IS_CONFIGURED_FOR_HOME_SERVER_OR_SELF_HOSTING)) {
const openTelemetrySDK = container.get<OpenTelemetrySDKInterface>(TYPES.Sync_OpenTelemetrySDK)
openTelemetrySDK.start()
}
const subscriberFactory: DomainEventSubscriberFactoryInterface = container.get(
TYPES.Sync_DomainEventSubscriberFactory,
)
logger.info('Starting worker...')
subscriberFactory.create().start()
})

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/syncing-server",
"version": "1.114.0",
"version": "1.115.3",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -13,8 +13,6 @@ import { Item } from '../Domain/Item/Item'
import {
DirectCallDomainEventPublisher,
DirectCallEventMessageHandler,
OpenTelemetrySDK,
OpenTelemetrySDKInterface,
SNSDomainEventPublisher,
SQSDomainEventSubscriberFactory,
SQSEventMessageHandler,
@@ -242,18 +240,6 @@ export class ContainerConfigLoader {
.bind<boolean>(TYPES.Sync_IS_CONFIGURED_FOR_HOME_SERVER_OR_SELF_HOSTING)
.toConstantValue(isConfiguredForHomeServerOrSelfHosting)
if (!isConfiguredForHomeServerOrSelfHosting) {
container
.bind<OpenTelemetrySDKInterface>(TYPES.Sync_OpenTelemetrySDK)
.toConstantValue(
new OpenTelemetrySDK(
this.mode === 'server'
? ServiceIdentifier.NAMES.SyncingServer
: ServiceIdentifier.NAMES.SyncingServerWorker,
),
)
}
if (!isConfiguredForInMemoryCache) {
const redisUrl = env.get('REDIS_URL')
const isRedisInClusterMode = redisUrl.indexOf(',') > 0
@@ -1178,7 +1164,11 @@ export class ContainerConfigLoader {
.toConstantValue(
isConfiguredForHomeServerOrSelfHosting
? new SQSEventMessageHandler(eventHandlers, container.get(TYPES.Sync_Logger))
: new SQSOpenTelemetryEventMessageHandler(eventHandlers, container.get(TYPES.Sync_Logger)),
: new SQSOpenTelemetryEventMessageHandler(
ServiceIdentifier.NAMES.SyncingServerWorker,
eventHandlers,
container.get(TYPES.Sync_Logger),
),
)
}

View File

@@ -6,7 +6,6 @@ const TYPES = {
Sync_SQS: Symbol.for('Sync_SQS'),
Sync_S3: Symbol.for('Sync_S3'),
Sync_Env: Symbol.for('Sync_Env'),
Sync_OpenTelemetrySDK: Symbol.for('Sync_OpenTelemetrySDK'),
// Repositories
Sync_ItemRepositoryResolver: Symbol.for('Sync_ItemRepositoryResolver'),
Sync_SQLItemRepository: Symbol.for('Sync_SQLItemRepository'),

View File

@@ -18,6 +18,8 @@ export interface ItemRepositoryInterface {
remove(item: Item): Promise<void>
removeByUuid(uuid: Uuid): Promise<void>
save(item: Item): Promise<void>
insert(item: Item): Promise<void>
update(item: Item): Promise<void>
markItemsAsDeleted(itemUuids: Array<string>, updatedAtTimestamp: number): Promise<void>
updateContentSize(itemUuid: string, contentSize: number): Promise<void>
unassignFromSharedVault(sharedVaultUuid: Uuid): Promise<void>

View File

@@ -23,7 +23,7 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
) {}
async execute(dto: TransitionItemsFromPrimaryToSecondaryDatabaseForUserDTO): Promise<Result<void>> {
this.logger.info(`[${dto.userUuid}] Transitioning items`)
this.logger.info(`[TRANSITION][${dto.userUuid}] Transitioning items`)
if (this.secondaryItemRepository === null) {
return Result.fail('Secondary item repository is not set')
@@ -40,7 +40,7 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
const userUuid = userUuidOrError.getValue()
if (await this.isAlreadyMigrated(userUuid)) {
this.logger.info(`[${userUuid.value}] User already migrated.`)
this.logger.info(`[TRANSITION][${userUuid.value}] User already migrated.`)
await this.updateTransitionStatus(userUuid, TransitionStatus.STATUSES.Verified, dto.timestamp)
@@ -49,7 +49,7 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
const migrationTimeStart = this.timer.getTimestampInMicroseconds()
this.logger.info(`[${dto.userUuid}] Migrating items`)
this.logger.info(`[TRANSITION][${dto.userUuid}] Migrating items`)
const migrationResult = await this.migrateItemsForUser(userUuid, dto.timestamp)
if (migrationResult.isFailed()) {
@@ -58,11 +58,11 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
return Result.fail(migrationResult.getError())
}
this.logger.info(`[${dto.userUuid}] Items migrated`)
this.logger.info(`[TRANSITION][${dto.userUuid}] Items migrated`)
await this.allowForPrimaryDatabaseToCatchUp()
this.logger.info(`[${dto.userUuid}] Checking integrity between primary and secondary database`)
this.logger.info(`[TRANSITION][${dto.userUuid}] Checking integrity between primary and secondary database`)
const integrityCheckResult = await this.checkIntegrityBetweenPrimaryAndSecondaryDatabase(userUuid)
if (integrityCheckResult.isFailed()) {
@@ -81,7 +81,9 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
if (cleanupResult.isFailed()) {
await this.updateTransitionStatus(userUuid, TransitionStatus.STATUSES.Failed, dto.timestamp)
this.logger.error(`[${dto.userUuid}] Failed to clean up secondary database items: ${cleanupResult.getError()}`)
this.logger.error(
`[TRANSITION][${dto.userUuid}] Failed to clean up secondary database items: ${cleanupResult.getError()}`,
)
}
const migrationTimeEnd = this.timer.getTimestampInMicroseconds()
@@ -90,7 +92,7 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
const migrationDurationTimeStructure = this.timer.convertMicrosecondsToTimeStructure(migrationDuration)
this.logger.info(
`[${dto.userUuid}] Transitioned items in ${migrationDurationTimeStructure.hours}h ${migrationDurationTimeStructure.minutes}m ${migrationDurationTimeStructure.seconds}s ${migrationDurationTimeStructure.milliseconds}ms`,
`[TRANSITION][${dto.userUuid}] Transitioned items in ${migrationDurationTimeStructure.hours}h ${migrationDurationTimeStructure.minutes}m ${migrationDurationTimeStructure.seconds}s ${migrationDurationTimeStructure.milliseconds}ms`,
)
await this.updateTransitionStatus(userUuid, TransitionStatus.STATUSES.Verified, dto.timestamp)
@@ -109,17 +111,28 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
userUuid.value,
)
this.logger.info(`[${userUuid.value}] Migrating from page ${initialPage}`)
this.logger.info(`[TRANSITION][${userUuid.value}] Migrating from page ${initialPage}`)
const totalItemsCountForUser = await (this.secondaryItemRepository as ItemRepositoryInterface).countAll({
userUuid: userUuid.value,
})
this.logger.info(`[TRANSITION][${userUuid.value}] Total items count for user: ${totalItemsCountForUser}`)
const totalPages = Math.ceil(totalItemsCountForUser / this.pageSize)
this.logger.info(`[TRANSITION][${userUuid.value}] Total pages: ${totalPages}`)
let insertedCount = 0
let updatedCount = 0
let newerCount = 0
let identicalCount = 0
for (let currentPage = initialPage; currentPage <= totalPages; currentPage++) {
const isPageInEvery10Percent = currentPage % Math.ceil(totalPages / 10) === 0
if (isPageInEvery10Percent) {
this.logger.info(
`[${userUuid.value}] Migrating items for user: ${Math.round((currentPage / totalPages) * 100)}% completed`,
`[TRANSITION][${userUuid.value}] Migrating items for user: ${Math.round(
(currentPage / totalPages) * 100,
)}% completed`,
)
this.logger.info(
`[TRANSITION][${userUuid.value}] Inserted items count: ${insertedCount}. Newer items count: ${newerCount}. Identical items count: ${identicalCount}. Updated items count: ${updatedCount}`,
)
await this.updateTransitionStatus(userUuid, TransitionStatus.STATUSES.InProgress, timestamp)
}
@@ -143,36 +156,43 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
try {
const itemInPrimary = await this.primaryItemRepository.findByUuid(item.uuid)
if (itemInPrimary !== null) {
if (!itemInPrimary) {
await this.primaryItemRepository.insert(item)
insertedCount++
} else {
if (itemInPrimary.props.timestamps.updatedAt > item.props.timestamps.updatedAt) {
this.logger.info(
`[${userUuid.value}] Item ${item.uuid.value} is older in secondary than item in primary database`,
`[TRANSITION][${userUuid.value}] Item ${item.uuid.value} is older in secondary than item in primary database`,
)
newerCount++
continue
}
if (itemInPrimary.isIdenticalTo(item)) {
identicalCount++
continue
}
this.logger.info(
`[${userUuid.value}] Removing item ${item.uuid.value} in primary database as it is not identical to item in primary database`,
)
await this.primaryItemRepository.update(item)
await this.primaryItemRepository.removeByUuid(item.uuid)
await this.allowForPrimaryDatabaseToCatchUp()
updatedCount++
}
await this.primaryItemRepository.save(item)
} catch (error) {
this.logger.error(
`Errored when saving item ${item.uuid.value} to primary database: ${(error as Error).message}`,
`[TRANSITION][${userUuid.value}] Errored when saving item ${item.uuid.value} to primary database: ${
(error as Error).message
}`,
)
}
}
}
this.logger.info(
`[TRANSITION][${userUuid.value}] Inserted items count: ${insertedCount}. Newer items count: ${newerCount}. Identical items count: ${identicalCount}. Updated items count: ${updatedCount}`,
)
return Result.ok()
} catch (error) {
return Result.fail((error as Error).message)
@@ -181,7 +201,7 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
private async deleteItemsForUser(userUuid: Uuid, itemRepository: ItemRepositoryInterface): Promise<Result<void>> {
try {
this.logger.info(`[${userUuid.value}] Cleaning up primary database items`)
this.logger.info(`[TRANSITION][${userUuid.value}] Cleaning up primary database items`)
await itemRepository.deleteByUserUuidAndNotInSharedVault(userUuid)
@@ -197,7 +217,7 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
userUuid.value,
)
this.logger.info(`[${userUuid.value}] Checking integrity from page ${initialPage}`)
this.logger.info(`[TRANSITION][${userUuid.value}] Checking integrity from page ${initialPage}`)
const totalItemsCountForUserInSecondary = await (
this.secondaryItemRepository as ItemRepositoryInterface
@@ -239,7 +259,7 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
if (itemInPrimary.props.timestamps.updatedAt > item.props.timestamps.updatedAt) {
this.logger.info(
`[${userUuid.value}] Integrity check of Item ${item.uuid.value} - is older in secondary than item in primary database`,
`[TRANSITION][${userUuid.value}] Integrity check of Item ${item.uuid.value} - is older in secondary than item in primary database`,
)
continue
@@ -282,7 +302,9 @@ export class TransitionItemsFromPrimaryToSecondaryDatabaseForUser implements Use
})
if (totalItemsCountForUserInSecondary > 0) {
this.logger.info(`[${userUuid.value}] User has ${totalItemsCountForUserInSecondary} items in secondary database.`)
this.logger.info(
`[TRANSITION][${userUuid.value}] User has ${totalItemsCountForUserInSecondary} items in secondary database.`,
)
}
return totalItemsCountForUserInSecondary === 0

View File

@@ -184,6 +184,25 @@ export class MongoDBItemRepository implements ItemRepositoryInterface {
)
}
async insert(item: Item): Promise<void> {
const persistence = this.mapper.toProjection(item)
await this.mongoRepository.insertOne(persistence)
}
async update(item: Item): Promise<void> {
const persistence = this.mapper.toProjection(item)
const { _id, ...rest } = persistence
await this.mongoRepository.updateOne(
{ _id: _id },
{
$set: rest,
},
)
}
async markItemsAsDeleted(itemUuids: string[], updatedAtTimestamp: number): Promise<void> {
await this.mongoRepository.updateMany(
{ _id: { $in: itemUuids.map((uuid) => BSON.UUID.createFromHexString(uuid)) } },

View File

@@ -43,6 +43,20 @@ export class SQLLegacyItemRepository implements ItemRepositoryInterface {
await this.ormRepository.save(persistence)
}
async insert(item: Item): Promise<void> {
const projection = this.mapper.toProjection(item)
await this.ormRepository.insert(projection)
}
async update(item: Item): Promise<void> {
const projection = this.mapper.toProjection(item)
const { uuid, ...updateValues } = projection
await this.ormRepository.update({ uuid: uuid }, updateValues)
}
async remove(item: Item): Promise<void> {
await this.ormRepository.remove(this.mapper.toProjection(item))
}

View File

@@ -3,6 +3,34 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
## [1.14.5](https://github.com/standardnotes/server/compare/@standardnotes/websockets-server@1.14.4...@standardnotes/websockets-server@1.14.5) (2023-10-10)
### Bug Fixes
* opentelemetry instantiation ([08f7c54](https://github.com/standardnotes/server/commit/08f7c5447b020fee71a1e49d382db32082bb9044))
## [1.14.4](https://github.com/standardnotes/server/compare/@standardnotes/websockets-server@1.14.3...@standardnotes/websockets-server@1.14.4) (2023-10-10)
**Note:** Version bump only for package @standardnotes/websockets-server
## [1.14.3](https://github.com/standardnotes/server/compare/@standardnotes/websockets-server@1.14.2...@standardnotes/websockets-server@1.14.3) (2023-10-09)
### Reverts
* Revert "Revert "fix: setting parent span on workers"" ([76ae6f5](https://github.com/standardnotes/server/commit/76ae6f5a882a82ab5f635452e3bc7b2b16709531))
## [1.14.2](https://github.com/standardnotes/server/compare/@standardnotes/websockets-server@1.14.1...@standardnotes/websockets-server@1.14.2) (2023-10-09)
### Reverts
* Revert "fix: setting parent span on workers" ([3fc07a5](https://github.com/standardnotes/server/commit/3fc07a5b60c26b583efd88e8a80d4c4321e71efb))
## [1.14.1](https://github.com/standardnotes/server/compare/@standardnotes/websockets-server@1.14.0...@standardnotes/websockets-server@1.14.1) (2023-10-09)
### Bug Fixes
* setting parent span on workers ([1c54d18](https://github.com/standardnotes/server/commit/1c54d18c3ca75353701ba921492a5ecfaa2e3572))
# [1.14.0](https://github.com/standardnotes/server/compare/@standardnotes/websockets-server@1.13.0...@standardnotes/websockets-server@1.14.0) (2023-10-09)
### Features

View File

@@ -1,5 +1,11 @@
import 'reflect-metadata'
import { OpenTelemetrySDK } from '@standardnotes/domain-events-infra'
import { ServiceIdentifier } from '@standardnotes/domain-core'
const sdk = new OpenTelemetrySDK(ServiceIdentifier.NAMES.Websockets)
sdk.start()
import '../src/Infra/InversifyExpressUtils/AnnotatedHealthCheckController'
import '../src/Infra/InversifyExpressUtils/AnnotatedWebSocketsController'
@@ -11,7 +17,6 @@ import { InversifyExpressServer } from 'inversify-express-utils'
import { ContainerConfigLoader } from '../src/Bootstrap/Container'
import TYPES from '../src/Bootstrap/Types'
import { Env } from '../src/Bootstrap/Env'
import { OpenTelemetrySDKInterface } from '@standardnotes/domain-events-infra'
const container = new ContainerConfigLoader()
void container.load().then((container) => {
@@ -47,9 +52,6 @@ void container.load().then((container) => {
const serverInstance = server.build()
const openTelemetrySDK = container.get<OpenTelemetrySDKInterface>(TYPES.WebSockets_OpenTelemetrySDK)
openTelemetrySDK.start()
serverInstance.listen(env.get('PORT'))
logger.info(`Server started on port ${process.env.PORT}`)

View File

@@ -1,12 +1,17 @@
import 'reflect-metadata'
import { OpenTelemetrySDK } from '@standardnotes/domain-events-infra'
import { ServiceIdentifier } from '@standardnotes/domain-core'
const sdk = new OpenTelemetrySDK(ServiceIdentifier.NAMES.WebsocketsWorker)
sdk.start()
import { Logger } from 'winston'
import { ContainerConfigLoader } from '../src/Bootstrap/Container'
import TYPES from '../src/Bootstrap/Types'
import { Env } from '../src/Bootstrap/Env'
import { DomainEventSubscriberFactoryInterface } from '@standardnotes/domain-events'
import { OpenTelemetrySDKInterface } from '@standardnotes/domain-events-infra'
const container = new ContainerConfigLoader()
void container.load().then((container) => {
@@ -17,9 +22,6 @@ void container.load().then((container) => {
logger.info('Starting worker...')
const openTelemetrySDK = container.get<OpenTelemetrySDKInterface>(TYPES.WebSockets_OpenTelemetrySDK)
openTelemetrySDK.start()
const subscriberFactory: DomainEventSubscriberFactoryInterface = container.get(TYPES.DomainEventSubscriberFactory)
subscriberFactory.create().start()
})

View File

@@ -1,6 +1,6 @@
{
"name": "@standardnotes/websockets-server",
"version": "1.14.0",
"version": "1.14.5",
"engines": {
"node": ">=18.0.0 <21.0.0"
},

View File

@@ -19,8 +19,6 @@ import { AddWebSocketsConnection } from '../Domain/UseCase/AddWebSocketsConnecti
import { RemoveWebSocketsConnection } from '../Domain/UseCase/RemoveWebSocketsConnection/RemoveWebSocketsConnection'
import { WebSocketsClientMessenger } from '../Infra/WebSockets/WebSocketsClientMessenger'
import {
OpenTelemetrySDK,
OpenTelemetrySDKInterface,
SQSDomainEventSubscriberFactory,
SQSOpenTelemetryEventMessageHandler,
} from '@standardnotes/domain-events-infra'
@@ -42,22 +40,12 @@ import { WebSocketMessageRequestedEventHandler } from '../Domain/Handler/WebSock
import { ServiceIdentifier } from '@standardnotes/domain-core'
export class ContainerConfigLoader {
constructor(private mode: 'server' | 'worker' = 'server') {}
async load(): Promise<Container> {
const env: Env = new Env()
env.load()
const container = new Container()
container
.bind<OpenTelemetrySDKInterface>(TYPES.WebSockets_OpenTelemetrySDK)
.toConstantValue(
new OpenTelemetrySDK(
this.mode === 'server' ? ServiceIdentifier.NAMES.Websockets : ServiceIdentifier.NAMES.WebsocketsWorker,
),
)
const redisUrl = env.get('REDIS_URL')
const isRedisInClusterMode = redisUrl.indexOf(',') > 0
let redis
@@ -164,7 +152,13 @@ export class ContainerConfigLoader {
container
.bind<DomainEventMessageHandlerInterface>(TYPES.DomainEventMessageHandler)
.toConstantValue(new SQSOpenTelemetryEventMessageHandler(eventHandlers, container.get(TYPES.Logger)))
.toConstantValue(
new SQSOpenTelemetryEventMessageHandler(
ServiceIdentifier.NAMES.WebsocketsWorker,
eventHandlers,
container.get(TYPES.Logger),
),
)
container
.bind<DomainEventSubscriberFactoryInterface>(TYPES.DomainEventSubscriberFactory)
.toConstantValue(

View File

@@ -2,7 +2,6 @@ const TYPES = {
Logger: Symbol.for('Logger'),
Redis: Symbol.for('Redis'),
SQS: Symbol.for('SQS'),
WebSockets_OpenTelemetrySDK: Symbol.for('WebSockets_OpenTelemetrySDK'),
WebSockets_ApiGatewayManagementApiClient: Symbol.for('WebSockets_ApiGatewayManagementApiClient'),
// Controller
WebSocketsController: Symbol.for('WebSocketsController'),