openc3 5.0.11 → 5.1.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of openc3 might be problematic. Click here for more details.

Files changed (280) hide show
  1. checksums.yaml +4 -4
  2. data/Guardfile +3 -0
  3. data/LICENSE.txt +7 -5
  4. data/README.md +11 -9
  5. data/Rakefile +3 -0
  6. data/bin/cstol_converter +3 -0
  7. data/bin/openc3cli +29 -18
  8. data/bin/rubysloc +3 -0
  9. data/data/config/screen.yaml +10 -2
  10. data/data/config/target.yaml +1 -1
  11. data/data/config/widgets.yaml +6 -6
  12. data/ext/mkrf_conf.rb +3 -0
  13. data/ext/openc3/ext/array/array.c +3 -0
  14. data/ext/openc3/ext/buffered_file/buffered_file.c +3 -0
  15. data/ext/openc3/ext/config_parser/config_parser.c +3 -0
  16. data/ext/openc3/ext/crc/crc.c +3 -0
  17. data/ext/openc3/ext/openc3_io/openc3_io.c +3 -0
  18. data/ext/openc3/ext/packet/packet.c +3 -0
  19. data/ext/openc3/ext/platform/platform.c +3 -0
  20. data/ext/openc3/ext/polynomial_conversion/polynomial_conversion.c +3 -0
  21. data/ext/openc3/ext/string/string.c +3 -0
  22. data/ext/openc3/ext/structure/structure.c +3 -0
  23. data/ext/openc3/ext/tabbed_plots_config/tabbed_plots_config.c +3 -0
  24. data/ext/openc3/ext/telemetry/telemetry.c +3 -0
  25. data/lib/cosmos.rb +3 -0
  26. data/lib/cosmosc2.rb +3 -0
  27. data/lib/openc3/accessors/accessor.rb +3 -0
  28. data/lib/openc3/accessors/binary_accessor.rb +3 -0
  29. data/lib/openc3/accessors/cbor_accessor.rb +3 -0
  30. data/lib/openc3/accessors/html_accessor.rb +3 -0
  31. data/lib/openc3/accessors/json_accessor.rb +4 -1
  32. data/lib/openc3/accessors/xml_accessor.rb +3 -0
  33. data/lib/openc3/accessors.rb +3 -0
  34. data/lib/openc3/api/api.rb +3 -0
  35. data/lib/openc3/api/authorized_api.rb +3 -0
  36. data/lib/openc3/api/cmd_api.rb +6 -3
  37. data/lib/openc3/api/config_api.rb +3 -0
  38. data/lib/openc3/api/interface_api.rb +6 -2
  39. data/lib/openc3/api/limits_api.rb +54 -61
  40. data/lib/openc3/api/router_api.rb +6 -3
  41. data/lib/openc3/api/settings_api.rb +3 -0
  42. data/lib/openc3/api/target_api.rb +3 -0
  43. data/lib/openc3/api/tlm_api.rb +27 -32
  44. data/lib/openc3/bridge/bridge.rb +3 -0
  45. data/lib/openc3/bridge/bridge_config.rb +3 -0
  46. data/lib/openc3/bridge/bridge_interface_thread.rb +3 -0
  47. data/lib/openc3/bridge/bridge_router_thread.rb +3 -0
  48. data/lib/openc3/ccsds/ccsds_packet.rb +3 -0
  49. data/lib/openc3/ccsds/ccsds_parser.rb +3 -0
  50. data/lib/openc3/config/config_parser.rb +3 -0
  51. data/lib/openc3/config/meta_config_parser.rb +3 -0
  52. data/lib/openc3/conversions/conversion.rb +3 -0
  53. data/lib/openc3/conversions/generic_conversion.rb +3 -0
  54. data/lib/openc3/conversions/packet_time_formatted_conversion.rb +3 -0
  55. data/lib/openc3/conversions/packet_time_seconds_conversion.rb +3 -0
  56. data/lib/openc3/conversions/polynomial_conversion.rb +3 -0
  57. data/lib/openc3/conversions/processor_conversion.rb +3 -0
  58. data/lib/openc3/conversions/received_count_conversion.rb +3 -0
  59. data/lib/openc3/conversions/received_time_formatted_conversion.rb +3 -0
  60. data/lib/openc3/conversions/received_time_seconds_conversion.rb +3 -0
  61. data/lib/openc3/conversions/segmented_polynomial_conversion.rb +3 -0
  62. data/lib/openc3/conversions/unix_time_conversion.rb +3 -0
  63. data/lib/openc3/conversions/unix_time_formatted_conversion.rb +3 -0
  64. data/lib/openc3/conversions/unix_time_seconds_conversion.rb +3 -0
  65. data/lib/openc3/conversions.rb +3 -0
  66. data/lib/openc3/core_ext/array.rb +3 -0
  67. data/lib/openc3/core_ext/binding.rb +3 -0
  68. data/lib/openc3/core_ext/class.rb +3 -0
  69. data/lib/openc3/core_ext/exception.rb +3 -0
  70. data/lib/openc3/core_ext/file.rb +3 -0
  71. data/lib/openc3/core_ext/hash.rb +3 -0
  72. data/lib/openc3/core_ext/io.rb +3 -0
  73. data/lib/openc3/core_ext/kernel.rb +3 -0
  74. data/lib/openc3/core_ext/math.rb +3 -0
  75. data/lib/openc3/core_ext/matrix.rb +3 -0
  76. data/lib/openc3/core_ext/objectspace.rb +3 -0
  77. data/lib/openc3/core_ext/openc3_io.rb +3 -0
  78. data/lib/openc3/core_ext/range.rb +3 -0
  79. data/lib/openc3/core_ext/socket.rb +3 -0
  80. data/lib/openc3/core_ext/string.rb +3 -0
  81. data/lib/openc3/core_ext/stringio.rb +3 -0
  82. data/lib/openc3/core_ext/tempfile.rb +3 -0
  83. data/lib/openc3/core_ext/time.rb +3 -0
  84. data/lib/openc3/core_ext.rb +3 -0
  85. data/lib/openc3/interfaces/interface.rb +3 -0
  86. data/lib/openc3/interfaces/linc_interface.rb +3 -0
  87. data/lib/openc3/interfaces/protocols/burst_protocol.rb +3 -0
  88. data/lib/openc3/interfaces/protocols/crc_protocol.rb +3 -0
  89. data/lib/openc3/interfaces/protocols/fixed_protocol.rb +3 -0
  90. data/lib/openc3/interfaces/protocols/ignore_packet_protocol.rb +3 -0
  91. data/lib/openc3/interfaces/protocols/length_protocol.rb +3 -0
  92. data/lib/openc3/interfaces/protocols/override_protocol.rb +3 -0
  93. data/lib/openc3/interfaces/protocols/preidentified_protocol.rb +3 -0
  94. data/lib/openc3/interfaces/protocols/protocol.rb +3 -0
  95. data/lib/openc3/interfaces/protocols/template_protocol.rb +3 -0
  96. data/lib/openc3/interfaces/protocols/terminated_protocol.rb +3 -0
  97. data/lib/openc3/interfaces/serial_interface.rb +3 -0
  98. data/lib/openc3/interfaces/simulated_target_interface.rb +3 -0
  99. data/lib/openc3/interfaces/stream_interface.rb +3 -0
  100. data/lib/openc3/interfaces/tcpip_client_interface.rb +3 -0
  101. data/lib/openc3/interfaces/tcpip_server_interface.rb +3 -0
  102. data/lib/openc3/interfaces/udp_interface.rb +3 -0
  103. data/lib/openc3/interfaces.rb +3 -0
  104. data/lib/openc3/io/buffered_file.rb +3 -0
  105. data/lib/openc3/io/io_multiplexer.rb +8 -0
  106. data/lib/openc3/io/json_api_object.rb +5 -2
  107. data/lib/openc3/io/json_drb.rb +3 -0
  108. data/lib/openc3/io/json_drb_object.rb +5 -2
  109. data/lib/openc3/io/json_drb_rack.rb +3 -0
  110. data/lib/openc3/io/json_rpc.rb +8 -3
  111. data/lib/openc3/io/openc3_snmp.rb +3 -0
  112. data/lib/openc3/io/posix_serial_driver.rb +3 -0
  113. data/lib/openc3/io/raw_logger.rb +3 -0
  114. data/lib/openc3/io/raw_logger_pair.rb +3 -0
  115. data/lib/openc3/io/serial_driver.rb +3 -0
  116. data/lib/openc3/io/stderr.rb +3 -0
  117. data/lib/openc3/io/stdout.rb +3 -0
  118. data/lib/openc3/io/udp_sockets.rb +3 -0
  119. data/lib/openc3/io/win32_serial_driver.rb +3 -0
  120. data/lib/openc3/logs/buffered_packet_log_reader.rb +65 -0
  121. data/lib/openc3/logs/buffered_packet_log_writer.rb +120 -0
  122. data/lib/openc3/logs/log_writer.rb +95 -40
  123. data/lib/openc3/logs/packet_log_constants.rb +9 -0
  124. data/lib/openc3/logs/packet_log_reader.rb +34 -3
  125. data/lib/openc3/logs/packet_log_writer.rb +85 -18
  126. data/lib/openc3/logs/text_log_writer.rb +9 -5
  127. data/lib/openc3/logs.rb +8 -2
  128. data/lib/openc3/microservices/cleanup_microservice.rb +18 -18
  129. data/lib/openc3/microservices/decom_microservice.rb +30 -24
  130. data/lib/openc3/microservices/interface_microservice.rb +136 -91
  131. data/lib/openc3/microservices/log_microservice.rb +35 -13
  132. data/lib/openc3/microservices/microservice.rb +16 -14
  133. data/lib/openc3/microservices/plugin_microservice.rb +3 -1
  134. data/lib/openc3/microservices/reaction_microservice.rb +4 -1
  135. data/lib/openc3/microservices/reducer_microservice.rb +332 -149
  136. data/lib/openc3/microservices/router_microservice.rb +3 -0
  137. data/lib/openc3/microservices/text_log_microservice.rb +22 -7
  138. data/lib/openc3/microservices/timeline_microservice.rb +4 -1
  139. data/lib/openc3/microservices/trigger_group_microservice.rb +3 -0
  140. data/lib/openc3/models/activity_model.rb +3 -0
  141. data/lib/openc3/models/auth_model.rb +3 -0
  142. data/lib/openc3/models/cvt_model.rb +14 -5
  143. data/lib/openc3/models/environment_model.rb +3 -0
  144. data/lib/openc3/models/gem_model.rb +30 -51
  145. data/lib/openc3/models/info_model.rb +3 -0
  146. data/lib/openc3/models/interface_model.rb +3 -0
  147. data/lib/openc3/models/interface_status_model.rb +4 -1
  148. data/lib/openc3/models/metadata_model.rb +3 -0
  149. data/lib/openc3/models/metric_model.rb +3 -0
  150. data/lib/openc3/models/microservice_model.rb +9 -6
  151. data/lib/openc3/models/microservice_status_model.rb +4 -1
  152. data/lib/openc3/models/model.rb +3 -0
  153. data/lib/openc3/models/note_model.rb +3 -0
  154. data/lib/openc3/models/notification_model.rb +3 -0
  155. data/lib/openc3/models/ping_model.rb +3 -0
  156. data/lib/openc3/models/plugin_model.rb +20 -14
  157. data/lib/openc3/models/process_status_model.rb +4 -1
  158. data/lib/openc3/models/reaction_model.rb +3 -0
  159. data/lib/openc3/models/reducer_model.rb +31 -24
  160. data/lib/openc3/models/router_model.rb +3 -0
  161. data/lib/openc3/models/router_status_model.rb +3 -0
  162. data/lib/openc3/models/scope_model.rb +3 -4
  163. data/lib/openc3/models/settings_model.rb +3 -0
  164. data/lib/openc3/models/sorted_model.rb +3 -0
  165. data/lib/openc3/models/target_model.rb +61 -94
  166. data/lib/openc3/models/timeline_model.rb +4 -1
  167. data/lib/openc3/models/tool_config_model.rb +3 -0
  168. data/lib/openc3/models/tool_model.rb +11 -9
  169. data/lib/openc3/models/trigger_group_model.rb +3 -0
  170. data/lib/openc3/models/trigger_model.rb +3 -0
  171. data/lib/openc3/models/widget_model.rb +18 -11
  172. data/lib/openc3/operators/microservice_operator.rb +3 -0
  173. data/lib/openc3/operators/operator.rb +105 -34
  174. data/lib/openc3/packets/commands.rb +3 -0
  175. data/lib/openc3/packets/json_packet.rb +87 -14
  176. data/lib/openc3/packets/limits.rb +4 -1
  177. data/lib/openc3/packets/limits_response.rb +3 -0
  178. data/lib/openc3/packets/packet.rb +5 -1
  179. data/lib/openc3/packets/packet_config.rb +3 -0
  180. data/lib/openc3/packets/packet_item.rb +9 -3
  181. data/lib/openc3/packets/packet_item_limits.rb +3 -0
  182. data/lib/openc3/packets/parsers/format_string_parser.rb +3 -0
  183. data/lib/openc3/packets/parsers/limits_parser.rb +3 -0
  184. data/lib/openc3/packets/parsers/limits_response_parser.rb +3 -0
  185. data/lib/openc3/packets/parsers/packet_item_parser.rb +3 -0
  186. data/lib/openc3/packets/parsers/packet_parser.rb +3 -0
  187. data/lib/openc3/packets/parsers/processor_parser.rb +3 -0
  188. data/lib/openc3/packets/parsers/state_parser.rb +3 -0
  189. data/lib/openc3/packets/parsers/xtce_converter.rb +3 -0
  190. data/lib/openc3/packets/parsers/xtce_parser.rb +3 -0
  191. data/lib/openc3/packets/structure.rb +3 -0
  192. data/lib/openc3/packets/structure_item.rb +3 -0
  193. data/lib/openc3/packets/telemetry.rb +3 -0
  194. data/lib/openc3/processors/processor.rb +3 -0
  195. data/lib/openc3/processors/statistics_processor.rb +3 -0
  196. data/lib/openc3/processors/watermark_processor.rb +3 -0
  197. data/lib/openc3/processors.rb +3 -0
  198. data/lib/openc3/script/api_shared.rb +35 -6
  199. data/lib/openc3/script/calendar.rb +3 -0
  200. data/lib/openc3/script/commands.rb +3 -0
  201. data/lib/openc3/script/exceptions.rb +3 -0
  202. data/lib/openc3/script/extract.rb +3 -0
  203. data/lib/openc3/script/limits.rb +3 -24
  204. data/lib/openc3/script/script.rb +11 -7
  205. data/lib/openc3/script/script_runner.rb +3 -0
  206. data/lib/openc3/script/storage.rb +33 -16
  207. data/lib/openc3/script/suite.rb +3 -0
  208. data/lib/openc3/script/suite_results.rb +3 -0
  209. data/lib/openc3/script/suite_runner.rb +3 -0
  210. data/lib/openc3/script/telemetry.rb +43 -0
  211. data/lib/openc3/script.rb +3 -0
  212. data/lib/openc3/streams/serial_stream.rb +3 -0
  213. data/lib/openc3/streams/stream.rb +3 -0
  214. data/lib/openc3/streams/tcpip_client_stream.rb +3 -0
  215. data/lib/openc3/streams/tcpip_socket_stream.rb +3 -0
  216. data/lib/openc3/system/system.rb +23 -10
  217. data/lib/openc3/system/system_config.rb +3 -0
  218. data/lib/openc3/system/target.rb +3 -0
  219. data/lib/openc3/system.rb +3 -0
  220. data/lib/openc3/tools/cmd_tlm_server/api.rb +3 -0
  221. data/lib/openc3/tools/cmd_tlm_server/cmd_tlm_server_config.rb +3 -0
  222. data/lib/openc3/tools/cmd_tlm_server/interface_thread.rb +3 -0
  223. data/lib/openc3/tools/table_manager/table.rb +3 -0
  224. data/lib/openc3/tools/table_manager/table_config.rb +3 -0
  225. data/lib/openc3/tools/table_manager/table_item.rb +3 -0
  226. data/lib/openc3/tools/table_manager/table_item_parser.rb +3 -0
  227. data/lib/openc3/tools/table_manager/table_manager_core.rb +3 -0
  228. data/lib/openc3/tools/table_manager/table_parser.rb +3 -0
  229. data/lib/openc3/tools/test_runner/test.rb +3 -0
  230. data/lib/openc3/top_level.rb +3 -0
  231. data/lib/openc3/topics/autonomic_topic.rb +3 -0
  232. data/lib/openc3/topics/calendar_topic.rb +3 -0
  233. data/lib/openc3/topics/command_decom_topic.rb +4 -1
  234. data/lib/openc3/topics/command_topic.rb +6 -1
  235. data/lib/openc3/topics/config_topic.rb +3 -0
  236. data/lib/openc3/topics/interface_topic.rb +9 -2
  237. data/lib/openc3/topics/limits_event_topic.rb +144 -10
  238. data/lib/openc3/topics/notifications_topic.rb +3 -0
  239. data/lib/openc3/topics/router_topic.rb +10 -3
  240. data/lib/openc3/topics/telemetry_decom_topic.rb +26 -20
  241. data/lib/openc3/topics/telemetry_reduced_topics.rb +92 -0
  242. data/lib/openc3/topics/telemetry_topic.rb +5 -2
  243. data/lib/openc3/topics/timeline_topic.rb +3 -0
  244. data/lib/openc3/topics/topic.rb +3 -0
  245. data/lib/openc3/utilities/authentication.rb +3 -0
  246. data/lib/openc3/utilities/authorization.rb +3 -0
  247. data/lib/openc3/utilities/aws_bucket.rb +199 -0
  248. data/lib/openc3/utilities/bucket.rb +82 -0
  249. data/lib/openc3/utilities/bucket_file_cache.rb +264 -0
  250. data/lib/openc3/utilities/bucket_utilities.rb +109 -0
  251. data/lib/openc3/utilities/crc.rb +3 -0
  252. data/lib/openc3/utilities/csv.rb +3 -0
  253. data/lib/openc3/utilities/local_bucket.rb +28 -0
  254. data/lib/openc3/utilities/local_mode.rb +47 -61
  255. data/lib/openc3/utilities/logger.rb +7 -1
  256. data/lib/openc3/utilities/message_log.rb +7 -4
  257. data/lib/openc3/utilities/metric.rb +4 -1
  258. data/lib/openc3/utilities/open_telemetry.rb +96 -0
  259. data/lib/openc3/utilities/process_manager.rb +3 -0
  260. data/lib/openc3/utilities/quaternion.rb +3 -0
  261. data/lib/openc3/utilities/ruby_lex_utils.rb +3 -0
  262. data/lib/openc3/utilities/s3_autoload.rb +3 -3
  263. data/lib/openc3/utilities/simulated_target.rb +3 -0
  264. data/lib/openc3/utilities/sleeper.rb +3 -0
  265. data/lib/openc3/utilities/store.rb +3 -0
  266. data/lib/openc3/utilities/store_autoload.rb +30 -23
  267. data/lib/openc3/utilities/target_file.rb +70 -83
  268. data/lib/openc3/utilities/zip.rb +3 -0
  269. data/lib/openc3/utilities.rb +3 -0
  270. data/lib/openc3/version.rb +6 -6
  271. data/lib/openc3/win32/excel.rb +3 -0
  272. data/lib/openc3/win32/win32.rb +3 -0
  273. data/lib/openc3/win32/win32_main.rb +3 -0
  274. data/lib/openc3.rb +3 -0
  275. data/tasks/gemfile_stats.rake +3 -0
  276. data/tasks/spec.rake +3 -0
  277. data/templates/plugin-template/plugin.gemspec +1 -1
  278. metadata +112 -6
  279. data/lib/openc3/utilities/s3.rb +0 -220
  280. data/lib/openc3/utilities/s3_file_cache.rb +0 -274
