Skip to content

Commit

Permalink
fix(plugin-server): don't sent app debug logs to CH
Browse files Browse the repository at this point in the history
  • Loading branch information
xvello committed Nov 22, 2023
1 parent 266c3ff commit 83a1d2d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
7 changes: 4 additions & 3 deletions plugin-server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,10 @@ export enum PluginLogEntryType {

export enum PluginLogLevel {
Full = 0, // all logs
Debug = 1, // all except log
Warn = 2, // all except log and info
Critical = 3, // only error type and system source
Log = 1, // all except debug
Info = 2, // all expect log and debug
Warn = 3, // all except log, debug and info
Critical = 4, // only error type and system source
}

export interface PluginLogEntry {
Expand Down
5 changes: 2 additions & 3 deletions plugin-server/src/utils/db/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1076,10 +1076,9 @@ export class DB {

public async queuePluginLogEntry(entry: LogEntryPayload): Promise<void> {
const { pluginConfig, source, message, type, timestamp, instanceId } = entry
const configuredLogLevel = pluginConfig.plugin?.log_level || PluginLogLevel.Log

const logLevel = pluginConfig.plugin?.log_level

if (!shouldStoreLog(logLevel || PluginLogLevel.Full, source, type)) {
if (!shouldStoreLog(configuredLogLevel, type)) {
return
}

Expand Down
32 changes: 13 additions & 19 deletions plugin-server/src/utils/db/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import { Counter } from 'prom-client'

import { defaultConfig } from '../../config/config'
import { KAFKA_PERSON } from '../../config/kafka-topics'
import { BasePerson, Person, RawPerson, TimestampFormat } from '../../types'
import { BasePerson, Person, PluginLogEntryType, PluginLogLevel, RawPerson, TimestampFormat } from '../../types'
import { status } from '../../utils/status'
import { castTimestampOrNow } from '../../utils/utils'
import { PluginLogEntrySource, PluginLogEntryType, PluginLogLevel } from './../../types'

export function unparsePersonPartial(person: Partial<Person>): Partial<RawPerson> {
return { ...(person as BasePerson), ...(person.created_at ? { created_at: person.created_at.toISO() } : {}) }
Expand Down Expand Up @@ -127,24 +126,19 @@ export function getFinalPostgresQuery(queryString: string, values: any[]): strin
return queryString.replace(/\$([0-9]+)/g, (m, v) => JSON.stringify(values[parseInt(v) - 1]))
}

export function shouldStoreLog(
pluginLogLevel: PluginLogLevel,
source: PluginLogEntrySource,
type: PluginLogEntryType
): boolean {
if (source === PluginLogEntrySource.System) {
return true
export function shouldStoreLog(pluginLogLevel: PluginLogLevel, type: PluginLogEntryType): boolean {
switch (pluginLogLevel) {
case PluginLogLevel.Full:
return true
case PluginLogLevel.Log:
return type !== PluginLogEntryType.Debug
case PluginLogLevel.Info:
return type !== PluginLogEntryType.Log && type !== PluginLogEntryType.Debug
case PluginLogLevel.Warn:
return type === PluginLogEntryType.Warn || type === PluginLogEntryType.Error
case PluginLogLevel.Critical:
return type === PluginLogEntryType.Error
}

if (pluginLogLevel === PluginLogLevel.Critical) {
return type === PluginLogEntryType.Error
} else if (pluginLogLevel === PluginLogLevel.Warn) {
return type !== PluginLogEntryType.Log && type !== PluginLogEntryType.Info
} else if (pluginLogLevel === PluginLogLevel.Debug) {
return type !== PluginLogEntryType.Log
}

return true
}

// keep in sync with posthog/posthog/api/utils.py::safe_clickhouse_string
Expand Down

0 comments on commit 83a1d2d

Please sign in to comment.