Skip to content

Commit 43b0ca0

Browse files
Add new test and fix for float configuration failure in conf_remap (#6967)
Test that conf_remap can override float settings (e.g. proxy.config.http.background_fill_completed_threshold) successfully.
1 parent e3212f1 commit 43b0ca0

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

plugins/conf_remap/conf_remap.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ str_to_datatype(const char *str)
6363
type = TS_RECORDDATATYPE_INT;
6464
} else if (!strcmp(str, "STRING")) {
6565
type = TS_RECORDDATATYPE_STRING;
66+
} else if (!strcmp(str, "FLOAT")) {
67+
type = TS_RECORDDATATYPE_FLOAT;
6668
}
6769

6870
return type;
@@ -106,6 +108,9 @@ RemapConfigs::parse_inline(const char *arg)
106108
_items[_current]._data_len = value.size();
107109
}
108110
break;
111+
case TS_RECORDDATATYPE_FLOAT:
112+
_items[_current]._data.rec_float = strtof(value.c_str(), nullptr);
113+
break;
109114
default:
110115
TSError("[%s] Configuration variable '%s' is of an unsupported type", PLUGIN_NAME, key.c_str());
111116
return false;
@@ -181,7 +186,7 @@ RemapConfigs::parse_file(const char *filename)
181186
// Find the type (INT or STRING only)
182187
tok = strtok_r(nullptr, " \t", &ln);
183188
if (TS_RECORDDATATYPE_NULL == (type = str_to_datatype(tok))) {
184-
TSError("[%s] file %s, line %d: only INT and STRING types supported", PLUGIN_NAME, path.c_str(), line_num);
189+
TSError("[%s] file %s, line %d: only INT, STRING, and FLOAT types supported", PLUGIN_NAME, path.c_str(), line_num);
185190
continue;
186191
}
187192

@@ -231,6 +236,9 @@ RemapConfigs::parse_file(const char *filename)
231236
_items[_current]._data_len = strlen(tok);
232237
}
233238
break;
239+
case TS_RECORDDATATYPE_FLOAT:
240+
_items[_current]._data.rec_float = strtof(tok, nullptr);
241+
break;
234242
default:
235243
TSError("[%s] file %s, line %d: type not support (unheard of)", PLUGIN_NAME, path.c_str(), line_num);
236244
continue;
@@ -330,6 +338,10 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo * /* rri ATS_UNUSED */
330338
TSHttpTxnConfigStringSet(txnp, conf->_items[ix]._name, conf->_items[ix]._data.rec_string, conf->_items[ix]._data_len);
331339
TSDebug(PLUGIN_NAME, "Setting config id %d to %s", conf->_items[ix]._name, conf->_items[ix]._data.rec_string);
332340
break;
341+
case TS_RECORDDATATYPE_FLOAT:
342+
TSHttpTxnConfigFloatSet(txnp, conf->_items[ix]._name, conf->_items[ix]._data.rec_int);
343+
TSDebug(PLUGIN_NAME, "Setting config id %d to %f", conf->_items[ix]._name, conf->_items[ix]._data.rec_float);
344+
break;
333345
default:
334346
break; // Error ?
335347
}

tests/gold_tests/autest-site/trafficserver.test.ext

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ def MakeATSProcess(obj, name, command='traffic_server', select_ports=True,
209209
tmpname = os.path.join(config_dir, fname)
210210
p.Disk.File(tmpname, id=make_id(fname), typename="ats:config")
211211

212+
# for conf_remap_float, used by conf_remap plugin
213+
fname = "delain.config"
214+
tmpname = os.path.join(config_dir, fname)
215+
p.Disk.File(tmpname, id=make_id(fname), typename="ats:config")
216+
212217
fname = "hosting.config"
213218
tmpname = os.path.join(config_dir, fname)
214219
p.Disk.File(tmpname, id=make_id(fname), typename="ats:config")
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
'''
2+
'''
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
20+
import os
21+
22+
Test.Summary = '''
23+
Test command: traffic_ctl config describe proxy.config.http.background_fill_completed_threshold (YTSATS-3309)
24+
'''
25+
Test.testName = 'Float in conf_remap Config Test'
26+
27+
ts = Test.MakeATSProcess("ts", command="traffic_manager", select_ports=True)
28+
29+
# Add dummy remap rule
30+
ts.Disk.remap_config.AddLine(
31+
'map http://cdn.example.com/ http://origin.example.com/ @plugin=conf_remap.so @pparam={file}'.format(file=os.path.join(ts.RunDirectory, 'ts/config/delain.config'))
32+
)
33+
34+
ts.Disk.delain_config.AddLine(
35+
'CONFIG proxy.config.http.background_fill_completed_threshold FLOAT 0.500000'
36+
)
37+
38+
#
39+
# Test body
40+
#
41+
42+
# First reload
43+
tr = Test.AddTestRun("traffic_ctl command")
44+
tr.Env = ts.Env
45+
tr.TimeOut = 5
46+
tr.StillRunningAfter = ts
47+
48+
p = tr.Processes.Default
49+
p.Command = "traffic_ctl config describe proxy.config.http.background_fill_completed_threshold"
50+
p.ReturnCode = 0
51+
p.StartBefore(Test.Processes.ts, ready=When.FileExists(os.path.join(tr.RunDirectory, 'ts/log/diags.log')))

0 commit comments

Comments
 (0)