@@ -16,9 +16,13 @@
16
16
  # Modified by OpenC3, Inc.
17
17
  # All changes Copyright 2022, OpenC3, Inc.
18
18
  # All Rights Reserved
19
+ #
20
+ # This file may also be used under the terms of a commercial license
21
+ # if purchased from OpenC3, Inc.
19
22
 
20
23
  require 'openc3/logs/log_writer'
21
24
  require 'openc3/logs/packet_log_constants'
25
+ require 'cbor'
22
26
 
23
27
  module OpenC3
24
28
  # Creates a packet log. Can automatically cycle the log based on an elasped
@@ -26,7 +30,9 @@ module OpenC3
26
30
  class PacketLogWriter < LogWriter
27
31
  include PacketLogConstants
28
32
 
29
- # @param remote_log_directory [String] The s3 path to store the log files
33
+ attr_accessor :data_format
34
+
35
+ # @param remote_log_directory [String] The path to store the log files
30
36
  # @param label [String] Label to apply to the log filename
31
37
  # @param logging_enabled [Boolean] Whether to start with logging enabled
32
38
  # @param cycle_time [Integer] The amount of time in seconds before creating
@@ -40,8 +46,6 @@ module OpenC3
40
46
  # will be cycled hourly at the specified cycle_minute.
