Skip to content

Commit

Permalink
Merge branch 'main' into iain/multi-region-config
Browse files Browse the repository at this point in the history
  • Loading branch information
iainsproat committed Oct 30, 2024
2 parents 2153bef + 55d0d10 commit cb27ddd
Show file tree
Hide file tree
Showing 32 changed files with 351 additions and 128 deletions.
3 changes: 3 additions & 0 deletions packages/frontend-2/components/workspace/ProjectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ const onShowSettingsDialog = (target: AvailableSettingsMenuKeys) => {
onResult((queryResult) => {
if (queryResult.data?.workspaceBySlug) {
workspaceMixpanelUpdateGroup(queryResult.data.workspaceBySlug)
useHeadSafe({
title: queryResult.data.workspaceBySlug.name
})
}
})
</script>
10 changes: 7 additions & 3 deletions packages/frontend-2/pages/projects/[id]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
</CommonBadge>
</div>
<div class="flex flex-row gap-x-3">
<div v-tippy="canEdit ? 'Manage collaborators' : 'View collaborators'">
<NuxtLink :to="projectCollaboratorsRoute(project.id)">
<div v-tippy="collaboratorsTooltip">
<NuxtLink :to="hasRole ? projectCollaboratorsRoute(project.id) : ''">
<UserAvatarGroup
:users="teamUsers"
:max-count="2"
Expand Down Expand Up @@ -168,7 +168,7 @@ const actionsItems = computed<LayoutMenuItem[][]>(() => {
]
]

if (isWorkspacesEnabled.value && !project.value?.workspace?.id) {
if (isWorkspacesEnabled.value && !project.value?.workspace?.id && hasRole.value) {
items.push([
{
title: 'Move project...',
Expand Down Expand Up @@ -233,6 +233,10 @@ const pageTabItems = computed((): LayoutPageTabItem[] => {
const findTabById = (id: string) =>
pageTabItems.value.find((tab) => tab.id === id) || pageTabItems.value[0]

const collaboratorsTooltip = computed(() =>
hasRole.value ? (canEdit.value ? 'Manage collaborators' : 'View collaborators') : null
)

const activePageTab = computed({
get: () => {
const path = router.currentRoute.value.path
Expand Down
26 changes: 26 additions & 0 deletions packages/server/assets/multiregion/typedefs/multiregion.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
type ServerRegionItem {
id: String!
key: String!
name: String!
description: String!
}

input CreateServerRegionInput {
key: String!
name: String!
description: String!
}

type ServerRegionMutations {
create(input: CreateServerRegionInput!): ServerRegionItem!
}

type ServerInfoMutations {
multiRegion: ServerRegionMutations!
}

extend type Mutation {
serverInfoMutations: ServerInfoMutations!
@hasServerRole(role: SERVER_ADMIN)
@hasScope(scope: "server:setup")
}
1 change: 0 additions & 1 deletion packages/server/codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ generates:
User: '@/modules/core/helpers/graphTypes#UserGraphQLReturn'
ActiveUserMutations: '@/modules/core/helpers/graphTypes#MutationsObjectGraphQLReturn'
UserEmailMutations: '@/modules/core/helpers/graphTypes#MutationsObjectGraphQLReturn'
UserWorkspaceMutations: '@/modules/core/helpers/graphTypes#MutationsObjectGraphQLReturn'
ProjectMutations: '@/modules/core/helpers/graphTypes#MutationsObjectGraphQLReturn'
ProjectInviteMutations: '@/modules/core/helpers/graphTypes#MutationsObjectGraphQLReturn'
ModelMutations: '@/modules/core/helpers/graphTypes#MutationsObjectGraphQLReturn'
Expand Down
17 changes: 6 additions & 11 deletions packages/server/db/knex.js → packages/server/db/knex.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* istanbul ignore file */
'use strict'

const env = process.env.NODE_ENV || 'development'
const configs = require('@/knexfile.js')
const { dbStartupLogger } = require('@/logging/logging')
import configs from '@/knexfile'
import { dbStartupLogger } from '@/logging/logging'
import knex from 'knex'

const config = configs[env]

config.log = {
Expand All @@ -18,12 +18,7 @@ config.log = {

dbStartupLogger.info(`Loaded knex conf for ${env}`)

/**
* Need to override type because type def file incorrectly uses ES6
* @type {import('knex').default}
*/
const knex = require('knex')
const knexInstance = knex(config)

module.exports = knexInstance
module.exports.db = knexInstance
export default knexInstance
export { knexInstance as db, knexInstance as knex, knexInstance as knexInstance }
35 changes: 17 additions & 18 deletions packages/server/knexfile.js → packages/server/knexfile.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/* eslint-disable no-restricted-imports */
/* eslint-disable camelcase */
/* istanbul ignore file */
'use strict'

const { packageRoot } = require('./bootstrap')
const fs = require('fs')
const path = require('path')
const {
import { packageRoot } from './bootstrap'
import fs from 'fs'
import path from 'path'
import {
isTestEnv,
ignoreMissingMigrations,
postgresMaxConnections
} = require('@/modules/shared/helpers/envHelper')
const { dbLogger: logger } = require('./logging/logging')
} from '@/modules/shared/helpers/envHelper'
import { dbLogger as logger } from './logging/logging'
import { Knex } from 'knex'

function walk(dir) {
let results = []
function walk(dir: string) {
let results: string[] = []
const list = fs.readdirSync(dir)
list.forEach(function (file) {
const fullFile = path.join(dir, file)
Expand Down Expand Up @@ -50,7 +50,7 @@ if (env.POSTGRES_USER && env.POSTGRES_PASSWORD) {
env.POSTGRES_USER
)}:${encodeURIComponent(env.POSTGRES_PASSWORD)}@${
env.POSTGRES_URL
}/${encodeURIComponent(env.POSTGRES_DB)}`
}/${encodeURIComponent(env.POSTGRES_DB as string)}`
} else {
connectionUri = env.POSTGRES_URL
}
Expand All @@ -77,16 +77,16 @@ const commonConfig = {
directory: migrationDirs
},
log: {
warn(message) {
warn(message: unknown) {
logger.warn(message)
},
error(message) {
error(message: unknown) {
logger.error(message)
},
deprecate(message) {
deprecate(message: unknown) {
logger.info(message)
},
debug(message) {
debug(message: unknown) {
logger.debug(message)
}
},
Expand All @@ -100,8 +100,7 @@ const commonConfig = {
}
}

/** @type {Object<string, import('knex').Knex.Config>} */
const config = {
const config: Record<string, Knex.Config> = {
test: {
...commonConfig,
connection: {
Expand Down Expand Up @@ -129,4 +128,4 @@ const config = {
}
}

module.exports = config
export default config
23 changes: 0 additions & 23 deletions packages/server/logging/errorLogging.js

This file was deleted.

29 changes: 29 additions & 0 deletions packages/server/logging/errorLogging.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* istanbul ignore file */
import { logger } from '@/logging/logging'
import type { Nullable } from '@speckle/shared'
import prometheusClient from 'prom-client'
import type express from 'express'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
let metricErrorCount: Nullable<prometheusClient.Counter<any>> = null

export const errorLoggingMiddleware: express.ErrorRequestHandler = (
err,
req,
res,
next
) => {
if (metricErrorCount === null) {
metricErrorCount = new prometheusClient.Counter({
name: 'speckle_server_request_errors',
help: 'Number of requests that threw exceptions',
labelNames: ['route']
})
}

logger.error(err, `Error when handling ${req.originalUrl} from ${req.ip}`)
let route = 'unknown'
if (req.route && req.route.path) route = req.route.path
metricErrorCount.labels(route).inc()
next(err)
}
30 changes: 0 additions & 30 deletions packages/server/logging/httpServerMonitoring.js

This file was deleted.

28 changes: 28 additions & 0 deletions packages/server/logging/httpServerMonitoring.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* istanbul ignore file */
import type { Nullable } from '@speckle/shared'
import prometheusClient from 'prom-client'
import type http from 'http'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
let metricActiveConnections: Nullable<prometheusClient.Gauge<any>> = null

export const monitorActiveConnections = (httpServer: http.Server) => {
if (metricActiveConnections !== null) {
prometheusClient.register.removeSingleMetric('speckle_server_active_connections')
}

metricActiveConnections = new prometheusClient.Gauge({
name: 'speckle_server_active_connections',
help: 'Number of active http connections',
async collect() {
let connectionCount = await new Promise<number>((resolve) => {
httpServer.getConnections(function (error, count) {
if (error) resolve(-1)
else resolve(count)
})
})
if (isNaN(connectionCount)) connectionCount = -1
this.set(connectionCount)
}
})
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
/* istanbul ignore file */
const prometheusClient = require('prom-client')
const promBundle = require('express-prom-bundle')
import prometheusClient from 'prom-client'
import promBundle from 'express-prom-bundle'

const { initKnexPrometheusMetrics } = require('@/logging/knexMonitoring')
const {
initHighFrequencyMonitoring
} = require('@/logging/highFrequencyMetrics/highfrequencyMonitoring')
const knex = require('@/db/knex')
const {
highFrequencyMetricsCollectionPeriodMs
} = require('@/modules/shared/helpers/envHelper')
const { startupLogger: logger } = require('@/logging/logging')
import { initKnexPrometheusMetrics } from '@/logging/knexMonitoring'
import { initHighFrequencyMonitoring } from '@/logging/highFrequencyMetrics/highfrequencyMonitoring'
import knex from '@/db/knex'
import { highFrequencyMetricsCollectionPeriodMs } from '@/modules/shared/helpers/envHelper'
import { startupLogger as logger } from '@/logging/logging'
import type express from 'express'

let prometheusInitialized = false

module.exports = function (app) {
export default function (app: express.Express) {
if (!prometheusInitialized) {
prometheusInitialized = true
prometheusClient.register.clear()
Expand Down
2 changes: 1 addition & 1 deletion packages/server/modules/auth/tests/apps.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
const { beforeEachContext } = require(`@/test/hooks`)

const { Scopes } = require('@/modules/core/helpers/mainConstants')
const knex = require('@/db/knex')
const { knex } = require('@/db/knex')
const cryptoRandomString = require('crypto-random-string')
const {
getAppFactory,
Expand Down
2 changes: 1 addition & 1 deletion packages/server/modules/auth/tests/auth.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const {
deleteServerOnlyInvitesFactory,
updateAllInviteTargetsFactory
} = require('@/modules/serverinvites/repositories/serverInvites')
const db = require('@/db/knex')
const { db } = require('@/db/knex')
const {
legacyCreateStreamFactory,
createStreamReturnRecordFactory
Expand Down
2 changes: 1 addition & 1 deletion packages/server/modules/blobstorage/tests/helpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* istanbul ignore file */
const crs = require('crypto-random-string')
const { range } = require('lodash')
const knex = require('@/db/knex')
const { knex } = require('@/db/knex')
const BlobStorage = () => knex('blob_storage')

const fakeIdGenerator = () => crs({ length: 10 })
Expand Down
Loading

0 comments on commit cb27ddd

Please sign in to comment.