openc3 7.5.0 → 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 +236 -195
- 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 +229 -61
- 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/log_writer.rb +9 -8
- 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 +73 -5
- data/lib/openc3/microservices/interface_decom_common.rb +16 -1
- 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 +10 -3
- 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 +333 -74
- 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 +48 -22
- 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 +27 -17
- 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/extract.rb +52 -5
- data/lib/openc3/script/metadata.rb +30 -4
- data/lib/openc3/script/plugins.rb +8 -0
- data/lib/openc3/script/script.rb +9 -25
- 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 +317 -11
- data/lib/openc3/topics/router_topic.rb +6 -2
- data/lib/openc3/topics/system_events_topic.rb +9 -6
- data/lib/openc3/topics/telemetry_decom_topic.rb +12 -3
- data/lib/openc3/topics/topic.rb +9 -1
- data/lib/openc3/utilities/authentication.rb +67 -16
- data/lib/openc3/utilities/bucket.rb +5 -0
- 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 +256 -54
- 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/secrets.rb +5 -0
- data/lib/openc3/utilities/store_autoload.rb +35 -2
- data/lib/openc3/utilities/store_queued.rb +5 -1
- data/lib/openc3/version.rb +5 -5
- 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
|
|
@@ -458,10 +482,13 @@ module OpenC3
|
|
|
458
482
|
end
|
|
459
483
|
|
|
460
484
|
def self.get_item_to_packet_map(target_name, scope:)
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
item_map_key = "#{scope}__#{target_name}__item_to_packet_map"
|
|
485
|
+
# Normalize before building the key so lowercase lookups share the entry
|
|
486
|
+
# that update_store_item_map and undeploy refresh and invalidate
|
|
464
487
|
target_name = target_name.upcase
|
|
488
|
+
# The cache is keyed by item_map_key since the same target can exist in multiple scopes
|
|
489
|
+
item_map_key = "#{scope}__#{target_name}__item_to_packet_map"
|
|
490
|
+
cache_time, item_map = @@item_map_cache[item_map_key]
|
|
491
|
+
return item_map if item_map and (Time.now - cache_time) < ITEM_MAP_CACHE_TIMEOUT
|
|
465
492
|
store = store_for_target(target_name, scope: scope)
|
|
466
493
|
json_data = store.get(item_map_key)
|
|
467
494
|
if json_data
|
|
@@ -470,14 +497,18 @@ module OpenC3
|
|
|
470
497
|
item_map = build_item_to_packet_map(target_name, scope: scope)
|
|
471
498
|
store.set(item_map_key, JSON.generate(item_map, allow_nan: true))
|
|
472
499
|
end
|
|
473
|
-
@@item_map_cache[
|
|
500
|
+
@@item_map_cache[item_map_key] = [Time.now, item_map]
|
|
474
501
|
return item_map
|
|
475
502
|
end
|
|
476
503
|
|
|
477
504
|
def self.build_item_to_packet_map(target_name, scope:)
|
|
478
505
|
item_map = {}
|
|
479
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.
|
|
480
509
|
packets.each do |packet|
|
|
510
|
+
next if packet['packet_name'] == PacketConfig::LIMITS_GROUP_PACKET
|
|
511
|
+
|
|
481
512
|
items = packet['items']
|
|
482
513
|
items.each do |item|
|
|
483
514
|
item_name = item['name']
|
|
@@ -495,6 +526,7 @@ module OpenC3
|
|
|
495
526
|
usage = "#{keyword} <TARGET FOLDER NAME> <TARGET NAME>"
|
|
496
527
|
parser.verify_num_parameters(2, 2, usage)
|
|
497
528
|
parser.verify_parameter_naming(2) # Target name is the 2nd parameter
|
|
529
|
+
|
|
498
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)
|
|
499
531
|
else
|
|
500
532
|
raise ConfigParser::Error.new(parser, "Unknown keyword and parameters for Target: #{keyword} #{parameters.join(" ")}")
|
|
@@ -525,12 +557,16 @@ module OpenC3
|
|
|
525
557
|
cmd_decom_retain_time: nil,
|
|
526
558
|
tlm_decom_retain_time: nil,
|
|
527
559
|
decom_flush_period: 5.0,
|
|
560
|
+
decom_update_interval: nil,
|
|
528
561
|
cleanup_poll_time: 3600,
|
|
529
562
|
needs_dependencies: false,
|
|
530
563
|
target_microservices: {},
|
|
531
564
|
disable_erb: nil,
|
|
532
565
|
shard: 0,
|
|
533
566
|
db_shard: 0,
|
|
567
|
+
microservice_group: nil,
|
|
568
|
+
language: nil,
|
|
569
|
+
shared_resource: nil,
|
|
534
570
|
scope:
|
|
535
571
|
)
|
|
536
572
|
super("#{scope}__#{PRIMARY_KEY}", name: name, plugin: plugin, updated_at: updated_at, scope: scope)
|
|
@@ -554,12 +590,16 @@ module OpenC3
|
|
|
554
590
|
@cmd_decom_retain_time = cmd_decom_retain_time
|
|
555
591
|
@tlm_decom_retain_time = tlm_decom_retain_time
|
|
556
592
|
@decom_flush_period = decom_flush_period
|
|
593
|
+
@decom_update_interval = decom_update_interval
|
|
557
594
|
@cleanup_poll_time = cleanup_poll_time
|
|
558
595
|
@needs_dependencies = needs_dependencies
|
|
559
596
|
@target_microservices = target_microservices
|
|
560
597
|
@disable_erb = disable_erb
|
|
561
598
|
@shard = shard.to_i # to_i to handle nil
|
|
562
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
|
|
563
603
|
@bucket = Bucket.getClient()
|
|
564
604
|
@children = []
|
|
565
605
|
end
|
|
@@ -588,15 +628,36 @@ module OpenC3
|
|
|
588
628
|
'cmd_decom_retain_time' => @cmd_decom_retain_time,
|
|
589
629
|
'tlm_decom_retain_time' => @tlm_decom_retain_time,
|
|
590
630
|
'decom_flush_period' => @decom_flush_period,
|
|
631
|
+
'decom_update_interval' => @decom_update_interval,
|
|
591
632
|
'cleanup_poll_time' => @cleanup_poll_time,
|
|
592
633
|
'needs_dependencies' => @needs_dependencies,
|
|
593
634
|
'target_microservices' => @target_microservices.as_json(),
|
|
594
635
|
'disable_erb' => @disable_erb,
|
|
595
636
|
'shard' => @shard,
|
|
596
637
|
'db_shard' => @db_shard,
|
|
638
|
+
'microservice_group' => @microservice_group,
|
|
639
|
+
'language' => @language,
|
|
640
|
+
'shared_resource' => @shared_resource,
|
|
597
641
|
}
|
|
598
642
|
end
|
|
599
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
|
+
|
|
600
661
|
# Handles Target specific configuration keywords
|
|
601
662
|
def handle_config(parser, keyword, parameters)
|
|
602
663
|
case keyword
|
|
@@ -645,6 +706,14 @@ module OpenC3
|
|
|
645
706
|
when 'DECOM_FLUSH_PERIOD'
|
|
646
707
|
parser.verify_num_parameters(1, 1, "#{keyword} <Flush period in seconds>")
|
|
647
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?
|
|
648
717
|
when 'REDUCED_MINUTE_LOG_RETAIN_TIME', 'REDUCED_HOUR_LOG_RETAIN_TIME', 'REDUCED_DAY_LOG_RETAIN_TIME', 'REDUCED_LOG_RETAIN_TIME'
|
|
649
718
|
# DEPRECATED
|
|
650
719
|
when 'REDUCER_DISABLE', 'REDUCER_DISABLED', 'REDUCER_MAX_CPU_UTILIZATION', 'REDUCED_MAX_CPU_UTILIZATION'
|
|
@@ -692,6 +761,12 @@ module OpenC3
|
|
|
692
761
|
parser.verify_num_parameters(1, 1, "#{keyword} <Shard Number Starting from 0>")
|
|
693
762
|
@db_shard = Integer(parameters[0])
|
|
694
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
|
+
|
|
695
770
|
when 'STORED_LIMITS_MODE'
|
|
696
771
|
parser.verify_num_parameters(1, 1, "#{keyword} <PROCESS, LOG, or DISABLE>")
|
|
697
772
|
mode = parameters[0].to_s.upcase
|
|
@@ -700,6 +775,14 @@ module OpenC3
|
|
|
700
775
|
end
|
|
701
776
|
@stored_limits_mode = mode
|
|
702
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
|
+
|
|
703
786
|
else
|
|
704
787
|
raise ConfigParser::Error.new(parser, "Unknown keyword and parameters for Target: #{keyword} #{parameters.join(" ")}")
|
|
705
788
|
end
|
|
@@ -745,9 +828,9 @@ module OpenC3
|
|
|
745
828
|
end
|
|
746
829
|
end
|
|
747
830
|
rescue => e
|
|
748
|
-
# 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
|
|
749
832
|
# With cmd/tlm or scripts this is a serious error and we raise
|
|
750
|
-
if (filename.include?('/screens/'))
|
|
833
|
+
if (filename.include?('/screens/') or filename.include?('/dashboards/'))
|
|
751
834
|
Logger.error("ERB error parsing #{key} due to #{e.message}")
|
|
752
835
|
else
|
|
753
836
|
raise "ERB error parsing #{key} due to #{e.message}"
|
|
@@ -775,6 +858,10 @@ module OpenC3
|
|
|
775
858
|
# Build a System for just this target
|
|
776
859
|
system = System.new([@name], temp_dir)
|
|
777
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)
|
|
778
865
|
if variables["xtce_output"]
|
|
779
866
|
puts "Converting target #{@name} to .xtce files in #{variables["xtce_output"]}/#{@name}"
|
|
780
867
|
if variables['time_association_name'].to_s.empty?
|
|
@@ -787,7 +874,17 @@ module OpenC3
|
|
|
787
874
|
unless validate_only
|
|
788
875
|
build_target_archive(temp_dir, target_folder)
|
|
789
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
|
|
790
886
|
deploy_microservices(gem_path, variables, system)
|
|
887
|
+
MicroserviceGroup.update(@microservice_group, scope: @scope) if @microservice_group
|
|
791
888
|
ConfigTopic.write({ kind: 'created', type: 'target', name: @name, plugin: @plugin }, scope: @scope)
|
|
792
889
|
end
|
|
793
890
|
ensure
|
|
@@ -855,19 +952,102 @@ module OpenC3
|
|
|
855
952
|
packets_by_target.each do |target_name, packets|
|
|
856
953
|
packets.each do |packet_name, packet|
|
|
857
954
|
packet.sorted_items.each do |item|
|
|
858
|
-
if item.name.
|
|
859
|
-
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})"
|
|
860
957
|
end
|
|
861
958
|
end
|
|
862
959
|
end
|
|
863
960
|
end
|
|
864
961
|
end
|
|
865
962
|
unless too_long.empty?
|
|
866
|
-
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
|
|
867
1040
|
end
|
|
868
1041
|
end
|
|
869
1042
|
|
|
870
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
|
|
871
1051
|
prefix = "#{@scope}/targets/#{@name}/"
|
|
872
1052
|
objects = @bucket.list_objects(bucket: ENV['OPENC3_CONFIG_BUCKET'], prefix: prefix)
|
|
873
1053
|
keys = objects.map(&:key)
|
|
@@ -879,7 +1059,7 @@ module OpenC3
|
|
|
879
1059
|
end
|
|
880
1060
|
|
|
881
1061
|
self.class.get_model(name: @name, scope: @scope).limits_groups.each do |group|
|
|
882
|
-
Store.hdel("#{@scope}__limits_groups", group)
|
|
1062
|
+
Store.hdel("#{@scope}__limits_groups", LimitsEventTopic.limits_group_key(@name, group))
|
|
883
1063
|
end
|
|
884
1064
|
self.class.packets(@name, type: :CMD, scope: @scope).each do |packet|
|
|
885
1065
|
Topic.del("#{@scope}__COMMAND__{#{@name}}__#{packet['packet_name']}", db_shard: @db_shard)
|
|
@@ -900,7 +1080,7 @@ module OpenC3
|
|
|
900
1080
|
db_shard_store.del("#{@scope}__COMMANDCNTS__{#{@name}}")
|
|
901
1081
|
|
|
902
1082
|
# Note: these match the names of the services in deploy_microservices
|
|
903
|
-
%w(MULTI DECOM COMMANDLOG PACKETLOG CLEANUP).each do |type|
|
|
1083
|
+
%w(MULTI DECOM COMMANDLOG PACKETLOG CLEANUP TSDB).each do |type|
|
|
904
1084
|
target_microservices = @target_microservices[type]
|
|
905
1085
|
if target_microservices
|
|
906
1086
|
max_instances = target_microservices.length + 1
|
|
@@ -914,10 +1094,12 @@ module OpenC3
|
|
|
914
1094
|
model.destroy if model
|
|
915
1095
|
end
|
|
916
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
|
|
917
1099
|
# Delete item_map
|
|
918
1100
|
item_map_key = "#{@scope}__#{@name}__item_to_packet_map"
|
|
919
1101
|
db_shard_store.del(item_map_key)
|
|
920
|
-
@@item_map_cache[
|
|
1102
|
+
@@item_map_cache[item_map_key] = nil
|
|
921
1103
|
|
|
922
1104
|
topic = { kind: 'deleted', type: 'target', name: @name }
|
|
923
1105
|
# The UNKNOWN target doesn't have an associated plugin
|
|
@@ -1006,7 +1188,7 @@ module OpenC3
|
|
|
1006
1188
|
@ignored_parameters = target.ignored_parameters
|
|
1007
1189
|
@ignored_items = target.ignored_items
|
|
1008
1190
|
@cmd_tlm_files = target.cmd_tlm_files
|
|
1009
|
-
@limits_groups = system.limits.groups.keys
|
|
1191
|
+
@limits_groups = (system.limits.groups[@name] || {}).keys
|
|
1010
1192
|
update()
|
|
1011
1193
|
end
|
|
1012
1194
|
|
|
@@ -1027,9 +1209,12 @@ module OpenC3
|
|
|
1027
1209
|
raise e
|
|
1028
1210
|
end
|
|
1029
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)
|
|
1030
1215
|
packet.sorted_items.each do |item|
|
|
1031
1216
|
json_hash[item.name] = nil
|
|
1032
|
-
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
|
|
1033
1218
|
end
|
|
1034
1219
|
CvtModel.set(json_hash, target_name: packet.target_name, packet_name: packet.packet_name, scope: @scope)
|
|
1035
1220
|
end
|
|
@@ -1077,9 +1262,9 @@ module OpenC3
|
|
|
1077
1262
|
end
|
|
1078
1263
|
|
|
1079
1264
|
def update_store_limits_groups(system)
|
|
1080
|
-
system.limits.groups.each do |group, items|
|
|
1265
|
+
(system.limits.groups[@name] || {}).each do |group, items|
|
|
1081
1266
|
begin
|
|
1082
|
-
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))
|
|
1083
1268
|
rescue JSON::GeneratorError => e
|
|
1084
1269
|
Logger.error("Invalid text present in #{group} limits group")
|
|
1085
1270
|
raise e
|
|
@@ -1101,7 +1286,7 @@ module OpenC3
|
|
|
1101
1286
|
item_map_key = "#{@scope}__#{@name}__item_to_packet_map"
|
|
1102
1287
|
item_map = self.class.build_item_to_packet_map(@name, scope: @scope)
|
|
1103
1288
|
Store.instance(db_shard: @db_shard).set(item_map_key, JSON.generate(item_map, allow_nan: true))
|
|
1104
|
-
@@item_map_cache[
|
|
1289
|
+
@@item_map_cache[item_map_key] = [Time.now, item_map]
|
|
1105
1290
|
end
|
|
1106
1291
|
|
|
1107
1292
|
def update_store(system, clear_old: true)
|
|
@@ -1252,22 +1437,27 @@ module OpenC3
|
|
|
1252
1437
|
filename = 'decom_microservice.rb'
|
|
1253
1438
|
work_dir = '/openc3/lib/openc3/microservices'
|
|
1254
1439
|
language_cmd = target.language
|
|
1440
|
+
microservice_parent = parent
|
|
1255
1441
|
if target.language == 'python'
|
|
1256
1442
|
filename = 'decom_microservice.py'
|
|
1257
1443
|
work_dir.sub!('openc3/lib', 'openc3/python')
|
|
1258
|
-
|
|
1444
|
+
# Python can't run in a Ruby MULTI so runs standalone or in the group's Python MULTI
|
|
1445
|
+
microservice_parent = @python_parent
|
|
1259
1446
|
# Use venv Python to ensure editable packages are found
|
|
1260
1447
|
language_cmd = ENV['OPENC3_PYTHON_BIN'] || '/openc3/python/.venv/bin/python'
|
|
1261
1448
|
end
|
|
1449
|
+
options = []
|
|
1450
|
+
options << ["UPDATE_INTERVAL", @decom_update_interval] if @decom_update_interval
|
|
1262
1451
|
microservice = MicroserviceModel.new(
|
|
1263
1452
|
name: microservice_name,
|
|
1264
1453
|
folder_name: @folder_name,
|
|
1265
1454
|
cmd: [language_cmd, filename, microservice_name],
|
|
1266
1455
|
work_dir: work_dir,
|
|
1456
|
+
options: options,
|
|
1267
1457
|
topics: topics,
|
|
1268
1458
|
target_names: [@name],
|
|
1269
1459
|
plugin: @plugin,
|
|
1270
|
-
parent:
|
|
1460
|
+
parent: microservice_parent,
|
|
1271
1461
|
needs_dependencies: @needs_dependencies,
|
|
1272
1462
|
shard: @shard,
|
|
1273
1463
|
db_shard: @db_shard,
|
|
@@ -1275,7 +1465,7 @@ module OpenC3
|
|
|
1275
1465
|
)
|
|
1276
1466
|
microservice.create
|
|
1277
1467
|
microservice.deploy(gem_path, variables)
|
|
1278
|
-
@children << microservice_name if
|
|
1468
|
+
@children << microservice_name if microservice_parent
|
|
1279
1469
|
Logger.info "Configured microservice #{microservice_name}"
|
|
1280
1470
|
end
|
|
1281
1471
|
|
|
@@ -1293,7 +1483,7 @@ module OpenC3
|
|
|
1293
1483
|
options: options,
|
|
1294
1484
|
topics: topics,
|
|
1295
1485
|
plugin: @plugin,
|
|
1296
|
-
parent:
|
|
1486
|
+
parent: @python_parent, # Standalone unless in a microservice group
|
|
1297
1487
|
needs_dependencies: @needs_dependencies,
|
|
1298
1488
|
shard: @shard,
|
|
1299
1489
|
db_shard: @db_shard,
|
|
@@ -1409,10 +1599,18 @@ module OpenC3
|
|
|
1409
1599
|
end
|
|
1410
1600
|
|
|
1411
1601
|
@parent = nil
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
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
|
|
1416
1614
|
end
|
|
1417
1615
|
end
|
|
1418
1616
|
|
|
@@ -1458,8 +1656,9 @@ module OpenC3
|
|
|
1458
1656
|
end
|
|
1459
1657
|
end
|
|
1460
1658
|
|
|
1461
|
-
if @parent
|
|
1659
|
+
if @parent and !@microservice_group
|
|
1462
1660
|
# Multi Microservice to parent other target microservices
|
|
1661
|
+
# (a microservice group's are created by MicroserviceGroup.update)
|
|
1463
1662
|
deploy_multi_microservice(gem_path, variables)
|
|
1464
1663
|
end
|
|
1465
1664
|
end
|
|
@@ -1532,18 +1731,16 @@ module OpenC3
|
|
|
1532
1731
|
|
|
1533
1732
|
# Get all the packet counts with the global counters
|
|
1534
1733
|
tlm_target_names.each do |target_name|
|
|
1734
|
+
unknown_packet_names = []
|
|
1535
1735
|
get_all_telemetry_counts(target_name, scope: scope).each do |packet_name, count|
|
|
1536
1736
|
begin
|
|
1537
1737
|
update_packet = System.telemetry.packet(target_name, packet_name)
|
|
1538
1738
|
update_packet.received_count = count.to_i
|
|
1539
1739
|
rescue RuntimeError
|
|
1540
|
-
|
|
1541
|
-
unless @@stale_packet_keys_warned.include?(key)
|
|
1542
|
-
@@stale_packet_keys_warned.add(key)
|
|
1543
|
-
Logger.warn("Stale tlmcnt Redis key detected for unknown packet #{key} - ignoring")
|
|
1544
|
-
end
|
|
1740
|
+
unknown_packet_names << packet_name
|
|
1545
1741
|
end
|
|
1546
1742
|
end
|
|
1743
|
+
prune_stale_telemetry_counts(target_name, unknown_packet_names, scope: scope) unless unknown_packet_names.empty?
|
|
1547
1744
|
end
|
|
1548
1745
|
get_all_telemetry_counts('UNKNOWN', scope: scope).each do |packet_name, count|
|
|
1549
1746
|
begin
|
|
@@ -1559,6 +1756,32 @@ module OpenC3
|
|
|
1559
1756
|
end
|
|
1560
1757
|
end
|
|
1561
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
|
+
|
|
1562
1785
|
def self.sync_tlm_packet_counts(packet, tlm_target_names, scope:)
|
|
1563
1786
|
if @@sync_packet_count_delay_seconds <= 0
|
|
1564
1787
|
# Perfect but slow method
|
|
@@ -1568,48 +1791,57 @@ module OpenC3
|
|
|
1568
1791
|
# Only sync every period (default 1 second) to avoid hammering Redis
|
|
1569
1792
|
# This is a trade off between speed and accuracy
|
|
1570
1793
|
# The packet count is eventually consistent
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
@@
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
#
|
|
1585
|
-
@@
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
tlm_target_names.each do |target_name|
|
|
1594
|
-
get_all_telemetry_counts(target_name, scope: scope).each do |packet_name, count|
|
|
1595
|
-
begin
|
|
1596
|
-
update_packet = System.telemetry.packet(target_name, packet_name)
|
|
1597
|
-
update_packet.received_count = count.to_i
|
|
1598
|
-
rescue RuntimeError
|
|
1599
|
-
key = "#{target_name} #{packet_name}"
|
|
1600
|
-
unless @@stale_packet_keys_warned.include?(key)
|
|
1601
|
-
@@stale_packet_keys_warned.add(key)
|
|
1602
|
-
Logger.warn("Stale tlmcnt Redis key detected for unknown packet #{key} - ignoring")
|
|
1603
|
-
end
|
|
1604
|
-
end
|
|
1605
|
-
end
|
|
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']
|
|
1606
1816
|
end
|
|
1607
|
-
|
|
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|
|
|
1608
1837
|
begin
|
|
1609
|
-
update_packet = System.telemetry.packet(
|
|
1610
|
-
|
|
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
|
|
1611
1843
|
rescue RuntimeError
|
|
1612
|
-
key = "
|
|
1844
|
+
key = "#{target_name} #{packet_name}"
|
|
1613
1845
|
unless @@stale_packet_keys_warned.include?(key)
|
|
1614
1846
|
@@stale_packet_keys_warned.add(key)
|
|
1615
1847
|
Logger.warn("Stale tlmcnt Redis key detected for unknown packet #{key} - ignoring")
|
|
@@ -1618,7 +1850,34 @@ module OpenC3
|
|
|
1618
1850
|
end
|
|
1619
1851
|
end
|
|
1620
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
|
|
1621
1879
|
end
|
|
1880
|
+
private_class_method :write_packet_counts
|
|
1622
1881
|
|
|
1623
1882
|
def self.increment_command_count(target_name, packet_name, count, scope:)
|
|
1624
1883
|
result = store_for_target(target_name, scope: scope).hincrby("#{scope}__COMMANDCNTS__{#{target_name}}", packet_name, count)
|