41
47
  # @param cycle_minute [Integer] The time at which to cycle the log. See cycle_hour
42
48
  # for more information.
43
- # @param redis_topic [String] The key of the Redis stream to trim when files are
44
- # moved to S3
45
49
  def initialize(
46
50
  remote_log_directory,
47
51
  label,
@@ -50,7 +54,7 @@ module OpenC3
50
54
  cycle_size = 1_000_000_000,
51
55
  cycle_hour = nil,
52
56
  cycle_minute = nil,
53
- redis_topic: nil
57
+ enforce_time_order = true
54
58
  )
55
59
  super(
56
60
  remote_log_directory,
@@ -59,18 +63,21 @@ module OpenC3
59
63
  cycle_size,
60
64
  cycle_hour,
61
65
  cycle_minute,
62
- redis_topic: redis_topic
66
+ enforce_time_order
63
67
  )
64
68
  @label = label
65
69
  @index_file = nil
66
70
  @index_filename = nil
67
71
  @cmd_packet_table = {}
68
72
  @tlm_packet_table = {}
73
+ @key_map_table = {}
69
74
  @target_dec_entries = []
70
75
  @packet_dec_entries = []
76
+ @key_map_entries = []
71
77
  @next_packet_index = 0
72
78
  @target_indexes = {}
