浏览代码

Fix pg insertion failure due to time zones

Npgsql started throwing exceptions in v6.0 when handed a datetime with a
local time zone, as the server expects a date time in UTC. This bug only
effects OhmGraphite v0.23
Nick Babcock 3 年之前
父节点
当前提交
ec600c886c
共有 1 个文件被更改,包括 4 次插入0 次删除
  1. 4 0
      OhmGraphite/TimescaleWriter.cs

+ 4 - 0
OhmGraphite/TimescaleWriter.cs

@@ -30,6 +30,10 @@ namespace OhmGraphite
         {
         {
             try
             try
             {
             {
+                // "timestamp with time zone" postgres type is a UTC timestamp so
+                // we explicitly convert the reported time to UTC to avoid a cast
+                // exception by npgsql
+                reportTime = reportTime.ToUniversalTime();
                 if (_failure)
                 if (_failure)
                 {
                 {
                     Logger.Debug("Clearing connection pool");
                     Logger.Debug("Clearing connection pool");