未验证 提交 41f3d6f2 编写于 作者: V Vlad Ilyushchenko 提交者: GitHub

chore(main): logging telemetry id and forcing debug level from Env variable (#645)

上级 bc92d78e
......@@ -120,24 +120,26 @@ public class ServerMain {
log.info().$("database root [dir=").$(path).$(']').$();
}
}
log.info().$("platform [bit=").$(System.getProperty("sun.arch.data.model")).$(']').$();
switch (Os.type) {
case Os.WINDOWS:
log.info().$("OS: windows-amd64 ").$(Vect.getSupportedInstructionSetName()).$();
log.info().$("OS: windows-amd64").$(Vect.getSupportedInstructionSetName()).$();
break;
case Os.LINUX_AMD64:
log.info().$("OS: linux-amd64 ").$(Vect.getSupportedInstructionSetName()).$();
log.info().$("OS: linux-amd64").$(Vect.getSupportedInstructionSetName()).$();
break;
case Os.OSX:
log.info().$("OS: apple-amd64 ").$(Vect.getSupportedInstructionSetName()).$();
log.info().$("OS: apple-amd64").$(Vect.getSupportedInstructionSetName()).$();
break;
case Os.LINUX_ARM64:
log.info().$("OS: linux-arm64 ").$(Vect.getSupportedInstructionSetName()).$();
log.info().$("OS: linux-arm64").$(Vect.getSupportedInstructionSetName()).$();
break;
case Os.FREEBSD:
log.info().$("OS: freebsd-amd64 ").$(Vect.getSupportedInstructionSetName()).$();
log.info().$("OS: freebsd-amd64").$(Vect.getSupportedInstructionSetName()).$();
break;
default:
log.error().$("Unsupported OS ").$(Vect.getSupportedInstructionSetName()).$();
log.error().$("Unsupported OS").$(Vect.getSupportedInstructionSetName()).$();
break;
}
......
......@@ -35,11 +35,11 @@ import io.questdb.mp.QueueConsumer;
import io.questdb.mp.RingQueue;
import io.questdb.mp.SCSequence;
import io.questdb.mp.SynchronizedJob;
import io.questdb.std.Long256;
import io.questdb.std.Misc;
import io.questdb.std.NanosecondClock;
import io.questdb.std.microtime.MicrosecondClock;
import io.questdb.std.str.Path;
import io.questdb.std.str.StringSink;
import io.questdb.tasks.TelemetryTask;
import org.jetbrains.annotations.Nullable;
......@@ -119,23 +119,41 @@ public class TelemetryJob extends SynchronizedJob implements Closeable {
final Record record = cursor.getRecord();
final boolean _enabled = record.getBool(1);
// if the configuration changed to enable or disable telemetry
// we need to update the table to reflect that
if (enabled != _enabled) {
final StringSink sink = new StringSink();
final TableWriter.Row row = writerConfig.newRow();
record.getLong256(0, sink);
row.putLong256(0, sink);
final Long256 l256 = record.getLong256A(0);
row.putLong256(0, l256);
row.putBool(1, enabled);
row.append();
writerConfig.commit();
LOG.info()
.$("instance config changes [id=").$256(l256.getLong0(), l256.getLong1(), 0, 0)
.$(", enabled=").$(this.enabled)
.$(']').$();
} else {
final Long256 l256 = record.getLong256A(0);
LOG.error()
.$("instance [id=").$256(l256.getLong0(), l256.getLong1(), 0, 0)
.$(", enabled=").$(this.enabled)
.$(']').$();
}
} else {
// if there are no record for telemetry id we need to create one using clocks
final MicrosecondClock clock = configuration.getMicrosecondClock();
final NanosecondClock nanosecondClock = configuration.getNanosecondClock();
final TableWriter.Row row = writerConfig.newRow();
row.putLong256(0, nanosecondClock.getTicks(), clock.getTicks(), 0, 0);
final long a = nanosecondClock.getTicks();
final long b = clock.getTicks();
row.putLong256(0, a, b, 0, 0);
row.putBool(1, enabled);
row.append();
writerConfig.commit();
LOG.info()
.$("new instance [id=").$256(a, b, 0, 0)
.$(", enabled=").$(this.enabled)
.$(']').$();
}
}
......
......@@ -39,6 +39,7 @@ public class LogFactory implements Closeable {
public static final LogFactory INSTANCE = new LogFactory();
public static final String DEBUG_TRIGGER = "ebug";
public static final String DEBUG_TRIGGER_ENV = "QDB_DEBUG";
public static final String CONFIG_SYSTEM_PROPERTY = "questdbLog";
private static final int DEFAULT_QUEUE_DEPTH = 1024;
......@@ -342,7 +343,7 @@ public class LogFactory implements Closeable {
}
}
if (System.getProperty(DEBUG_TRIGGER) != null) {
if (isForcedDebug()) {
level = level | LogLevel.LOG_LEVEL_DEBUG;
}
......@@ -375,6 +376,10 @@ public class LogFactory implements Closeable {
});
}
private static boolean isForcedDebug() {
return System.getProperty(DEBUG_TRIGGER) != null || System.getenv().containsKey(DEBUG_TRIGGER_ENV);
}
/**
* Converts fully qualified class name into an abbreviated form:
* com.questdb.mp.Sequence -> c.n.m.Sequence
......@@ -412,7 +417,7 @@ public class LogFactory implements Closeable {
private void configureDefaultWriter() {
int level = LogLevel.LOG_LEVEL_INFO | LogLevel.LOG_LEVEL_ERROR;
if (System.getProperty(DEBUG_TRIGGER) != null) {
if (isForcedDebug()) {
level = level | LogLevel.LOG_LEVEL_DEBUG;
}
add(new LogWriterConfig(level, LogConsoleWriter::new));
......
......@@ -57,6 +57,8 @@ public interface LogRecord {
LogRecord $ts(long x);
LogRecord $256(long a, long b, long c, long d);
boolean isEnabled();
LogRecord ts();
......
......@@ -201,6 +201,12 @@ class Logger implements LogRecord, Log {
return this;
}
@Override
public LogRecord $256(long a, long b, long c, long d) {
Numbers.appendLong256(a, b, c, d, sink());
return this;
}
@Override
public LogRecord debug() {
return xdebug().ts().$(" D ").$(name);
......
......@@ -44,6 +44,11 @@ final class NullLogRecord implements LogRecord {
return this;
}
@Override
public LogRecord $(CharSequence sequence, int lo, int hi) {
return this;
}
@Override
public LogRecord $(int x) {
return this;
......@@ -100,13 +105,13 @@ final class NullLogRecord implements LogRecord {
}
@Override
public boolean isEnabled() {
return false;
public LogRecord $256(long a, long b, long c, long d) {
return this;
}
@Override
public LogRecord $(CharSequence sequence, int lo, int hi) {
return this;
public boolean isEnabled() {
return false;
}
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册