73
79
  @next_target_index = 0
80
+ @data_format = :CBOR # Default to CBOR for improved compression
74
81
 
75
82
  # This is an optimization to avoid creating a new entry object
76
83
  # each time we create an entry which we do a LOT!
@@ -83,7 +90,7 @@ module OpenC3
83
90
  # created.
84
91
  #
85
92
  # @param entry_type [Symbol] Type of entry to write. Must be one of
86
- # :TARGET_DECLARATION, :PACKET_DECLARATION, :RAW_PACKET, :JSON_PACKET
93
+ # :TARGET_DECLARATION, :PACKET_DECLARATION, :RAW_PACKET, :JSON_PACKET, :OFFSET_MARKER, :KEY_MAP
87
94
  # @param cmd_or_tlm [Symbol] One of :CMD or :TLM
88
95
  # @param target_name [String] Name of the target
89
96
  # @param packet_name [String] Name of the packet
@@ -92,11 +99,11 @@ module OpenC3
92
99
  # @param data [String] Binary string of data
93
100
  # @param id [Integer] Target ID
94
101
  # @param redis_offset [Integer] The offset of this packet in its Redis stream
95
- def write(entry_type, cmd_or_tlm, target_name, packet_name, time_nsec_since_epoch, stored, data, id = nil, redis_offset = '0-0')
102
+ def write(entry_type, cmd_or_tlm, target_name, packet_name, time_nsec_since_epoch, stored, data, id = nil, redis_topic = nil, redis_offset = '0-0')
96
103
  return if !@logging_enabled
