Skip to content

Commit

Permalink
Merge pull request #449 from metrico/read_only_mode_fixes
Browse files Browse the repository at this point in the history
fix: init clickhouse conn in readonly mode
  • Loading branch information
akvlad authored Feb 1, 2024
2 parents 6eb3ebe + 9b6212f commit 55cdc5e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions lib/db/clickhouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const axios = require('axios')
const { samplesTableName, samplesReadTableName } = UTILS
const path = require('path')
const { Transform } = require('stream')
const { CORS, bun } = require('../../common')
const { CORS, bun, readonly } = require('../../common')
const clickhouseOptions = require('./clickhouse_options').databaseOptions
const { getClickhouseUrl } = require('./clickhouse_options')

Expand Down Expand Up @@ -180,6 +180,10 @@ const initialize = async function (dbName) {
logger.info('Initializing DB... ' + dbName)
const tmp = { ...clickhouseOptions, queryOptions: { database: '' } }
ch = new ClickHouse(tmp)
if (readonly) {
state = 'READY'
return
}
if (!isOmitTablesCreation()) {
const maintain = require('./maintain/index')
await maintain.upgrade({ name: dbName, storage_policy: storagePolicy })
Expand Down Expand Up @@ -1333,9 +1337,12 @@ const samplesReadTable = {
}
},
settingsVersions: async function () {
const versions = await axios.post(`${getClickhouseUrl()}/?database=${UTILS.DATABASE_NAME()}`,
const versions = await rawRequest(
`SELECT argMax(name, inserted_at) as _name, argMax(value, inserted_at) as _value
FROM settings${dist} WHERE type == 'update' GROUP BY fingerprint HAVING _name != '' FORMAT JSON`)
FROM settings${dist} WHERE type == 'update' GROUP BY fingerprint HAVING _name != '' FORMAT JSON`,
null,
UTILS.DATABASE_NAME()
)
for (const version of versions.data.data) {
this.versions[version._name] = parseInt(version._value) * 1000
}
Expand Down
2 changes: 1 addition & 1 deletion qryn_bun.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ const http_user = process.env.QRYN_LOGIN || process.env.CLOKI_LOGIN || undefined
const http_password = process.env.QRYN_PASSWORD || process.env.CLOKI_PASSWORD || undefined

export default async() => {
await init(process.env.CLICKHOUSE_DB || 'cloki')
if (!readonly) {
await init(process.env.CLICKHOUSE_DB || 'cloki')
await startAlerting()
}
await DATABASE.checkDB()
Expand Down
2 changes: 1 addition & 1 deletion qryn_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ let fastify = require('fastify')({
});
(async () => {
try {
await init(process.env.CLICKHOUSE_DB || 'cloki')
if (!this.readonly) {
await init(process.env.CLICKHOUSE_DB || 'cloki')
await startAlerting()
}
await DATABASE.checkDB()
Expand Down

0 comments on commit 55cdc5e

Please sign in to comment.