@@ -20,13 +20,14 @@ class ExtensionNameUtil {
20
20
enum class Status { Warn, Block };
21
21
22
22
/* *
23
- * Returns the status of deprecated extension names.
23
+ * Checks the status of deprecated extension names and increments the deprecated feature stats
24
+ * counter if deprecated names are allowed.
24
25
*
25
- * @return Status indicating whether deprecated names trigger warnings or are blocked.
26
+ * @param runtime Runtime::Loader used to determine if deprecated extension names are allowed.
27
+ * @return Status::Warn (allowed, warn) or Status::Block (disallowed, error)
26
28
*/
27
29
static Status deprecatedExtensionNameStatus (
28
30
Runtime::Loader* runtime = Runtime::LoaderSingleton::getExisting()) {
29
-
30
31
#ifdef ENVOY_DISABLE_DEPRECATED_FEATURES
31
32
UNREFERENCED_PARAMETER (runtime);
32
33
return Status::Block;
@@ -43,9 +44,42 @@ class ExtensionNameUtil {
43
44
}
44
45
45
46
/* *
46
- * Checks the status of deprecated extension and either generates a log message or throws.
47
- * The passed strings are used only to generate the log or exception message.
47
+ * Checks the status of deprecated extension names. If deprecated extension names are allowed,
48
+ * it increments the deprecated feature stats counter. Generates a warning or error log message
49
+ * based on whether the name is allowed (warning) or not (error). The string parameters are used
50
+ * only to generate the log message.
51
+ *
52
+ * @param extension_type absl::string_view that contains the extension type, for logging
53
+ * @param deprecated_name absl::string_view that contains the deprecated name, for logging
54
+ * @param canonical_name absl::string_view that contains the canonical name, for logging
55
+ * @param runtime Runtime::Loader used to determine if deprecated extension names are allowed.
56
+ * @return true if deprecated extensions are allowed, false otherwise.
57
+ */
58
+ static bool
59
+ allowDeprecatedExtensionName (absl::string_view extension_type, absl::string_view deprecated_name,
60
+ absl::string_view canonical_name,
61
+ Runtime::Loader* runtime = Runtime::LoaderSingleton::getExisting()) {
62
+ auto status = deprecatedExtensionNameStatus (runtime);
63
+
64
+ if (status == Status::Warn) {
65
+ ENVOY_LOG_MISC (warn, " {}" , message (extension_type, deprecated_name, canonical_name));
66
+ return true ;
67
+ }
68
+
69
+ ENVOY_LOG_MISC (error, " {}" , fatalMessage (extension_type, deprecated_name, canonical_name));
70
+ return false ;
71
+ }
72
+
73
+ /* *
74
+ * Checks the status of deprecated extension names. If deprecated extension names are allowed,
75
+ * it increments the deprecated feature stats counter and generates a log message. If not allowed,
76
+ * an exception is thrown. The passed strings are used only to generate the log or exception
77
+ * message.
48
78
*
79
+ * @param extension_type absl::string_view that contains the extension type, for logging
80
+ * @param deprecated_name absl::string_view that contains the deprecated name, for logging
81
+ * @param canonical_name absl::string_view that contains the canonical name, for logging
82
+ * @param runtime Runtime::Loader used to determine if deprecated extension names are allowed.
49
83
* @throw EnvoyException if the use of deprecated extension names is not allowed.
50
84
*/
51
85
static void
@@ -54,24 +88,38 @@ class ExtensionNameUtil {
54
88
Runtime::Loader* runtime = Runtime::LoaderSingleton::getExisting()) {
55
89
auto status = deprecatedExtensionNameStatus (runtime);
56
90
57
- std::string err = fmt::format (
58
- " Using deprecated {} extension name '{}' for '{}'. This name will be removed from Envoy "
59
- " soon. Please see "
60
- " https://www.envoyproxy.io/docs/envoy/latest/intro/deprecated for details." ,
61
- extension_type, deprecated_name, canonical_name);
62
-
63
91
if (status == Status::Warn) {
64
- ENVOY_LOG_MISC (warn, " {}" , err );
92
+ ENVOY_LOG_MISC (warn, " {}" , message (extension_type, deprecated_name, canonical_name) );
65
93
return ;
66
94
}
67
95
96
+ throw EnvoyException (fatalMessage (extension_type, deprecated_name, canonical_name));
97
+ }
98
+
99
+ private:
100
+ static std::string message (absl::string_view extension_type, absl::string_view deprecated_name,
101
+ absl::string_view canonical_name) {
102
+ absl::string_view spacing = extension_type.empty () ? " " : " " ;
103
+
104
+ return fmt::format (
105
+ " Using deprecated {}{}extension name '{}' for '{}'. This name will be removed from Envoy "
106
+ " soon. Please see "
107
+ " https://www.envoyproxy.io/docs/envoy/latest/intro/deprecated for details." ,
108
+ extension_type, spacing, deprecated_name, canonical_name);
109
+ }
110
+
111
+ static std::string fatalMessage (absl::string_view extension_type,
112
+ absl::string_view deprecated_name,
113
+ absl::string_view canonical_name) {
114
+ std::string err = message (extension_type, deprecated_name, canonical_name);
115
+
68
116
const char fatal_error[] =
69
117
" If continued use of this filter name is absolutely necessary, see "
70
118
" https://www.envoyproxy.io/docs/envoy/latest/configuration/operations/runtime"
71
119
" #using-runtime-overrides-for-deprecated-features for how to apply a temporary and "
72
120
" highly discouraged override." ;
73
121
74
- throw EnvoyException ( err + fatal_error) ;
122
+ return err + fatal_error;
75
123
}
76
124
};
77
125
0 commit comments