97
104
 
98
105
  @mutex.synchronize do
99
- prepare_write(time_nsec_since_epoch, data.length, redis_offset)
106
+ prepare_write(time_nsec_since_epoch, data.length, redis_topic, redis_offset)
100
107
  write_entry(entry_type, cmd_or_tlm, target_name, packet_name, time_nsec_since_epoch, stored, data, id) if @file
101
108
  end
102
109
  rescue => err
@@ -119,10 +126,12 @@ module OpenC3
119
126
 
120
127
  @cmd_packet_table = {}
121
128
  @tlm_packet_table = {}
129
+ @key_map_table = {}
122
130
  @next_packet_index = 0
123
131
  @target_indexes = {}
124
132
  @target_dec_entries = []
125
133
  @packet_dec_entries = []
134
+ @key_map_entries = []
126
135
  Logger.debug "Index Log File Opened : #{@index_filename}"
127
136
  rescue => err
128
137
  Logger.error "Error starting new log file: #{err.formatted}"
@@ -131,20 +140,26 @@ module OpenC3
131
140
  end
132
141
 
133
142
  # Closing a log file isn't critical so we just log an error
143
+ # Returns threads that moves log to bucket
134
144
  def close_file(take_mutex = true)
135
- write_entry(:OFFSET_MARKER, nil, nil, nil, nil, nil, nil, nil) if @file
136
- super
137
-
145
+ threads = []
138
146
  @mutex.lock if take_mutex
139
147
  begin
148
+ # Need to write the OFFSET_MARKER for each packet
149
+ @last_offsets.each do |redis_topic, last_offset|
150
+ write_entry(:OFFSET_MARKER, nil, nil, nil, nil, nil, last_offset + ',' + redis_topic, nil) if @file
151
+ end
152
+
153
+ threads.concat(super(false))
154
+
140
155
  if @index_file
141
156
  begin
142
157
  write_index_file_footer()
143
158
  @index_file.close unless @index_file.closed?
144
159
  Logger.debug "Index Log File Closed : #{@index_filename}"
145
160
  date = first_timestamp[0..7] # YYYYMMDD
146
- s3_key = File.join(@remote_log_directory, date, "#{first_timestamp}__#{last_timestamp}__#{@label}.idx")
147
- S3Utilities.move_log_file_to_s3(@index_filename, s3_key)
161
+ bucket_key = File.join(@remote_log_directory, date, "#{first_timestamp}__#{last_timestamp}__#{@label}.idx")
162
+ threads << BucketUtilities.move_log_file_to_bucket(@index_filename, bucket_key)
148
163
  rescue Exception => err
149
164
  Logger.instance.error "Error closing #{@index_filename} : #{err.formatted}"
150
165
  end
@@ -155,9 +170,10 @@ module OpenC3
155
170
  ensure
156
171
  @mutex.unlock if take_mutex
157
172
  end
173
+ return threads
158
174
  end
159
175
 
160
- def get_packet_index(cmd_or_tlm, target_name, packet_name)
176
+ def get_packet_index(cmd_or_tlm, target_name, packet_name, entry_type, data)
161
177
  if cmd_or_tlm == :CMD
162
178
  target_table = @cmd_packet_table[target_name]
163
179
  else
@@ -200,6 +216,26 @@ module OpenC3
200
216
  # No packet def
201
217
  end
202
218
  write_entry(:PACKET_DECLARATION, cmd_or_tlm, target_name, packet_name, nil, nil, nil, id)
