Copilot commented on code in PR #12752:
URL: https://github.com/apache/trafficserver/pull/12752#discussion_r2610821156
##########
src/traffic_ctl/CtrlCommands.cc:
##########
@@ -237,6 +255,49 @@ ConfigCommand::config_set()
_printer->write_output(response);
}
+void
+ConfigCommand::config_reset()
+{
+ auto const &paths = get_parsed_arguments()->get(RESET_STR);
+
+ // Build lookup request - always use REGEX to support partial path matching
+ shared::rpc::RecordLookupRequest lookup_request;
+
+ if (paths.empty() || (paths.size() == 1 && paths[0] == "records")) {
+ lookup_request.emplace_rec(".*", shared::rpc::REGEX,
shared::rpc::CONFIG_REC_TYPES);
+ } else {
+ for (auto const &path : paths) {
+ // Convert YAML-style path (records.*) to record name format
(proxy.config.*)
+ auto record_path = yaml_to_record_name(path);
+ lookup_request.emplace_rec(record_path, shared::rpc::REGEX,
shared::rpc::CONFIG_REC_TYPES);
+ }
+ }
+
+ // Lookup matching records
+ auto lookup_response = invoke_rpc(lookup_request);
+ if (lookup_response.is_error()) {
+ _printer->write_output(lookup_response);
+ return;
+ }
+
+ // Build reset request from modified records (current != default)
+ auto const &records =
lookup_response.result.as<shared::rpc::RecordLookUpResponse>();
+ ConfigSetRecordRequest set_request;
+
+ for (auto const &rec : records.recordList) {
+ if (rec.currentValue != rec.defaultValue) {
+ set_request.params.push_back(ConfigSetRecordRequest::Params{rec.name,
rec.defaultValue});
+ }
+ }
+
+ if (set_request.params.size() == 0) {
Review Comment:
Use `.empty()` instead of `.size() == 0` for container emptiness checks.
This is more idiomatic C++ and clearly expresses the intent to check for
emptiness rather than a specific size value.
```suggestion
if (set_request.params.empty()) {
```
##########
tests/gold_tests/traffic_ctl/traffic_ctl_config_output.test.py:
##########
@@ -70,12 +72,70 @@
traffic_ctl.config().match("diags.logfile").as_records().validate_with_goldfile("t4_yaml.gold")
##### CONFIG DIFF
+# Test 7:
traffic_ctl.config().diff().validate_with_goldfile("diff.gold")
+# Test 8:
traffic_ctl.config().diff().as_records().validate_with_goldfile("diff_yaml.gold")
##### CONFIG DESCRIBE
-# don't really care about values, but just output and that the command
actually went through
+# Test 9: don't really care about values, but just output and that the command
actually went through
traffic_ctl.config().describe("proxy.config.http.server_ports").validate_with_goldfile("describe.gold")
-# Make sure that the command returns an exit code of 2
+##### CONFIG RESET
+# Test 10: Reset a single modified record (proxy.config.diags.debug.tags is
set to "rpc" in records_yaml,
+# default is "http|dns", so it should be reset)
+traffic_ctl.config().reset("proxy.config.diags.debug.tags").validate_with_text(
+ "Set proxy.config.diags.debug.tags, please wait 10 seconds for traffic
server to sync "
+ "configuration, restart is not required")
+# Test 11: Validate the record was reset to its default value
+traffic_ctl.config().get("proxy.config.diags.debug.tags").validate_with_text("proxy.config.diags.debug.tags:
http|dns")
+
+# Test 12: Reset records matching a partial path (proxy.config.diags)
+# First set the record back to non-default for this test
+traffic_ctl.config().set("proxy.config.diags.debug.tags", "rpc").exec()
+# Test 13: Resetting proxy.config.diags should reset all matching modified
records under that path
+traffic_ctl.config().reset("proxy.config.diags").validate_contains_all(
+ "Set proxy.config.diags.debug.tags", "Set
proxy.config.diags.debug.enabled")
+# Test 14: Validate the record was reset to its default value
+traffic_ctl.config().get("proxy.config.diags.debug.tags").validate_with_text("proxy.config.diags.debug.tags:
http|dns")
+
+# Test 15: Reset all records using "records" keyword
+# First set the record back to non-default for this test
+traffic_ctl.config().set("proxy.config.diags.debug.tags", "rpc").exec()
+# Test 16: This will reset all modified records (including
proxy.config.diags.debug.tags)
+# Some may require restart, which is ok, we can use diff anyways as the
records that needs
+# restart will just chage the value but won't have any effect.
Review Comment:
Typo in comment: "chage" should be "change"
```suggestion
# restart will just change the value but won't have any effect.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]