From 262cd529ed3d7eb675b45d8473158aeed7a3e70b Mon Sep 17 00:00:00 2001 From: Stephen von Takach Date: Tue, 18 Oct 2022 13:10:15 +1100 Subject: [PATCH] fix(publishing/influx_publisher): use float64 for numeric field types avoids issues with JSON ambiguity and is the default influxdb type --- shard.lock | 12 ++++++------ src/source/publishing/influx_publisher.cr | 16 +++++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/shard.lock b/shard.lock index 2acf396..8e714be 100644 --- a/shard.lock +++ b/shard.lock @@ -6,15 +6,15 @@ shards: action-controller: git: https://github.com/spider-gazelle/action-controller.git - version: 5.3.13 + version: 5.4.2 active-model: git: https://github.com/spider-gazelle/active-model.git - version: 4.0.0 + version: 4.2.2 ameba: git: https://github.com/crystal-ameba/ameba.git - version: 1.1.0 + version: 1.2.0 backtracer: git: https://github.com/sija/backtracer.cr.git @@ -22,7 +22,7 @@ shards: bindata: git: https://github.com/spider-gazelle/bindata.git - version: 1.10.0 + version: 1.11.0 cron_parser: git: https://github.com/kostya/cron_parser.git @@ -78,7 +78,7 @@ shards: json-schema: git: https://github.com/spider-gazelle/json-schema.git - version: 1.2.1 + version: 1.3.0 jwt: git: https://github.com/crystal-community/jwt.git @@ -102,7 +102,7 @@ shards: neuroplastic: git: https://github.com/spider-gazelle/neuroplastic.git - version: 1.12.0 + version: 1.12.1 open_api: git: https://github.com/elbywan/open_api.cr.git diff --git a/src/source/publishing/influx_publisher.cr b/src/source/publishing/influx_publisher.cr index 6f76261..bafa6bf 100644 --- a/src/source/publishing/influx_publisher.cr +++ b/src/source/publishing/influx_publisher.cr @@ -15,6 +15,8 @@ module PlaceOS::Source getter client : Flux::Client getter bucket : String + alias FieldTypes = Bool | Float64 | String + abstract class CustomMetrics include JSON::Serializable @@ -23,7 +25,7 @@ module PlaceOS::Source # Add these tags and fields to all the values property ts_tags : Hash(String, String?)? - property ts_fields : Hash(String, Flux::Point::FieldType?)? + property ts_fields : Hash(String, FieldTypes?)? # Allow custom measurement name to be used for entries property measurement : String? @@ -32,12 +34,12 @@ module PlaceOS::Source class ComplexMetric < CustomMetrics getter ts_hint : String = "complex" - property value : Array(Hash(String, Flux::Point::FieldType?)) + property value : Array(Hash(String, FieldTypes?)) property ts_tag_keys : Array(String)? property ts_map : Hash(String, String)? end - alias Value = Flux::Point::FieldType | Hash(String, Flux::Point::FieldType?) | Hash(String, Hash(String, Flux::Point::FieldType?)) | Array(Hash(String, Flux::Point::FieldType?)) | CustomMetrics + alias Value = FieldTypes | Hash(String, FieldTypes?) | Hash(String, Hash(String, FieldTypes?)) | Array(Hash(String, FieldTypes?)) | CustomMetrics def initialize(@client : Flux::Client, @bucket : String) end @@ -92,7 +94,7 @@ module PlaceOS::Source begin case raw = Value.from_json(payload) in CustomMetrics then parse_custom(raw, fields, tags, data, timestamp) - in Flux::Point::FieldType + in FieldTypes fields[key] = raw point = Flux::Point.new!( measurement: data.module_name, @@ -102,16 +104,16 @@ module PlaceOS::Source ).tap &.fields.merge!(fields) [point] - in Hash(String, Flux::Point::FieldType?) + in Hash(String, FieldTypes?) [parse_hash(raw, nil, fields, tags, data, timestamp)].compact - in Hash(String, Hash(String, Flux::Point::FieldType?)) + in Hash(String, Hash(String, FieldTypes?)) pos_uniq = 0 raw.compact_map do |hash_key, hash| tags["pos_uniq"] = pos_uniq.to_s pos_uniq += 1 parse_hash(hash, hash_key, fields, tags, data, timestamp) end - in Array(Hash(String, Flux::Point::FieldType?)) + in Array(Hash(String, FieldTypes?)) pos_uniq = 0 raw.compact_map do |hash| tags["pos_uniq"] = pos_uniq.to_s