219
+ if entry_type == :JSON_PACKET
220
+ key_map = @key_map_table[packet_index]
221
+ unless key_map
222
+ parsed = data
223
+ parsed = JSON.parse(data, :allow_nan => true, :create_additions => true) if String === parsed
224
+ keys = parsed.keys
225
+ key_map = {}
226
+ reverse_key_map = {}
227
+ keys.each_with_index do |key, index|
228
+ key_map[index.to_s] = key
229
+ reverse_key_map[key] = index.to_s
230
+ end
231
+ @key_map_table[packet_index] = reverse_key_map
232
+ if @data_format == :CBOR
233
+ write_entry(:KEY_MAP, cmd_or_tlm, target_name, packet_name, nil, nil, key_map.to_cbor, nil)
234
+ else # JSON
235
+ write_entry(:KEY_MAP, cmd_or_tlm, target_name, packet_name, nil, nil, JSON.generate(key_map, :allow_nan => true), nil)
236
+ end
237
+ end
238
+ end
203
239
  return packet_index
204
240
  end
205
241
 
@@ -238,19 +274,44 @@ module OpenC3
238
274
  @entry << [length, flags, target_index].pack(OPENC3_PACKET_DECLARATION_PACK_DIRECTIVE) << packet_name
239
275
  @entry << [id].pack('H*') if id
240
276
  @packet_dec_entries << @entry.dup
277
+ when :KEY_MAP
278
+ flags |= OPENC3_KEY_MAP_ENTRY_TYPE_MASK
279
+ flags |= OPENC3_CBOR_FLAG_MASK if @data_format == :CBOR
280
+ length += OPENC3_KEY_MAP_SECONDARY_FIXED_SIZE + data.length
281
+ packet_index = get_packet_index(cmd_or_tlm, target_name, packet_name, entry_type, data)
282
+ @entry.clear
283
+ @entry << [length, flags, packet_index].pack(OPENC3_KEY_MAP_PACK_DIRECTIVE) << data
284
+ @key_map_entries << @entry.dup
241
285
  when :OFFSET_MARKER
242
286
  flags |= OPENC3_OFFSET_MARKER_ENTRY_TYPE_MASK
243
- length += OPENC3_OFFSET_MARKER_SECONDARY_FIXED_SIZE + @last_offset.length
287
+ length += OPENC3_OFFSET_MARKER_SECONDARY_FIXED_SIZE + data.length
244
288
  @entry.clear
245
- @entry << [length, flags].pack(OPENC3_OFFSET_MARKER_PACK_DIRECTIVE) << @last_offset
289
+ @entry << [length, flags].pack(OPENC3_OFFSET_MARKER_PACK_DIRECTIVE) << data
246
290
  when :RAW_PACKET, :JSON_PACKET
247
291
  target_name = 'UNKNOWN'.freeze unless target_name
248
292
  packet_name = 'UNKNOWN'.freeze unless packet_name
249
- packet_index = get_packet_index(cmd_or_tlm, target_name, packet_name)
293
+ packet_index = get_packet_index(cmd_or_tlm, target_name, packet_name, entry_type, data)
250
294
  if entry_type == :RAW_PACKET
251
295
  flags |= OPENC3_RAW_PACKET_ENTRY_TYPE_MASK
252
296
  else
253
297
  flags |= OPENC3_JSON_PACKET_ENTRY_TYPE_MASK
298
+ key_map = @key_map_table[packet_index]
299
+ if key_map
300
+ # Compress data using key map
301
+ data = JSON.parse(data, :allow_nan => true, :create_additions => true) if String === data
302
+ compressed = {}
303
+ data.each do |key, value|
304
+ compressed_key = key_map[key]
305
+ compressed_key = key unless compressed_key
306
+ compressed[compressed_key] = value
307
+ end
308
+ if @data_format == :CBOR
309
+ flags |= OPENC3_CBOR_FLAG_MASK
310
+ data = compressed.to_cbor
311
+ else
312
+ data = JSON.generate(compressed, :allow_nan => true)
313
+ end
314
+ end
254
315
  end
255
316
  if cmd_or_tlm == :CMD
256
317
  flags |= OPENC3_CMD_FLAG_MASK
@@ -285,10 +346,16 @@ module OpenC3
285
346
  @index_file.write(packet_dec_entry)
286
347
  footer_length += packet_dec_entry.length
287
348
  end
349
+ @index_file.write([@key_map_entries.length].pack('n'))
350
+ footer_length += 2
351
+ @key_map_entries.each do |key_map_entry|
352
+ @index_file.write(key_map_entry)
353
+ footer_length += key_map_entry.length
354
+ end
288
355
  @index_file.write([footer_length].pack('N'))
289
356
  end
290
357
 
291
- def s3_filename
358
+ def bucket_filename
292
359
  "#{first_timestamp}__#{last_timestamp}__#{@label}" + extension
293
360
  end
294
361
 
@@ -16,6 +16,9 @@
16
16
  # Modified by OpenC3, Inc.
17
17
  # All changes Copyright 2022, OpenC3, Inc.
18
18
  # All Rights Reserved
19
+ #
20
+ # This file may also be used under the terms of a commercial license
21
+ # if purchased from OpenC3, Inc.
19
22
 
20
23
  require 'openc3/logs/log_writer'
21
24
 
@@ -31,11 +34,11 @@ module OpenC3
31
34
  # @param time_nsec_since_epoch [Integer] 64 bit integer nsecs since EPOCH
32
35
  # @param data [String] String of data
33
36
  # @param redis_offset [Integer] The offset of this packet in its Redis stream
34
- def write(time_nsec_since_epoch, data, redis_offset)
37
+ def write(time_nsec_since_epoch, data, redis_topic, redis_offset)
35
38
  return if !@logging_enabled
36
39
 
37
40
  @mutex.synchronize do
38
- prepare_write(time_nsec_since_epoch, data.length, redis_offset)
41
+ prepare_write(time_nsec_since_epoch, data.length, redis_topic, redis_offset)
39
42
  write_entry(time_nsec_since_epoch, data) if @file
40
43
  end
