openc3 7.5.1 → 7.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -0
- data/bin/openc3cli +82 -5
- data/data/config/_params.yaml +3 -0
- data/data/config/command_modifiers.yaml +5 -3
- data/data/config/default_plugins.yaml +1 -0
- data/data/config/interface_modifiers.yaml +17 -1
- data/data/config/item_modifiers.yaml +24 -1
- data/data/config/microservice.yaml +15 -1
- data/data/config/parameter_modifiers.yaml +4 -4
- data/data/config/plugins.yaml +511 -3
- data/data/config/settings.yaml +17 -0
- data/data/config/target.yaml +53 -0
- data/data/config/telemetry.yaml +58 -2
- data/data/config/widgets.yaml +30 -0
- data/lib/openc3/accessors/accessor.rb +14 -2
- data/lib/openc3/accessors/binary_accessor.rb +25 -5
- data/lib/openc3/api/CLAUDE.md +1 -0
- data/lib/openc3/api/api.rb +1 -0
- data/lib/openc3/api/cmd_api.rb +9 -1
- data/lib/openc3/api/interface_api.rb +7 -2
- data/lib/openc3/api/limits_api.rb +93 -41
- data/lib/openc3/api/router_api.rb +7 -2
- data/lib/openc3/api/settings_api.rb +4 -1
- data/lib/openc3/api/shared_resource_api.rb +107 -0
- data/lib/openc3/api/tlm_api.rb +10 -0
- data/lib/openc3/interfaces/http_client_interface.rb +84 -27
- data/lib/openc3/interfaces/protocols/preidentified_protocol.rb +6 -2
- data/lib/openc3/interfaces/tcpip_server_interface.rb +205 -125
- data/lib/openc3/io/json_api.rb +2 -10
- data/lib/openc3/io/json_api_object.rb +2 -10
- data/lib/openc3/logs/packet_log_writer.rb +8 -3
- data/lib/openc3/microservices/decom_common.rb +4 -1
- data/lib/openc3/microservices/decom_microservice.rb +52 -6
- data/lib/openc3/microservices/interface_decom_common.rb +13 -0
- data/lib/openc3/microservices/interface_microservice.rb +50 -11
- data/lib/openc3/microservices/limits_group_microservice.rb +513 -0
- data/lib/openc3/microservices/log_microservice.rb +22 -8
- data/lib/openc3/microservices/microservice.rb +8 -2
- data/lib/openc3/microservices/multi_microservice.rb +76 -22
- data/lib/openc3/microservices/queue_microservice.rb +29 -24
- data/lib/openc3/migrations/20260704000000_default_bridge.rb +1 -2
- data/lib/openc3/migrations/20261103000001_limits_group_backfill.rb +193 -0
- data/lib/openc3/models/bridge_model.rb +3 -3
- data/lib/openc3/models/cvt_model.rb +3 -1
- data/lib/openc3/models/host_interface_microservice_model.rb +4 -4
- data/lib/openc3/models/interface_model.rb +27 -7
- data/lib/openc3/models/microservice_group.rb +167 -0
- data/lib/openc3/models/microservice_model.rb +88 -2
- data/lib/openc3/models/panel_model.rb +109 -0
- data/lib/openc3/models/plugin_model.rb +1006 -26
- data/lib/openc3/models/plugin_store_model.rb +6 -1
- data/lib/openc3/models/protected_storage_model.rb +64 -0
- data/lib/openc3/models/queue_model.rb +19 -10
- data/lib/openc3/models/scope_model.rb +80 -3
- data/lib/openc3/models/setting_model.rb +2 -2
- data/lib/openc3/models/shared_resource_model.rb +381 -0
- data/lib/openc3/models/target_model.rb +324 -68
- data/lib/openc3/operators/microservice_operator.rb +76 -9
- data/lib/openc3/operators/operator.rb +29 -0
- data/lib/openc3/packets/commands.rb +16 -16
- data/lib/openc3/packets/limits.rb +2 -0
- data/lib/openc3/packets/packet.rb +75 -4
- data/lib/openc3/packets/packet_config.rb +152 -13
- data/lib/openc3/packets/packet_item.rb +35 -14
- data/lib/openc3/packets/packet_item_limits.rb +67 -6
- data/lib/openc3/packets/parsers/limits_parser.rb +69 -2
- data/lib/openc3/packets/parsers/packet_item_parser.rb +6 -0
- data/lib/openc3/packets/parsers/packet_parser.rb +45 -0
- data/lib/openc3/packets/parsers/state_parser.rb +1 -1
- data/lib/openc3/script/CLAUDE.md +1 -0
- data/lib/openc3/script/api_shared.rb +17 -9
- data/lib/openc3/script/calendar.rb +18 -6
- data/lib/openc3/script/commands.rb +11 -9
- data/lib/openc3/script/critical_cmd.rb +22 -2
- data/lib/openc3/script/metadata.rb +30 -4
- data/lib/openc3/script/plugins.rb +8 -0
- data/lib/openc3/script/script.rb +8 -24
- data/lib/openc3/script/web_socket_api.rb +23 -17
- data/lib/openc3/system/system.rb +9 -3
- data/lib/openc3/top_level.rb +17 -0
- data/lib/openc3/topics/command_topic.rb +7 -1
- data/lib/openc3/topics/decom_interface_topic.rb +9 -3
- data/lib/openc3/topics/discovery_topic.rb +84 -0
- data/lib/openc3/topics/limits_event_topic.rb +236 -17
- data/lib/openc3/topics/telemetry_decom_topic.rb +12 -3
- data/lib/openc3/topics/topic.rb +2 -1
- data/lib/openc3/utilities/authentication.rb +67 -16
- data/lib/openc3/utilities/cli_generator.rb +117 -25
- data/lib/openc3/utilities/client_ip_header_filter.rb +38 -0
- data/lib/openc3/utilities/config_overlay.rb +24 -1
- data/lib/openc3/utilities/cosmos_rails_formatter.rb +18 -10
- data/lib/openc3/utilities/hardware_discovery.rb +279 -0
- data/lib/openc3/utilities/limits_rollup.rb +81 -0
- data/lib/openc3/utilities/local_mode.rb +48 -5
- data/lib/openc3/utilities/questdb_client.rb +130 -22
- data/lib/openc3/utilities/reingest_job.rb +12 -3
- data/lib/openc3/utilities/running_script.rb +206 -49
- data/lib/openc3/utilities/script.rb +24 -12
- data/lib/openc3/utilities/script_env.rb +164 -0
- data/lib/openc3/utilities/script_message_signing.rb +133 -0
- data/lib/openc3/utilities/store_autoload.rb +32 -1
- data/lib/openc3/utilities/store_queued.rb +5 -1
- data/lib/openc3/version.rb +6 -6
- data/templates/command_validator/command_validator.py +9 -9
- data/templates/{tool_react/pnpm-workspace.yaml → panel/.prettierrc.cjs} +7 -5
- data/templates/panel/Rakefile +24 -0
- data/templates/panel/package.json +17 -0
- data/templates/{tool_angular → panel}/pnpm-workspace.yaml +5 -0
- data/templates/panel/src/Panel.js +52 -0
- data/templates/panel/src/Panel.vue +60 -0
- data/templates/panel/src/panelSdk.js +24 -0
- data/templates/panel/vite-Panel.config.js +43 -0
- data/templates/tool_vue/package.json +3 -3
- data/templates/widget/package.json +2 -2
- metadata +24 -56
- data/templates/tool_angular/.editorconfig +0 -16
- data/templates/tool_angular/.gitignore +0 -44
- data/templates/tool_angular/.vscode/extensions.json +0 -4
- data/templates/tool_angular/.vscode/launch.json +0 -20
- data/templates/tool_angular/.vscode/tasks.json +0 -42
- data/templates/tool_angular/angular.json +0 -111
- data/templates/tool_angular/extra-webpack.config.js +0 -8
- data/templates/tool_angular/package.json +0 -48
- data/templates/tool_angular/src/app/app-routing.module.ts +0 -15
- data/templates/tool_angular/src/app/app.component.html +0 -22
- data/templates/tool_angular/src/app/app.component.scss +0 -18
- data/templates/tool_angular/src/app/app.component.spec.ts +0 -29
- data/templates/tool_angular/src/app/app.component.ts +0 -52
- data/templates/tool_angular/src/app/app.module.ts +0 -30
- data/templates/tool_angular/src/app/custom-overlay-container.ts +0 -17
- data/templates/tool_angular/src/app/empty-route/empty-route.component.ts +0 -7
- data/templates/tool_angular/src/app/openc3-api.d.ts +0 -1
- data/templates/tool_angular/src/assets/.gitkeep +0 -0
- data/templates/tool_angular/src/environments/environment.prod.ts +0 -3
- data/templates/tool_angular/src/environments/environment.ts +0 -16
- data/templates/tool_angular/src/favicon.ico +0 -0
- data/templates/tool_angular/src/index.html +0 -13
- data/templates/tool_angular/src/main.single-spa.ts +0 -40
- data/templates/tool_angular/src/single-spa/asset-url.ts +0 -12
- data/templates/tool_angular/src/single-spa/single-spa-props.ts +0 -8
- data/templates/tool_angular/src/styles.scss +0 -1
- data/templates/tool_angular/tsconfig.app.json +0 -13
- data/templates/tool_angular/tsconfig.json +0 -33
- data/templates/tool_angular/tsconfig.spec.json +0 -14
- data/templates/tool_react/.eslintrc +0 -7
- data/templates/tool_react/.gitignore +0 -71
- data/templates/tool_react/.prettierignore +0 -8
- data/templates/tool_react/babel.config.json +0 -29
- data/templates/tool_react/jest.config.js +0 -12
- data/templates/tool_react/package.json +0 -51
- data/templates/tool_react/src/openc3-tool_name.js +0 -24
- data/templates/tool_react/src/root.component.js +0 -88
- data/templates/tool_react/src/root.component.test.js +0 -9
- data/templates/tool_react/webpack.config.js +0 -27
- data/templates/tool_svelte/.gitignore +0 -71
- data/templates/tool_svelte/.prettierignore +0 -8
- data/templates/tool_svelte/.prettierrc.js +0 -5
- data/templates/tool_svelte/babel.config.js +0 -12
- data/templates/tool_svelte/build/smui.css +0 -1
- data/templates/tool_svelte/jest.config.js +0 -9
- data/templates/tool_svelte/package.json +0 -49
- data/templates/tool_svelte/pnpm-workspace.yaml +0 -20
- data/templates/tool_svelte/rollup.config.js +0 -74
- data/templates/tool_svelte/src/App.svelte +0 -42
- data/templates/tool_svelte/src/App.test.js +0 -9
- data/templates/tool_svelte/src/theme/_smui-theme.scss +0 -25
- data/templates/tool_svelte/src/tool_name.js +0 -17
- data/templates/widget/LICENSE.md +0 -20
|
@@ -25,6 +25,8 @@ require 'openc3/top_level'
|
|
|
25
25
|
require 'openc3/models/model'
|
|
26
26
|
require 'openc3/models/cvt_model'
|
|
27
27
|
require 'openc3/models/microservice_model'
|
|
28
|
+
require 'openc3/models/microservice_group'
|
|
29
|
+
require 'openc3/models/shared_resource_model'
|
|
28
30
|
require 'openc3/topics/limits_event_topic'
|
|
29
31
|
require 'openc3/topics/config_topic'
|
|
30
32
|
require 'openc3/system'
|
|
@@ -32,6 +34,8 @@ require 'openc3/utilities/local_mode'
|
|
|
32
34
|
require 'openc3/utilities/bucket'
|
|
33
35
|
require 'openc3/utilities/target_file'
|
|
34
36
|
require 'openc3/utilities/zip'
|
|
37
|
+
require 'openc3/conversions'
|
|
38
|
+
require 'openc3/packets/packet_config'
|
|
35
39
|
require 'fileutils'
|
|
36
40
|
require 'ostruct'
|
|
37
41
|
require 'set'
|
|
@@ -43,7 +47,7 @@ module OpenC3
|
|
|
43
47
|
# in the target are stored under the <SCOPE>__openc3cmd__<TARGET NAME> key and the
|
|
44
48
|
# telemetry under the <SCOPE>__openc3tlm__<TARGET NAME> key. Any new limits sets
|
|
45
49
|
# are merged into the <SCOPE>__limits_sets key as fields. Any new limits groups are
|
|
46
|
-
# created under <SCOPE>__limits_groups with field
|
|
50
|
+
# created under <SCOPE>__limits_groups with field <TARGET NAME>__<GROUP NAME>. These Redis key/fields are
|
|
47
51
|
# all removed when the undeploy method is called.
|
|
48
52
|
class TargetModel < Model
|
|
49
53
|
PRIMARY_KEY = 'openc3_targets'
|
|
@@ -51,13 +55,24 @@ module OpenC3
|
|
|
51
55
|
ERB_EXTENSIONS = %w(.txt .rb .py .json .yaml .yml)
|
|
52
56
|
ITEM_MAP_CACHE_TIMEOUT = 10.0
|
|
53
57
|
PACKET_CACHE_TIMEOUT = 10.0
|
|
54
|
-
|
|
58
|
+
# QuestDB limits column names to 127 bytes of UTF-8 (cairo.max.file.name.length). Items get
|
|
59
|
+
# __C (converted) and __F (formatted) columns when they have states, conversions, formats or
|
|
60
|
+
# units. All names leave room for the 3 byte suffix so adding one never breaks an item.
|
|
61
|
+
MAX_COLUMN_HEADER_LENGTH = 127
|
|
62
|
+
COLUMN_SUFFIX_LENGTH = 3
|
|
63
|
+
MAX_ITEM_NAME_BYTES = MAX_COLUMN_HEADER_LENGTH - COLUMN_SUFFIX_LENGTH
|
|
55
64
|
@@item_map_cache = {}
|
|
56
65
|
@@packet_cache = {}
|
|
57
66
|
@@packet_cache_mutex = Mutex.new
|
|
58
67
|
@@sync_packet_count_data = {}
|
|
59
68
|
@@sync_packet_count_time = nil
|
|
60
69
|
@@sync_packet_count_delay_seconds = 1.0 # Sync packet counts every second
|
|
70
|
+
# Decom microservices sharing a process (a MULTI or MULTIGROUP) share these counts
|
|
71
|
+
@@sync_packet_count_mutex = Mutex.new
|
|
72
|
+
# Targets decom'd in this process, whose counts each sync reads back
|
|
73
|
+
@@sync_packet_count_target_names = Set.new
|
|
74
|
+
# Only one sync at a time so an older read back can't overwrite a newer one
|
|
75
|
+
@@sync_packet_count_in_progress = false
|
|
61
76
|
@@stale_packet_keys_warned = Set.new # Track stale keys already warned about
|
|
62
77
|
|
|
63
78
|
attr_accessor :folder_name
|
|
@@ -79,6 +94,7 @@ module OpenC3
|
|
|
79
94
|
attr_accessor :cmd_decom_retain_time
|
|
80
95
|
attr_accessor :tlm_decom_retain_time
|
|
81
96
|
attr_accessor :decom_flush_period
|
|
97
|
+
attr_accessor :decom_update_interval
|
|
82
98
|
attr_accessor :cleanup_poll_time
|
|
83
99
|
attr_accessor :needs_dependencies
|
|
84
100
|
attr_accessor :target_microservices
|
|
@@ -86,6 +102,9 @@ module OpenC3
|
|
|
86
102
|
attr_accessor :disable_erb
|
|
87
103
|
attr_accessor :shard
|
|
88
104
|
attr_accessor :db_shard
|
|
105
|
+
attr_accessor :microservice_group
|
|
106
|
+
attr_accessor :language
|
|
107
|
+
attr_accessor :shared_resource
|
|
89
108
|
|
|
90
109
|
# NOTE: The following three class methods are used by the ModelController
|
|
91
110
|
# and are reimplemented to enable various Model class methods to work
|
|
@@ -425,7 +444,9 @@ module OpenC3
|
|
|
425
444
|
found
|
|
426
445
|
end
|
|
427
446
|
|
|
428
|
-
# @return [Array<String>] All the item names for every packet in a target
|
|
447
|
+
# @return [Array<String>] All the item names for every packet in a target which
|
|
448
|
+
# LATEST can resolve. The generated LIMITS_GROUP packet is left out like in
|
|
449
|
+
# build_item_to_packet_map.
|
|
429
450
|
def self.all_item_names(target_name, type: :TLM, scope:)
|
|
430
451
|
items = store_for_target(target_name, scope: scope).zrange("#{scope}__openc3tlm__#{target_name}__allitems", 0, -1)
|
|
431
452
|
items = rebuild_target_allitems_list(target_name, type: type, scope: scope) if items.empty?
|
|
@@ -435,6 +456,8 @@ module OpenC3
|
|
|
435
456
|
def self.rebuild_target_allitems_list(target_name, type: :TLM, scope:)
|
|
436
457
|
packets = packets(target_name, type: type, scope: scope)
|
|
437
458
|
packets.each do |packet|
|
|
459
|
+
next if type.to_s.upcase == 'TLM' and packet['packet_name'] == PacketConfig::LIMITS_GROUP_PACKET
|
|
460
|
+
|
|
438
461
|
packet['items'].each do |item|
|
|
439
462
|
TargetModel.add_to_target_allitems_list(target_name, item['name'], scope: scope)
|
|
440
463
|
end
|
|
@@ -447,7 +470,8 @@ module OpenC3
|
|
|
447
470
|
store_for_target(target_name, scope: scope).zadd("#{scope}__openc3tlm__#{target_name}__allitems", score, item_name)
|
|
448
471
|
end
|
|
449
472
|
|
|
450
|
-
# @return [Hash{String => Array<Array<String, String, String>>}]
|
|
473
|
+
# @return [Hash{String => Array<Array<String, String, String>>}] Limits groups keyed
|
|
474
|
+
# by TARGET__GROUP (see LimitsEventTopic.limits_group_key)
|
|
451
475
|
def self.limits_groups(scope:)
|
|
452
476
|
groups = Store.hgetall("#{scope}__limits_groups")
|
|
453
477
|
if groups
|
|
@@ -480,7 +504,11 @@ module OpenC3
|
|
|
480
504
|
def self.build_item_to_packet_map(target_name, scope:)
|
|
481
505
|
item_map = {}
|
|
482
506
|
packets = packets(target_name, scope: scope)
|
|
507
|
+
# LATEST never resolves to the generated LIMITS_GROUP packet. Its items are
|
|
508
|
+
# limits groups which can share a name with an item in another packet.
|
|
483
509
|
packets.each do |packet|
|
|
510
|
+
next if packet['packet_name'] == PacketConfig::LIMITS_GROUP_PACKET
|
|
511
|
+
|
|
484
512
|
items = packet['items']
|
|
485
513
|
items.each do |item|
|
|
486
514
|
item_name = item['name']
|
|
@@ -498,6 +526,7 @@ module OpenC3
|
|
|
498
526
|
usage = "#{keyword} <TARGET FOLDER NAME> <TARGET NAME>"
|
|
499
527
|
parser.verify_num_parameters(2, 2, usage)
|
|
500
528
|
parser.verify_parameter_naming(2) # Target name is the 2nd parameter
|
|
529
|
+
|
|
501
530
|
return self.new(name: parameters[1].to_s.upcase, folder_name: parameters[0].to_s.upcase, plugin: plugin, needs_dependencies: needs_dependencies, scope: scope)
|
|
502
531
|
else
|
|
503
532
|
raise ConfigParser::Error.new(parser, "Unknown keyword and parameters for Target: #{keyword} #{parameters.join(" ")}")
|
|
@@ -528,12 +557,16 @@ module OpenC3
|
|
|
528
557
|
cmd_decom_retain_time: nil,
|
|
529
558
|
tlm_decom_retain_time: nil,
|
|
530
559
|
decom_flush_period: 5.0,
|
|
560
|
+
decom_update_interval: nil,
|
|
531
561
|
cleanup_poll_time: 3600,
|
|
532
562
|
needs_dependencies: false,
|
|
533
563
|
target_microservices: {},
|
|
534
564
|
disable_erb: nil,
|
|
535
565
|
shard: 0,
|
|
536
566
|
db_shard: 0,
|
|
567
|
+
microservice_group: nil,
|
|
568
|
+
language: nil,
|
|
569
|
+
shared_resource: nil,
|
|
537
570
|
scope:
|
|
538
571
|
)
|
|
539
572
|
super("#{scope}__#{PRIMARY_KEY}", name: name, plugin: plugin, updated_at: updated_at, scope: scope)
|
|
@@ -557,12 +590,16 @@ module OpenC3
|
|
|
557
590
|
@cmd_decom_retain_time = cmd_decom_retain_time
|
|
558
591
|
@tlm_decom_retain_time = tlm_decom_retain_time
|
|
559
592
|
@decom_flush_period = decom_flush_period
|
|
593
|
+
@decom_update_interval = decom_update_interval
|
|
560
594
|
@cleanup_poll_time = cleanup_poll_time
|
|
561
595
|
@needs_dependencies = needs_dependencies
|
|
562
596
|
@target_microservices = target_microservices
|
|
563
597
|
@disable_erb = disable_erb
|
|
564
598
|
@shard = shard.to_i # to_i to handle nil
|
|
565
599
|
@db_shard = db_shard.to_i # to_i to handle nil
|
|
600
|
+
@microservice_group = microservice_group
|
|
601
|
+
@language = language
|
|
602
|
+
@shared_resource = shared_resource
|
|
566
603
|
@bucket = Bucket.getClient()
|
|
567
604
|
@children = []
|
|
568
605
|
end
|
|
@@ -591,15 +628,36 @@ module OpenC3
|
|
|
591
628
|
'cmd_decom_retain_time' => @cmd_decom_retain_time,
|
|
592
629
|
'tlm_decom_retain_time' => @tlm_decom_retain_time,
|
|
593
630
|
'decom_flush_period' => @decom_flush_period,
|
|
631
|
+
'decom_update_interval' => @decom_update_interval,
|
|
594
632
|
'cleanup_poll_time' => @cleanup_poll_time,
|
|
595
633
|
'needs_dependencies' => @needs_dependencies,
|
|
596
634
|
'target_microservices' => @target_microservices.as_json(),
|
|
597
635
|
'disable_erb' => @disable_erb,
|
|
598
636
|
'shard' => @shard,
|
|
599
637
|
'db_shard' => @db_shard,
|
|
638
|
+
'microservice_group' => @microservice_group,
|
|
639
|
+
'language' => @language,
|
|
640
|
+
'shared_resource' => @shared_resource,
|
|
600
641
|
}
|
|
601
642
|
end
|
|
602
643
|
|
|
644
|
+
# Join the shared resource (if any) when first created. Targets are members
|
|
645
|
+
# without a process: their microservices keep running in every scope but
|
|
646
|
+
# commands are only accepted in the scope where the resource is active.
|
|
647
|
+
def create(update: false, force: false, queued: false)
|
|
648
|
+
added = false
|
|
649
|
+
if @shared_resource and not update
|
|
650
|
+
existed = SharedResourceModel.member?(@shared_resource, scope: @scope, type: 'TARGET', member_name: @name)
|
|
651
|
+
SharedResourceModel.add_member(@shared_resource, scope: @scope, type: 'TARGET', member_name: @name)
|
|
652
|
+
added = !existed
|
|
653
|
+
end
|
|
654
|
+
super(update: update, force: force, queued: queued)
|
|
655
|
+
rescue
|
|
656
|
+
# Don't leave a member behind for a target that wasn't created
|
|
657
|
+
SharedResourceModel.remove_member(@shared_resource, scope: @scope, type: 'TARGET', member_name: @name) if added
|
|
658
|
+
raise
|
|
659
|
+
end
|
|
660
|
+
|
|
603
661
|
# Handles Target specific configuration keywords
|
|
604
662
|
def handle_config(parser, keyword, parameters)
|
|
605
663
|
case keyword
|
|
@@ -648,6 +706,14 @@ module OpenC3
|
|
|
648
706
|
when 'DECOM_FLUSH_PERIOD'
|
|
649
707
|
parser.verify_num_parameters(1, 1, "#{keyword} <Flush period in seconds>")
|
|
650
708
|
@decom_flush_period = Float(parameters[0])
|
|
709
|
+
when 'DECOM_UPDATE_INTERVAL'
|
|
710
|
+
parser.verify_num_parameters(1, 1, "#{keyword} <Update interval in seconds - 0 = No queuing>")
|
|
711
|
+
begin
|
|
712
|
+
@decom_update_interval = Float(parameters[0])
|
|
713
|
+
rescue ArgumentError, TypeError
|
|
714
|
+
raise ConfigParser::Error.new(parser, "#{keyword} must be a number of seconds")
|
|
715
|
+
end
|
|
716
|
+
raise ConfigParser::Error.new(parser, "#{keyword} must be a finite number of seconds") unless @decom_update_interval.finite?
|
|
651
717
|
when 'REDUCED_MINUTE_LOG_RETAIN_TIME', 'REDUCED_HOUR_LOG_RETAIN_TIME', 'REDUCED_DAY_LOG_RETAIN_TIME', 'REDUCED_LOG_RETAIN_TIME'
|
|
652
718
|
# DEPRECATED
|
|
653
719
|
when 'REDUCER_DISABLE', 'REDUCER_DISABLED', 'REDUCER_MAX_CPU_UTILIZATION', 'REDUCED_MAX_CPU_UTILIZATION'
|
|
@@ -695,6 +761,12 @@ module OpenC3
|
|
|
695
761
|
parser.verify_num_parameters(1, 1, "#{keyword} <Shard Number Starting from 0>")
|
|
696
762
|
@db_shard = Integer(parameters[0])
|
|
697
763
|
|
|
764
|
+
when 'MICROSERVICE_GROUP'
|
|
765
|
+
usage = "#{keyword} <Group Name>"
|
|
766
|
+
parser.verify_num_parameters(1, 1, usage)
|
|
767
|
+
parser.verify_parameter_naming(1, usage)
|
|
768
|
+
@microservice_group = parameters[0].to_s.upcase
|
|
769
|
+
|
|
698
770
|
when 'STORED_LIMITS_MODE'
|
|
699
771
|
parser.verify_num_parameters(1, 1, "#{keyword} <PROCESS, LOG, or DISABLE>")
|
|
700
772
|
mode = parameters[0].to_s.upcase
|
|
@@ -703,6 +775,14 @@ module OpenC3
|
|
|
703
775
|
end
|
|
704
776
|
@stored_limits_mode = mode
|
|
705
777
|
|
|
778
|
+
when 'SHARED_RESOURCE'
|
|
779
|
+
parser.verify_num_parameters(1, 1, "#{keyword} <Shared Resource Name>")
|
|
780
|
+
begin
|
|
781
|
+
@shared_resource = SharedResourceModel.validate_name(parameters[0])
|
|
782
|
+
rescue => e
|
|
783
|
+
raise parser.error(e.message)
|
|
784
|
+
end
|
|
785
|
+
|
|
706
786
|
else
|
|
707
787
|
raise ConfigParser::Error.new(parser, "Unknown keyword and parameters for Target: #{keyword} #{parameters.join(" ")}")
|
|
708
788
|
end
|
|
@@ -748,9 +828,9 @@ module OpenC3
|
|
|
748
828
|
end
|
|
749
829
|
end
|
|
750
830
|
rescue => e
|
|
751
|
-
# ERB error parsing a screen is just a logger error because life can go on
|
|
831
|
+
# ERB error parsing a screen or dashboard is just a logger error because life can go on
|
|
752
832
|
# With cmd/tlm or scripts this is a serious error and we raise
|
|
753
|
-
if (filename.include?('/screens/'))
|
|
833
|
+
if (filename.include?('/screens/') or filename.include?('/dashboards/'))
|
|
754
834
|
Logger.error("ERB error parsing #{key} due to #{e.message}")
|
|
755
835
|
else
|
|
756
836
|
raise "ERB error parsing #{key} due to #{e.message}"
|
|
@@ -778,6 +858,10 @@ module OpenC3
|
|
|
778
858
|
# Build a System for just this target
|
|
779
859
|
system = System.new([@name], temp_dir)
|
|
780
860
|
check_column_header_lengths(system)
|
|
861
|
+
check_limits_groups(system)
|
|
862
|
+
@language = system.targets[@name].language
|
|
863
|
+
MicroserviceGroup.validate_member(self) if @microservice_group
|
|
864
|
+
check_command_default_sizes(system)
|
|
781
865
|
if variables["xtce_output"]
|
|
782
866
|
puts "Converting target #{@name} to .xtce files in #{variables["xtce_output"]}/#{@name}"
|
|
783
867
|
if variables['time_association_name'].to_s.empty?
|
|
@@ -790,7 +874,17 @@ module OpenC3
|
|
|
790
874
|
unless validate_only
|
|
791
875
|
build_target_archive(temp_dir, target_folder)
|
|
792
876
|
system = update_store(system)
|
|
877
|
+
if @microservice_group
|
|
878
|
+
# Check again and save (with language) under the group lock so a
|
|
879
|
+
# target of another plugin installed at the same time is checked
|
|
880
|
+
# against this one, or this one against it
|
|
881
|
+
MicroserviceGroup.with_lock(@microservice_group, scope: @scope) do
|
|
882
|
+
MicroserviceGroup.validate_member(self)
|
|
883
|
+
update(force: true)
|
|
884
|
+
end
|
|
885
|
+
end
|
|
793
886
|
deploy_microservices(gem_path, variables, system)
|
|
887
|
+
MicroserviceGroup.update(@microservice_group, scope: @scope) if @microservice_group
|
|
794
888
|
ConfigTopic.write({ kind: 'created', type: 'target', name: @name, plugin: @plugin }, scope: @scope)
|
|
795
889
|
end
|
|
796
890
|
ensure
|
|
@@ -858,19 +952,102 @@ module OpenC3
|
|
|
858
952
|
packets_by_target.each do |target_name, packets|
|
|
859
953
|
packets.each do |packet_name, packet|
|
|
860
954
|
packet.sorted_items.each do |item|
|
|
861
|
-
if item.name.
|
|
862
|
-
too_long << "#{target_name} #{packet_name} #{item.name} (#{item.name.
|
|
955
|
+
if item.name.bytesize > MAX_ITEM_NAME_BYTES
|
|
956
|
+
too_long << "#{target_name} #{packet_name} #{item.name} (#{item.name.bytesize})"
|
|
863
957
|
end
|
|
864
958
|
end
|
|
865
959
|
end
|
|
866
960
|
end
|
|
867
961
|
end
|
|
868
962
|
unless too_long.empty?
|
|
869
|
-
raise "Item / parameter names must be #{
|
|
963
|
+
raise "Item / parameter names must be #{MAX_ITEM_NAME_BYTES} bytes (UTF-8) or less (QuestDB column name limit of #{MAX_COLUMN_HEADER_LENGTH} bytes minus the #{COLUMN_SUFFIX_LENGTH} byte __C or __F value type suffix). The following are too long:\n #{too_long.join("\n ")}"
|
|
964
|
+
end
|
|
965
|
+
end
|
|
966
|
+
|
|
967
|
+
# Nested limits groups can't form a loop. Since a loop is likely a typo the
|
|
968
|
+
# member which closes it is skipped with a warning, like a member whose name
|
|
969
|
+
# PacketConfig rejects. Group names are already checked by the parser
|
|
970
|
+
# (PacketConfig.limits_group_name_error) which also keeps each group in its own column.
|
|
971
|
+
def check_limits_groups(system)
|
|
972
|
+
new_groups = system.limits.groups[@name] || {}
|
|
973
|
+
return if new_groups.empty?
|
|
974
|
+
|
|
975
|
+
# The groups of other targets plus this target's new groups which replace its old ones
|
|
976
|
+
groups = {}
|
|
977
|
+
Store.hgetall("#{@scope}__limits_groups").each do |key, json|
|
|
978
|
+
next if LimitsEventTopic.split_limits_group_key(key)[0] == @name
|
|
979
|
+
|
|
980
|
+
groups[key] = JSON.parse(json, allow_nan: true, create_additions: true)
|
|
981
|
+
end
|
|
982
|
+
new_groups.each { |group, items| groups[LimitsEventTopic.limits_group_key(@name, group)] = items }
|
|
983
|
+
children = {}
|
|
984
|
+
groups.each do |key, items|
|
|
985
|
+
children[key] = items.select { |_target_name, packet_name, _item| packet_name == PacketConfig::LIMITS_GROUP_PACKET }
|
|
986
|
+
.map { |target_name, _packet_name, item_name| LimitsEventTopic.limits_group_key(target_name, item_name) }
|
|
987
|
+
end
|
|
988
|
+
|
|
989
|
+
# Each pass removes one member so this ends
|
|
990
|
+
while (loop = find_limits_group_loop(children, new_groups.keys))
|
|
991
|
+
names = loop.map { |key| key.sub('__', ' ') }.join(' -> ')
|
|
992
|
+
# Skip the last member in the loop which belongs to this target. Install never
|
|
993
|
+
# stores a loop between other targets' groups but ignore one if it's found.
|
|
994
|
+
from, to = loop.each_cons(2).to_a.reverse.find { |key, _child| LimitsEventTopic.split_limits_group_key(key)[0] == @name }
|
|
995
|
+
unless from
|
|
996
|
+
from, to = loop.last(2)
|
|
997
|
+
children[from].delete(to)
|
|
998
|
+
Logger.warn("LIMITS_GROUP #{from.sub('__', ' ')} contains itself: #{names}. Nested limits groups can't form a loop.")
|
|
999
|
+
next
|
|
1000
|
+
end
|
|
1001
|
+
children[from].delete(to)
|
|
1002
|
+
to_target, to_group = LimitsEventTopic.split_limits_group_key(to)
|
|
1003
|
+
new_groups[LimitsEventTopic.split_limits_group_key(from)[1]].delete([to_target, PacketConfig::LIMITS_GROUP_PACKET, to_group])
|
|
1004
|
+
Logger.warn("LIMITS_GROUP #{from.sub('__', ' ')} contains itself: #{names}. Skipping its member #{to_target} #{PacketConfig::LIMITS_GROUP_PACKET} #{to_group} since nested limits groups can't form a loop.")
|
|
1005
|
+
end
|
|
1006
|
+
end
|
|
1007
|
+
|
|
1008
|
+
# Depth first search keeping the current path so a loop can be reported
|
|
1009
|
+
#
|
|
1010
|
+
# @return [Array<String>, nil] The group keys of a loop with the first repeated
|
|
1011
|
+
# at the end, or nil if the groups don't loop
|
|
1012
|
+
def find_limits_group_loop(children, group_names)
|
|
1013
|
+
done = Set.new
|
|
1014
|
+
visit = lambda do |key, path|
|
|
1015
|
+
index = path.index(key)
|
|
1016
|
+
return path[index..] + [key] if index
|
|
1017
|
+
return nil if done.include?(key)
|
|
1018
|
+
|
|
1019
|
+
(children[key] || []).each do |child|
|
|
1020
|
+
loop = visit.call(child, path + [key])
|
|
1021
|
+
return loop if loop
|
|
1022
|
+
end
|
|
1023
|
+
done << key
|
|
1024
|
+
nil
|
|
1025
|
+
end
|
|
1026
|
+
group_names.each do |group|
|
|
1027
|
+
loop = visit.call(LimitsEventTopic.limits_group_key(@name, group), [])
|
|
1028
|
+
return loop if loop
|
|
1029
|
+
end
|
|
1030
|
+
nil
|
|
1031
|
+
end
|
|
1032
|
+
|
|
1033
|
+
# Check that command STRING and BLOCK defaults fit. This is only done at
|
|
1034
|
+
# install so targets installed before the check was added still load.
|
|
1035
|
+
def check_command_default_sizes(system)
|
|
1036
|
+
system.packet_config.commands.each do |_target_name, packets|
|
|
1037
|
+
packets.each do |_packet_name, packet|
|
|
1038
|
+
PacketParser.check_item_default_sizes(packet)
|
|
1039
|
+
end
|
|
870
1040
|
end
|
|
871
1041
|
end
|
|
872
1042
|
|
|
873
1043
|
def undeploy
|
|
1044
|
+
if @shared_resource
|
|
1045
|
+
begin
|
|
1046
|
+
SharedResourceModel.remove_member(@shared_resource, scope: @scope, type: 'TARGET', member_name: @name)
|
|
1047
|
+
rescue => error
|
|
1048
|
+
Logger.error("Error removing target #{@name} from shared resource #{@shared_resource} in scope #{@scope} due to #{error}")
|
|
1049
|
+
end
|
|
1050
|
+
end
|
|
874
1051
|
prefix = "#{@scope}/targets/#{@name}/"
|
|
875
1052
|
objects = @bucket.list_objects(bucket: ENV['OPENC3_CONFIG_BUCKET'], prefix: prefix)
|
|
876
1053
|
keys = objects.map(&:key)
|
|
@@ -882,7 +1059,7 @@ module OpenC3
|
|
|
882
1059
|
end
|
|
883
1060
|
|
|
884
1061
|
self.class.get_model(name: @name, scope: @scope).limits_groups.each do |group|
|
|
885
|
-
Store.hdel("#{@scope}__limits_groups", group)
|
|
1062
|
+
Store.hdel("#{@scope}__limits_groups", LimitsEventTopic.limits_group_key(@name, group))
|
|
886
1063
|
end
|
|
887
1064
|
self.class.packets(@name, type: :CMD, scope: @scope).each do |packet|
|
|
888
1065
|
Topic.del("#{@scope}__COMMAND__{#{@name}}__#{packet['packet_name']}", db_shard: @db_shard)
|
|
@@ -903,7 +1080,7 @@ module OpenC3
|
|
|
903
1080
|
db_shard_store.del("#{@scope}__COMMANDCNTS__{#{@name}}")
|
|
904
1081
|
|
|
905
1082
|
# Note: these match the names of the services in deploy_microservices
|
|
906
|
-
%w(MULTI DECOM COMMANDLOG PACKETLOG CLEANUP).each do |type|
|
|
1083
|
+
%w(MULTI DECOM COMMANDLOG PACKETLOG CLEANUP TSDB).each do |type|
|
|
907
1084
|
target_microservices = @target_microservices[type]
|
|
908
1085
|
if target_microservices
|
|
909
1086
|
max_instances = target_microservices.length + 1
|
|
@@ -917,6 +1094,8 @@ module OpenC3
|
|
|
917
1094
|
model.destroy if model
|
|
918
1095
|
end
|
|
919
1096
|
end
|
|
1097
|
+
# Remove the group's parent microservices if this was their last child
|
|
1098
|
+
MicroserviceGroup.update(@microservice_group, scope: @scope) if @microservice_group
|
|
920
1099
|
# Delete item_map
|
|
921
1100
|
item_map_key = "#{@scope}__#{@name}__item_to_packet_map"
|
|
922
1101
|
db_shard_store.del(item_map_key)
|
|
@@ -1009,7 +1188,7 @@ module OpenC3
|
|
|
1009
1188
|
@ignored_parameters = target.ignored_parameters
|
|
1010
1189
|
@ignored_items = target.ignored_items
|
|
1011
1190
|
@cmd_tlm_files = target.cmd_tlm_files
|
|
1012
|
-
@limits_groups = system.limits.groups.keys
|
|
1191
|
+
@limits_groups = (system.limits.groups[@name] || {}).keys
|
|
1013
1192
|
update()
|
|
1014
1193
|
end
|
|
1015
1194
|
|
|
@@ -1030,9 +1209,12 @@ module OpenC3
|
|
|
1030
1209
|
raise e
|
|
1031
1210
|
end
|
|
1032
1211
|
json_hash = {}
|
|
1212
|
+
# LATEST never resolves to the generated LIMITS_GROUP packet so its items
|
|
1213
|
+
# (the limits group names) don't belong in the LATEST item list
|
|
1214
|
+
add_to_allitems = (packet_name != PacketConfig::LIMITS_GROUP_PACKET)
|
|
1033
1215
|
packet.sorted_items.each do |item|
|
|
1034
1216
|
json_hash[item.name] = nil
|
|
1035
|
-
TargetModel.add_to_target_allitems_list(target_name, item.name, scope: @scope)
|
|
1217
|
+
TargetModel.add_to_target_allitems_list(target_name, item.name, scope: @scope) if add_to_allitems
|
|
1036
1218
|
end
|
|
1037
1219
|
CvtModel.set(json_hash, target_name: packet.target_name, packet_name: packet.packet_name, scope: @scope)
|
|
1038
1220
|
end
|
|
@@ -1080,9 +1262,9 @@ module OpenC3
|
|
|
1080
1262
|
end
|
|
1081
1263
|
|
|
1082
1264
|
def update_store_limits_groups(system)
|
|
1083
|
-
system.limits.groups.each do |group, items|
|
|
1265
|
+
(system.limits.groups[@name] || {}).each do |group, items|
|
|
1084
1266
|
begin
|
|
1085
|
-
Store.hset("#{@scope}__limits_groups", group, JSON.generate(items, allow_nan: true))
|
|
1267
|
+
Store.hset("#{@scope}__limits_groups", LimitsEventTopic.limits_group_key(@name, group), JSON.generate(items, allow_nan: true))
|
|
1086
1268
|
rescue JSON::GeneratorError => e
|
|
1087
1269
|
Logger.error("Invalid text present in #{group} limits group")
|
|
1088
1270
|
raise e
|
|
@@ -1255,22 +1437,27 @@ module OpenC3
|
|
|
1255
1437
|
filename = 'decom_microservice.rb'
|
|
1256
1438
|
work_dir = '/openc3/lib/openc3/microservices'
|
|
1257
1439
|
language_cmd = target.language
|
|
1440
|
+
microservice_parent = parent
|
|
1258
1441
|
if target.language == 'python'
|
|
1259
1442
|
filename = 'decom_microservice.py'
|
|
1260
1443
|
work_dir.sub!('openc3/lib', 'openc3/python')
|
|
1261
|
-
|
|
1444
|
+
# Python can't run in a Ruby MULTI so runs standalone or in the group's Python MULTI
|
|
1445
|
+
microservice_parent = @python_parent
|
|
1262
1446
|
# Use venv Python to ensure editable packages are found
|
|
1263
1447
|
language_cmd = ENV['OPENC3_PYTHON_BIN'] || '/openc3/python/.venv/bin/python'
|
|
1264
1448
|
end
|
|
1449
|
+
options = []
|
|
1450
|
+
options << ["UPDATE_INTERVAL", @decom_update_interval] if @decom_update_interval
|
|
1265
1451
|
microservice = MicroserviceModel.new(
|
|
1266
1452
|
name: microservice_name,
|
|
1267
1453
|
folder_name: @folder_name,
|
|
1268
1454
|
cmd: [language_cmd, filename, microservice_name],
|
|
1269
1455
|
work_dir: work_dir,
|
|
1456
|
+
options: options,
|
|
1270
1457
|
topics: topics,
|
|
1271
1458
|
target_names: [@name],
|
|
1272
1459
|
plugin: @plugin,
|
|
1273
|
-
parent:
|
|
1460
|
+
parent: microservice_parent,
|
|
1274
1461
|
needs_dependencies: @needs_dependencies,
|
|
1275
1462
|
shard: @shard,
|
|
1276
1463
|
db_shard: @db_shard,
|
|
@@ -1278,7 +1465,7 @@ module OpenC3
|
|
|
1278
1465
|
)
|
|
1279
1466
|
microservice.create
|
|
1280
1467
|
microservice.deploy(gem_path, variables)
|
|
1281
|
-
@children << microservice_name if
|
|
1468
|
+
@children << microservice_name if microservice_parent
|
|
1282
1469
|
Logger.info "Configured microservice #{microservice_name}"
|
|
1283
1470
|
end
|
|
1284
1471
|
|
|
@@ -1296,7 +1483,7 @@ module OpenC3
|
|
|
1296
1483
|
options: options,
|
|
1297
1484
|
topics: topics,
|
|
1298
1485
|
plugin: @plugin,
|
|
1299
|
-
parent:
|
|
1486
|
+
parent: @python_parent, # Standalone unless in a microservice group
|
|
1300
1487
|
needs_dependencies: @needs_dependencies,
|
|
1301
1488
|
shard: @shard,
|
|
1302
1489
|
db_shard: @db_shard,
|
|
@@ -1412,10 +1599,18 @@ module OpenC3
|
|
|
1412
1599
|
end
|
|
1413
1600
|
|
|
1414
1601
|
@parent = nil
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1602
|
+
@python_parent = nil
|
|
1603
|
+
if @microservice_group
|
|
1604
|
+
# Run in the group's shared MULTI microservices instead of this target's own
|
|
1605
|
+
# (TARGET_MICROSERVICE isn't allowed in a group, see MicroserviceGroup.validate_member)
|
|
1606
|
+
@parent = MicroserviceGroup.microservice_name(MicroserviceGroup::RUBY_TYPE, @microservice_group, scope: @scope)
|
|
1607
|
+
@python_parent = MicroserviceGroup.microservice_name(MicroserviceGroup::PYTHON_TYPE, @microservice_group, scope: @scope)
|
|
1608
|
+
else
|
|
1609
|
+
%w(DECOM COMMANDLOG PACKETLOG CLEANUP).each do |type|
|
|
1610
|
+
unless @target_microservices[type]
|
|
1611
|
+
@parent = "#{@scope}__MULTI__#{@name}"
|
|
1612
|
+
break
|
|
1613
|
+
end
|
|
1419
1614
|
end
|
|
1420
1615
|
end
|
|
1421
1616
|
|
|
@@ -1461,8 +1656,9 @@ module OpenC3
|
|
|
1461
1656
|
end
|
|
1462
1657
|
end
|
|
1463
1658
|
|
|
1464
|
-
if @parent
|
|
1659
|
+
if @parent and !@microservice_group
|
|
1465
1660
|
# Multi Microservice to parent other target microservices
|
|
1661
|
+
# (a microservice group's are created by MicroserviceGroup.update)
|
|
1466
1662
|
deploy_multi_microservice(gem_path, variables)
|
|
1467
1663
|
end
|
|
1468
1664
|
end
|
|
@@ -1535,18 +1731,16 @@ module OpenC3
|
|
|
1535
1731
|
|
|
1536
1732
|
# Get all the packet counts with the global counters
|
|
1537
1733
|
tlm_target_names.each do |target_name|
|
|
1734
|
+
unknown_packet_names = []
|
|
1538
1735
|
get_all_telemetry_counts(target_name, scope: scope).each do |packet_name, count|
|
|
1539
1736
|
begin
|
|
1540
1737
|
update_packet = System.telemetry.packet(target_name, packet_name)
|
|
1541
1738
|
update_packet.received_count = count.to_i
|
|
1542
1739
|
rescue RuntimeError
|
|
1543
|
-
|
|
1544
|
-
unless @@stale_packet_keys_warned.include?(key)
|
|
1545
|
-
@@stale_packet_keys_warned.add(key)
|
|
1546
|
-
Logger.warn("Stale tlmcnt Redis key detected for unknown packet #{key} - ignoring")
|
|
1547
|
-
end
|
|
1740
|
+
unknown_packet_names << packet_name
|
|
1548
1741
|
end
|
|
1549
1742
|
end
|
|
1743
|
+
prune_stale_telemetry_counts(target_name, unknown_packet_names, scope: scope) unless unknown_packet_names.empty?
|
|
1550
1744
|
end
|
|
1551
1745
|
get_all_telemetry_counts('UNKNOWN', scope: scope).each do |packet_name, count|
|
|
1552
1746
|
begin
|
|
@@ -1562,6 +1756,32 @@ module OpenC3
|
|
|
1562
1756
|
end
|
|
1563
1757
|
end
|
|
1564
1758
|
|
|
1759
|
+
# A microservice still running the old packet definitions during a plugin
|
|
1760
|
+
# upgrade can write counts for removed packets after the upgrade cleared
|
|
1761
|
+
# the counts. Delete the counts for packets the target no longer defines.
|
|
1762
|
+
# Keep the count of a packet that is still defined but this System didn't
|
|
1763
|
+
# load (e.g. a dynamic packet) and warn about it instead.
|
|
1764
|
+
def self.prune_stale_telemetry_counts(target_name, unknown_packet_names, scope:)
|
|
1765
|
+
begin
|
|
1766
|
+
defined_packet_names = packet_names(target_name, type: :TLM, scope: scope)
|
|
1767
|
+
rescue RuntimeError
|
|
1768
|
+
# The target isn't installed so there's nothing to compare against
|
|
1769
|
+
defined_packet_names = unknown_packet_names
|
|
1770
|
+
end
|
|
1771
|
+
stale_packet_names = unknown_packet_names - defined_packet_names
|
|
1772
|
+
unless stale_packet_names.empty?
|
|
1773
|
+
store_for_target(target_name, scope: scope).hdel("#{scope}__TELEMETRYCNTS__{#{target_name}}", *stale_packet_names)
|
|
1774
|
+
Logger.info("Removed stale tlmcnt Redis keys for #{target_name} packets that are no longer defined: #{stale_packet_names.join(', ')}")
|
|
1775
|
+
end
|
|
1776
|
+
(unknown_packet_names & defined_packet_names).each do |packet_name|
|
|
1777
|
+
key = "#{target_name} #{packet_name}"
|
|
1778
|
+
unless @@stale_packet_keys_warned.include?(key)
|
|
1779
|
+
@@stale_packet_keys_warned.add(key)
|
|
1780
|
+
Logger.warn("Stale tlmcnt Redis key detected for unknown packet #{key} - ignoring")
|
|
1781
|
+
end
|
|
1782
|
+
end
|
|
1783
|
+
end
|
|
1784
|
+
|
|
1565
1785
|
def self.sync_tlm_packet_counts(packet, tlm_target_names, scope:)
|
|
1566
1786
|
if @@sync_packet_count_delay_seconds <= 0
|
|
1567
1787
|
# Perfect but slow method
|
|
@@ -1571,48 +1791,57 @@ module OpenC3
|
|
|
1571
1791
|
# Only sync every period (default 1 second) to avoid hammering Redis
|
|
1572
1792
|
# This is a trade off between speed and accuracy
|
|
1573
1793
|
# The packet count is eventually consistent
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
@@
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
#
|
|
1588
|
-
@@
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1794
|
+
sync_data = nil
|
|
1795
|
+
sync_target_names = nil
|
|
1796
|
+
@@sync_packet_count_mutex.synchronize do
|
|
1797
|
+
@@sync_packet_count_target_names.merge(tlm_target_names)
|
|
1798
|
+
@@sync_packet_count_data[packet.target_name] ||= {}
|
|
1799
|
+
@@sync_packet_count_data[packet.target_name][packet.packet_name] ||= 0
|
|
1800
|
+
@@sync_packet_count_data[packet.target_name][packet.packet_name] += 1
|
|
1801
|
+
|
|
1802
|
+
# Ensures counters change between syncs
|
|
1803
|
+
update_packet = System.telemetry.packet(packet.target_name, packet.packet_name)
|
|
1804
|
+
update_packet.received_count += 1
|
|
1805
|
+
packet.received_count = update_packet.received_count
|
|
1806
|
+
|
|
1807
|
+
# Check if we need to sync the packet counts
|
|
1808
|
+
if !@@sync_packet_count_in_progress and (@@sync_packet_count_time.nil? or (Time.now - @@sync_packet_count_time) > @@sync_packet_count_delay_seconds)
|
|
1809
|
+
@@sync_packet_count_in_progress = true
|
|
1810
|
+
@@sync_packet_count_time = Time.now
|
|
1811
|
+
sync_data = @@sync_packet_count_data
|
|
1812
|
+
@@sync_packet_count_data = {}
|
|
1813
|
+
# Every target in the process, since the other decoms skip the sync
|
|
1814
|
+
# while this one runs it (and the timer it reset)
|
|
1815
|
+
sync_target_names = @@sync_packet_count_target_names.to_a + ['UNKNOWN']
|
|
1592
1816
|
end
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1817
|
+
end
|
|
1818
|
+
|
|
1819
|
+
sync_and_read_back_packet_counts(sync_data, sync_target_names.uniq, scope: scope) if sync_data
|
|
1820
|
+
end
|
|
1821
|
+
end
|
|
1822
|
+
|
|
1823
|
+
# Write a batch to Redis and set every packet's received_count from the
|
|
1824
|
+
# global counters. Only one thread runs this at a time (see
|
|
1825
|
+
# @@sync_packet_count_in_progress).
|
|
1826
|
+
def self.sync_and_read_back_packet_counts(sync_data, target_names, scope:)
|
|
1827
|
+
write_packet_counts(sync_data, scope: scope)
|
|
1828
|
+
|
|
1829
|
+
# Get all the packet counts with the global counters
|
|
1830
|
+
counts = {}
|
|
1831
|
+
target_names.each do |target_name|
|
|
1832
|
+
counts[target_name] = get_all_telemetry_counts(target_name, scope: scope)
|
|
1833
|
+
end
|
|
1834
|
+
@@sync_packet_count_mutex.synchronize do
|
|
1835
|
+
counts.each do |target_name, packet_counts|
|
|
1836
|
+
packet_counts.each do |packet_name, count|
|
|
1611
1837
|
begin
|
|
1612
|
-
update_packet = System.telemetry.packet(
|
|
1613
|
-
|
|
1838
|
+
update_packet = System.telemetry.packet(target_name, packet_name)
|
|
1839
|
+
# Add the increments threads in this process queued since the flush
|
|
1840
|
+
# (e.g. UNKNOWN is shared) so the count doesn't go backwards
|
|
1841
|
+
pending = @@sync_packet_count_data.dig(target_name, packet_name) || 0
|
|
1842
|
+
update_packet.received_count = count.to_i + pending
|
|
1614
1843
|
rescue RuntimeError
|
|
1615
|
-
key = "
|
|
1844
|
+
key = "#{target_name} #{packet_name}"
|
|
1616
1845
|
unless @@stale_packet_keys_warned.include?(key)
|
|
1617
1846
|
@@stale_packet_keys_warned.add(key)
|
|
1618
1847
|
Logger.warn("Stale tlmcnt Redis key detected for unknown packet #{key} - ignoring")
|
|
@@ -1621,7 +1850,34 @@ module OpenC3
|
|
|
1621
1850
|
end
|
|
1622
1851
|
end
|
|
1623
1852
|
end
|
|
1853
|
+
ensure
|
|
1854
|
+
@@sync_packet_count_mutex.synchronize { @@sync_packet_count_in_progress = false }
|
|
1855
|
+
end
|
|
1856
|
+
private_class_method :sync_and_read_back_packet_counts
|
|
1857
|
+
|
|
1858
|
+
# Write a batch detached from @@sync_packet_count_data to Redis. Entries are
|
|
1859
|
+
# removed as they're written so if a write fails only the unwritten counts
|
|
1860
|
+
# are put back for the next sync.
|
|
1861
|
+
def self.write_packet_counts(sync_data, scope:)
|
|
1862
|
+
sync_data.each do |target_name, packet_data|
|
|
1863
|
+
packet_data.keys.each do |packet_name|
|
|
1864
|
+
increment_telemetry_count(target_name, packet_name, packet_data[packet_name], scope: scope)
|
|
1865
|
+
packet_data.delete(packet_name)
|
|
1866
|
+
end
|
|
1867
|
+
end
|
|
1868
|
+
rescue StandardError
|
|
1869
|
+
@@sync_packet_count_mutex.synchronize do
|
|
1870
|
+
sync_data.each do |target_name, packet_data|
|
|
1871
|
+
packet_data.each do |packet_name, count|
|
|
1872
|
+
@@sync_packet_count_data[target_name] ||= {}
|
|
1873
|
+
@@sync_packet_count_data[target_name][packet_name] ||= 0
|
|
1874
|
+
@@sync_packet_count_data[target_name][packet_name] += count
|
|
1875
|
+
end
|
|
1876
|
+
end
|
|
1877
|
+
end
|
|
1878
|
+
raise
|
|
1624
1879
|
end
|
|
1880
|
+
private_class_method :write_packet_counts
|
|
1625
1881
|
|
|
1626
1882
|
def self.increment_command_count(target_name, packet_name, count, scope:)
|
|
1627
1883
|
result = store_for_target(target_name, scope: scope).hincrby("#{scope}__COMMANDCNTS__{#{target_name}}", packet_name, count)
|