|
1 | 1 | <% |
2 | 2 | require 'cgi' |
3 | 3 |
|
4 | | - def yaml_escape(input_string) |
5 | | - chars_to_escape = /[:\\"\x00-\x1f\x7f]/ |
6 | | - chars_needing_quotes = /[ !#'&%*,:>@\[\]\\`{|}]/ |
7 | | - delimiter = (chars_needing_quotes.match(input_string) || |
8 | | - chars_to_escape.match(input_string)) ? '"' : '' |
9 | | - fixed_string = input_string.gsub(/(#{chars_to_escape})/) { |m| "\\x#{'%x' % m.ord}" } |
10 | | - "#{delimiter}#{fixed_string}#{delimiter}" |
11 | | - end |
12 | | - |
13 | 4 | def deep_merge_without_overwrite(base, extra) |
14 | 5 | return base unless extra.is_a?(Hash) |
15 | 6 |
|
|
28 | 19 | end |
29 | 20 |
|
30 | 21 | cc_cfg = (link("cloud_controller_internal").p("cc") rescue {}) |
31 | | - |
32 | 22 | unless cc_cfg.is_a?(Hash) |
33 | 23 | raise "cc link did not return a Hash, got: #{cc_cfg.class}" |
34 | 24 | end |
35 | 25 |
|
| 26 | + overrides = p("blobstore_benchmark.cc_overrides", {}) |
| 27 | + unless overrides.is_a?(Hash) |
| 28 | + raise "blobstore_benchmark.cc_overrides must be a Hash, got: #{overrides.class}" |
| 29 | + end |
| 30 | + |
| 31 | + def deep_stringify_keys(obj) |
| 32 | + return obj unless obj.is_a?(Hash) |
| 33 | + |
| 34 | + obj.each_with_object({}) do |(k, v), h| |
| 35 | + h[k.to_s] = v.is_a?(Hash) ? deep_stringify_keys(v) : v |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + def deep_merge_overwrite(base, extra) |
| 40 | + return base unless extra.is_a?(Hash) |
| 41 | + |
| 42 | + extra.each do |k, v| |
| 43 | + if base[k].is_a?(Hash) && v.is_a?(Hash) |
| 44 | + deep_merge_overwrite(base[k], v) |
| 45 | + else |
| 46 | + base[k] = v |
| 47 | + end |
| 48 | + end |
| 49 | + |
| 50 | + base |
| 51 | + end |
| 52 | + |
| 53 | + cc_cfg = deep_merge_overwrite(cc_cfg, overrides) |
| 54 | + |
36 | 55 | %w[resource_pool buildpacks packages droplets].each do |k| |
37 | 56 | section = cc_cfg[k] |
38 | 57 | next unless section.is_a?(Hash) |
|
72 | 91 | db_hash['ca_cert_path'] = '/var/vcap/jobs/blobstore_benchmark/config/certs/db_ca.crt' |
73 | 92 | end |
74 | 93 |
|
75 | | - logging_level = p("cc.logging_level", cc_cfg["logging_level"] || cc_cfg.dig("logging", "level") || "error") |
| 94 | + benchmark_logging_level = p("blobstore_benchmark.logging_level", "info") |
| 95 | + benchmark_stdout_sink = p("blobstore_benchmark.stdout_sink_enabled", false) |
76 | 96 |
|
77 | 97 | final = { |
78 | 98 | 'pid_filename' => '/var/vcap/sys/run/blobstore_benchmark/blobstore_benchmark.pid', |
|
82 | 102 | 'logging' => { |
83 | 103 | 'file' => '/var/vcap/sys/log/blobstore_benchmark/blobstore_benchmark.log', |
84 | 104 | 'syslog' => 'vcap.cloud_controller_ng', |
85 | | - 'level' => logging_level.to_s, |
| 105 | + 'level' => benchmark_logging_level.to_s, |
| 106 | + |
86 | 107 | 'max_retries' => p("cc.logging_max_retries", cc_cfg["logging_max_retries"] || 0), |
87 | 108 | 'format' => { |
88 | 109 | 'timestamp' => (cc_cfg.dig("logging", "format", "timestamp") || |
89 | 110 | link("cloud_controller_internal").p("cc.logging.format.timestamp", "rfc3339")) |
90 | 111 | }, |
91 | | - 'stdout_sink_enabled' => p('cc.stdout_logging_enabled', false) |
| 112 | + 'stdout_sink_enabled' => benchmark_stdout_sink |
92 | 113 | }, |
93 | 114 |
|
94 | 115 | 'db' => db_hash, |
95 | | - |
96 | | - 'storage_cli_config_file_resource_pool' => '/var/vcap/jobs/blobstore_benchmark/config/storage_cli_config_resource_pool.json', |
97 | | - 'storage_cli_config_file_buildpacks' => '/var/vcap/jobs/blobstore_benchmark/config/storage_cli_config_buildpacks.json', |
98 | | - 'storage_cli_config_file_packages' => '/var/vcap/jobs/blobstore_benchmark/config/storage_cli_config_packages.json', |
99 | | - 'storage_cli_config_file_droplets' => '/var/vcap/jobs/blobstore_benchmark/config/storage_cli_config_droplets.json', |
100 | 116 | } |
101 | 117 |
|
| 118 | + mode = p("blobstore_benchmark.mode") |
| 119 | + |
| 120 | + # Only configure storage-cli JSON config paths when running storage-cli mode |
| 121 | + if mode == "storage-cli" |
| 122 | + final.merge!( |
| 123 | + 'storage_cli_config_file_resource_pool' => '/var/vcap/jobs/blobstore_benchmark/config/storage_cli_config_resource_pool.json', |
| 124 | + 'storage_cli_config_file_buildpacks' => '/var/vcap/jobs/blobstore_benchmark/config/storage_cli_config_buildpacks.json', |
| 125 | + 'storage_cli_config_file_packages' => '/var/vcap/jobs/blobstore_benchmark/config/storage_cli_config_packages.json', |
| 126 | + 'storage_cli_config_file_droplets' => '/var/vcap/jobs/blobstore_benchmark/config/storage_cli_config_droplets.json', |
| 127 | + ) |
| 128 | + end |
| 129 | + |
102 | 130 | deep_merge_without_overwrite(final, cc_cfg) |
103 | 131 | %> |
104 | 132 | --- |
|
0 commit comments