41
44
  rescue => err
@@ -53,11 +56,12 @@ module OpenC3
53
56
  @last_time = time_nsec_since_epoch if !@last_time or time_nsec_since_epoch > @last_time
54
57
  end
55
58
 
56
- def s3_filename
59
+ def bucket_filename
57
60
  # Put the name of the redis topic in the filename, but remove the scope
58
61
  # because we're already in a directory with the scope name
59
- split_index = @redis_topic.index("__") + 2
60
- topic_name = @redis_topic[split_index, @redis_topic.length - split_index]
62
+ redis_topic = @last_offsets.keys[0].to_s
63
+ split_index = redis_topic.index("__") + 2
64
+ topic_name = redis_topic[split_index, redis_topic.length - split_index]
61
65
  "#{first_timestamp}__#{last_timestamp}__#{topic_name}" + extension
62
66
  end
63
67
 
data/lib/openc3/logs.rb CHANGED
@@ -16,10 +16,16 @@
16
16
  # Modified by OpenC3, Inc.
17
17
  # All changes Copyright 2022, OpenC3, Inc.
18
18
  # All Rights Reserved
19
+ #
20
+ # This file may also be used under the terms of a commercial license
21
+ # if purchased from OpenC3, Inc.
19
22
 
20
23
  module OpenC3
21
- autoload(:PacketLogWriter, 'openc3/logs/packet_log_writer.rb')
22
- autoload(:PacketLogWriterPair, 'openc3/logs/packet_log_writer_pair.rb')
24
+ autoload(:BufferedPacketLogReader, 'openc3/logs/buffered_packet_log_reader.rb')
25
+ autoload(:BufferedPacketLogWriter, 'openc3/logs/buffered_packet_log_writer.rb')
26
+ autoload(:LogWriter, 'openc3/logs/log_writer.rb')
27
+ autoload(:PacketLogConstants, 'openc3/logs/packet_log_constants.rb')
23
28
  autoload(:PacketLogReader, 'openc3/logs/packet_log_reader.rb')
29
+ autoload(:PacketLogWriter, 'openc3/logs/packet_log_writer.rb')
24
30
  autoload(:TextLogWriter, 'openc3/logs/text_log_writer.rb')
25
31
  end
@@ -16,10 +16,14 @@
16
16
  # Modified by OpenC3, Inc.
17
17
  # All changes Copyright 2022, OpenC3, Inc.
18
18
  # All Rights Reserved
19
+ #
20
+ # This file may also be used under the terms of a commercial license
21
+ # if purchased from OpenC3, Inc.
19
22
 
20
23
  require 'openc3/models/target_model'
21
24
  require 'openc3/microservices/microservice'
22
- require 'openc3/utilities/s3'
25
+ require 'openc3/utilities/bucket'
26
+ require 'openc3/utilities/bucket_utilities'
23
27
 
24
28
  module OpenC3
25
29
  class CleanupMicroservice < Microservice
@@ -28,33 +32,29 @@ module OpenC3
28
32
  target_name = split_name[-1]
29
33
  target = TargetModel.get_model(name: target_name, scope: @scope)
30
34
 
31
- rubys3_client = Aws::S3::Client.new
35
+ bucket = Bucket.getClient()
32
36
  while true
33
37
  break if @cancel_thread
34
38
 
35
39
  @state = 'GETTING_OBJECTS'
36
40
  start_time = Time.now
37
41
  [
38
- ["#{@scope}/raw_logs/cmd/#{target_name}/", target.cmd_log_retain_time],
39
- ["#{@scope}/decom_logs/cmd/#{target_name}/", target.cmd_decom_log_retain_time],
40
- ["#{@scope}/raw_logs/tlm/#{target_name}/", target.tlm_log_retain_time],
41
- ["#{@scope}/decom_logs/tlm/#{target_name}/", target.tlm_decom_log_retain_time],
42
- ["#{@scope}/reduced_minute_logs/tlm/#{target_name}/", target.reduced_minute_log_retain_time],
43
- ["#{@scope}/reduced_hour_logs/tlm/#{target_name}/", target.reduced_hour_log_retain_time],
44
- ["#{@scope}/reduced_day_logs/tlm/#{target_name}/", target.reduced_day_log_retain_time],
42
+ ["#{@scope}/raw_logs/cmd/#{target_name}", target.cmd_log_retain_time],
43
+ ["#{@scope}/decom_logs/cmd/#{target_name}", target.cmd_decom_log_retain_time],
44
+ ["#{@scope}/raw_logs/tlm/#{target_name}", target.tlm_log_retain_time],
45
+ ["#{@scope}/decom_logs/tlm/#{target_name}", target.tlm_decom_log_retain_time],
46
+ ["#{@scope}/reduced_minute_logs/tlm/#{target_name}", target.reduced_minute_log_retain_time],
47
+ ["#{@scope}/reduced_hour_logs/tlm/#{target_name}", target.reduced_hour_log_retain_time],
48
+ ["#{@scope}/reduced_day_logs/tlm/#{target_name}", target.reduced_day_log_retain_time],
45
49
  ].each do |prefix, retain_time|
46
50
  next unless retain_time
47
51
  time = start_time - retain_time
48
- total_size, oldest_list = S3Utilities.list_files_before_time('logs', prefix, time)
49
- delete_items = []
50
- oldest_list.each do |item|
51
- delete_items << { :key => item.key }
52
- end
53
- if delete_items.length > 0
52
+ oldest_list = BucketUtilities.list_files_before_time(ENV['OPENC3_LOGS_BUCKET'], prefix, time)
53
+ if oldest_list.length > 0
54
54
  @state = 'DELETING_OBJECTS'
55
- delete_items.each_slice(1000) do |delete_slice|
56
- rubys3_client.delete_objects({ bucket: 'logs', delete: { objects: delete_slice } })
57
- Logger.info("Deleted #{delete_slice.length} #{target_name} log files")
55
+ oldest_list.each_slice(1000) do |slice|
56
+ bucket.delete_objects(bucket: ENV['OPENC3_LOGS_BUCKET'], keys: slice)
57
+ Logger.info("Deleted #{slice.length} #{target_name} log files")
58
58
  end
59
59
  end
60
60
  end
@@ -16,6 +16,9 @@
16
16
  # Modified by OpenC3, Inc.
17
17
  # All changes Copyright 2022, OpenC3, Inc.
18
18
  # All Rights Reserved
19
+ #
20
+ # This file may also be used under the terms of a commercial license
21
+ # if purchased from OpenC3, Inc.
19
22
 
20
23
  require 'openc3/microservices/microservice'
21
24
  require 'openc3/topics/telemetry_decom_topic'
@@ -33,6 +36,7 @@ module OpenC3
33
36
  super(*args)
34
37
  Topic.update_topic_offsets(@topics)
35
38
  System.telemetry.limits_change_callback = method(:limits_change_callback)
39
+ LimitsEventTopic.sync_system(scope: @scope)
36
40
  end
37
41
 
38
42
  def run
@@ -40,12 +44,15 @@ module OpenC3
40
44
  break if @cancel_thread
41
45
 
42
46
  begin
43
- Topic.read_topics(@topics) do |topic, msg_id, msg_hash, redis|
44
- break if @cancel_thread
47
+ OpenC3.in_span("read_topics") do
48
+ Topic.read_topics(@topics) do |topic, msg_id, msg_hash, redis|
49
+ break if @cancel_thread
45
50
 
46
- decom_packet(topic, msg_id, msg_hash, redis)
47
- @count += 1
51
+ decom_packet(topic, msg_id, msg_hash, redis)
52
+ @count += 1
53
+ end
48
54
  end
55
+ LimitsEventTopic.sync_system_thread_body(scope: @scope)
49
56
  rescue => e
50
57
  @error = e
51
58
  Logger.error("Decom error: #{e.formatted}")
@@ -54,23 +61,23 @@ module OpenC3
54
61
  end
55
62
 
56
63
  def decom_packet(topic, _msg_id, msg_hash, _redis)
57
- start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
58
- target_name = msg_hash["target_name"]
59
- packet_name = msg_hash["packet_name"]
60
-
61
- current_limits_set = LimitsEventTopic.current_set(scope: @scope)
62
-
63
- packet = System.telemetry.packet(target_name, packet_name)
64
- packet.stored = ConfigParser.handle_true_false(msg_hash["stored"])
65
- packet.received_time = Time.from_nsec_from_epoch(msg_hash["time"].to_i)
66
- packet.received_count = msg_hash["received_count"].to_i
67
- packet.buffer = msg_hash["buffer"]
68
- packet.check_limits(current_limits_set.intern) # Process all the limits and call the limits_change_callback (as necessary)
69
-
70
- TelemetryDecomTopic.write_packet(packet, scope: @scope)
71
- diff = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start # seconds as a float
72
- metric_labels = { "packet" => packet_name, "target" => target_name }
73
- @metric.add_sample(name: DECOM_METRIC_NAME, value: diff, labels: metric_labels)
64
+ OpenC3.in_span("decom_packet") do
65
+ start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
66
+ target_name = msg_hash["target_name"]
67
+ packet_name = msg_hash["packet_name"]
68
+
69
+ packet = System.telemetry.packet(target_name, packet_name)
70
+ packet.stored = ConfigParser.handle_true_false(msg_hash["stored"])
71
+ packet.received_time = Time.from_nsec_from_epoch(msg_hash["time"].to_i)
72
+ packet.received_count = msg_hash["received_count"].to_i
73
+ packet.buffer = msg_hash["buffer"]
74
+ packet.check_limits(System.limits_set) # Process all the limits and call the limits_change_callback (as necessary)
75
+
76
+ TelemetryDecomTopic.write_packet(packet, scope: @scope)
77
+ diff = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start # seconds as a float
78
+ metric_labels = { "packet" => packet_name, "target" => target_name }
79
+ @metric.add_sample(name: DECOM_METRIC_NAME, value: diff, labels: metric_labels)
80
+ end
74
81
  end
75
82
 
76
83
  # Called when an item in any packet changes limits states.
@@ -96,7 +103,6 @@ module OpenC3
96
103
  when :YELLOW, :YELLOW_LOW, :YELLOW_HIGH
97
104
  Logger.warn message
98
105
  when :RED, :RED_LOW, :RED_HIGH
99
- # TODO: Is this necessary? The LimitsEventTopic is what communicates with LimitsMonitor
100
106
  notification = NotificationModel.new(
101
107
  time: time_nsec,
102
108
  severity: "critical",
@@ -111,8 +117,8 @@ module OpenC3
111
117
 
112
118
  # The openc3_limits_events topic can be listened to for all limits events, it is a continuous stream
113
119
  event = { type: :LIMITS_CHANGE, target_name: packet.target_name, packet_name: packet.packet_name,
114
- item_name: item.name, old_limits_state: old_limits_state, new_limits_state: item.limits.state,
115
- time_nsec: time_nsec, message: message }
120
+ item_name: item.name, old_limits_state: old_limits_state.to_s, new_limits_state: item.limits.state.to_s,
121
+ time_nsec: time_nsec, message: message.to_s }
116
122
  LimitsEventTopic.write(event, scope: @scope)
117
123
 
118
124
  if item.limits.response