Skip to content

Commit aa9eccf

Browse files
authored
Merge branch 'master' into dmehala/send-integration-errors
2 parents 5d6e7f3 + 2f646bb commit aa9eccf

36 files changed

+1013
-1160
lines changed

.circleci/continue_config.yml

+7-3
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ jobs:
294294
name: Move the module to the system-tests directory
295295
working_directory: ./system-tests
296296
- run:
297-
command: ./build.sh cpp
297+
command: ./build.sh cpp_nginx
298298
name: Build test targets
299299
working_directory: ./system-tests
300300
- run:
@@ -460,7 +460,7 @@ workflows:
460460
- amd64
461461
- arm64
462462
version:
463-
- 1.12.0
463+
- 1.12.1
464464
name: build ingress-nginx-<< matrix.version >> on << matrix.arch >>
465465
- coverage:
466466
name: Coverage on 1.27.0 with WAF ON
@@ -538,7 +538,7 @@ workflows:
538538
base-image:
539539
- registry.k8s.io/ingress-nginx/controller
540540
nginx-version:
541-
- 1.12.0
541+
- 1.12.1
542542
name: test ingress-nginx-<< matrix.nginx-version >> on << matrix.arch >>
543543
requires:
544544
- build ingress-nginx-<< matrix.nginx-version >> on << matrix.arch >>
@@ -562,7 +562,9 @@ workflows:
562562
- amd64
563563
- arm64
564564
version:
565+
- 1.12.1
565566
- 1.12.0
567+
- 1.11.5
566568
- 1.11.4
567569
- 1.11.3
568570
- 1.11.2
@@ -587,7 +589,9 @@ workflows:
587589
base-image:
588590
- registry.k8s.io/ingress-nginx/controller
589591
nginx-version:
592+
- 1.12.1
590593
- 1.12.0
594+
- 1.11.5
591595
- 1.11.4
592596
- 1.11.3
593597
- 1.11.2

.circleci/src/@jobs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ jobs:
250250
- run:
251251
name: Build test targets
252252
working_directory: ./system-tests
253-
command: ./build.sh cpp
253+
command: ./build.sh cpp_nginx
254254
- run:
255255
name: Run DEFAULT scenarios
256256
working_directory: ./system-tests

.circleci/src/workflows/build-and-test-all.yml

+4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
- 'amd64'
1515
- 'arm64'
1616
version:
17+
- 1.12.1
1718
- 1.12.0
19+
- 1.11.5
1820
- 1.11.4
1921
- 1.11.3
2022
- 1.11.2
@@ -41,7 +43,9 @@
4143
base-image:
4244
- registry.k8s.io/ingress-nginx/controller
4345
nginx-version:
46+
- 1.12.1
4447
- 1.12.0
48+
- 1.11.5
4549
- 1.11.4
4650
- 1.11.3
4751
- 1.11.2

.circleci/src/workflows/build-and-test.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
- 'amd64'
4848
- 'arm64'
4949
version:
50-
- 1.12.0
50+
- 1.12.1
5151
- coverage:
5252
name: Coverage on 1.27.0 with WAF ON
5353
- test:
@@ -131,7 +131,7 @@ jobs:
131131
base-image:
132132
- registry.k8s.io/ingress-nginx/controller
133133
nginx-version:
134-
- 1.12.0
134+
- 1.12.1
135135
- system_tests:
136136
name: Run system tests
137137
requires:

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ set_target_properties(ngx_http_datadog_objs PROPERTIES POSITION_INDEPENDENT_CODE
136136
target_compile_definitions(ngx_http_datadog_objs PUBLIC DD_NGINX_FLAVOR="${NGINX_DATADOG_FLAVOR}")
137137
target_sources(ngx_http_datadog_objs
138138
PRIVATE
139+
src/common/variable.cpp
139140
src/array_util.cpp
140141
src/datadog_conf.cpp
141142
src/datadog_conf_handler.cpp

bin/ingress_nginx.py

+4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
def get_underlying_nginx_version(controller_version: str) -> str:
3434
# Map an ingress-nginx version to an NGINX version
3535
mapping = {
36+
"v1.12.1": "1.25.5",
3637
"v1.12.0": "1.25.5",
38+
"v1.11.5": "1.25.5",
3739
"v1.11.4": "1.25.5",
3840
"v1.11.3": "1.25.5",
3941
"v1.11.2": "1.25.5",
@@ -73,7 +75,9 @@ def clone_nginx(version: str, out_dir: str) -> str:
7375

7476
def get_patch_directory(version: str, ingress_rootdir: str) -> str:
7577
mapping = {
78+
"v1.12.1": f"{ingress_rootdir}/images/nginx/rootfs/patches",
7679
"v1.12.0": f"{ingress_rootdir}/images/nginx/rootfs/patches",
80+
"v1.11.5": f"{ingress_rootdir}/images/nginx/rootfs/patches",
7781
"v1.11.4": f"{ingress_rootdir}/images/nginx/rootfs/patches",
7882
"v1.11.3": f"{ingress_rootdir}/images/nginx/rootfs/patches",
7983
"v1.11.2": f"{ingress_rootdir}/images/nginx-1.25/rootfs/patches",

libddwaf

Submodule libddwaf updated 209 files

src/common/variable.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include "common/variable.h"
2+
3+
#include "string_util.h"
4+
5+
namespace datadog::common {
6+
7+
ngx_http_complex_value_t *make_complex_value(ngx_conf_t *cf, ngx_str_t &expr) {
8+
auto *cv = (ngx_http_complex_value_t *)ngx_pcalloc(
9+
cf->pool, sizeof(ngx_http_complex_value_t));
10+
11+
ngx_http_compile_complex_value_t ccv;
12+
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
13+
14+
ccv.cf = cf;
15+
ccv.value = &expr;
16+
ccv.complex_value = cv;
17+
ccv.zero = 0;
18+
ccv.conf_prefix = 0;
19+
20+
if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
21+
return nullptr;
22+
}
23+
24+
return cv;
25+
}
26+
27+
ngx_http_complex_value_t *make_complex_value(ngx_conf_t *cf,
28+
std::string_view expr) {
29+
auto ngx_expr = nginx::to_ngx_str(cf->pool, expr);
30+
return make_complex_value(cf, ngx_expr);
31+
}
32+
33+
std::optional<std::string> eval_complex_value(
34+
ngx_http_complex_value_t *complex_value, ngx_http_request_t *request) {
35+
if (complex_value == nullptr) return std::nullopt;
36+
37+
ngx_str_t res;
38+
if (ngx_http_complex_value(request, complex_value, &res) != NGX_OK ||
39+
res.len == 0) {
40+
return std::nullopt;
41+
}
42+
43+
return nginx::to_string(res);
44+
}
45+
46+
} // namespace datadog::common

src/common/variable.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#pragma once
2+
3+
extern "C" {
4+
5+
#include <nginx.h>
6+
#include <ngx_conf_file.h>
7+
#include <ngx_config.h>
8+
#include <ngx_core.h>
9+
#include <ngx_http.h>
10+
#include <ngx_log.h>
11+
}
12+
13+
#include <optional>
14+
#include <string>
15+
16+
namespace datadog::common {
17+
18+
/// Extracted from NGINX Development Guide
19+
/// (<https://nginx.org/en/docs/dev/development_guide.html#http_complex_values>)
20+
///
21+
/// A complex value, despite its name, provides an easy way to evaluate
22+
/// expressions which can contain text, variables, and their combination.
23+
ngx_http_complex_value_t *make_complex_value(ngx_conf_t *cf,
24+
ngx_str_t &default_value);
25+
26+
ngx_http_complex_value_t *make_complex_value(ngx_conf_t *cf,
27+
std::string_view default_value);
28+
29+
/// Evaluate complex expressions. Returns the value if the evaluation is
30+
/// successful, otherwise returns nothing.
31+
std::optional<std::string> eval_complex_value(
32+
ngx_http_complex_value_t *complex_value, ngx_http_request_t *request);
33+
34+
} // namespace datadog::common

src/datadog_conf.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern "C" {
1717
#endif
1818

1919
#include <string>
20+
#include <unordered_map>
2021
#include <vector>
2122

2223
#define DD_NGX_CONF_COMPLEX_UNSET \
@@ -25,11 +26,6 @@ extern "C" {
2526
namespace datadog {
2627
namespace nginx {
2728

28-
struct datadog_tag_t {
29-
NgxScript key_script;
30-
NgxScript value_script;
31-
};
32-
3329
struct conf_directive_source_location_t {
3430
ngx_str_t file_name; // e.g. "nginx.conf"
3531
ngx_uint_t line; // line number within the file `file_name`
@@ -61,7 +57,7 @@ struct sampling_rule_t {
6157
};
6258

6359
struct datadog_main_conf_t {
64-
ngx_array_t *tags;
60+
std::unordered_map<std::string, ngx_http_complex_value_t *> tags;
6561
// `are_propagation_styles_locked` is whether the tracer's propagation styles
6662
// have been set, either by an explicit `datadog_propagation_styles`
6763
// directive, or implicitly to a default configuration by another directive.
@@ -197,7 +193,7 @@ struct datadog_loc_conf_t {
197193
ngx_http_complex_value_t *service_env = DD_NGX_CONF_COMPLEX_UNSET;
198194
// `service_version` is set by the `datadog_version` directive.
199195
ngx_http_complex_value_t *service_version = DD_NGX_CONF_COMPLEX_UNSET;
200-
ngx_array_t *tags;
196+
std::unordered_map<std::string, ngx_http_complex_value_t *> tags;
201197
// `parent` is the parent context (e.g. the `server` to this `location`), or
202198
// `nullptr` if this context has no parent.
203199
datadog_loc_conf_t *parent;

src/datadog_directive.cpp

+60-8
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,73 @@
22

33
#include <cassert>
44

5+
#include "datadog_conf_handler.h"
6+
57
namespace datadog {
68
namespace nginx {
79

8-
char *warn_deprecated_command_datadog_tracing(ngx_conf_t *cf,
9-
ngx_command_t * /*command*/,
10-
void * /*conf*/) noexcept {
10+
char *silently_ignore_command(ngx_conf_t *cf, ngx_command_t *command, void *) {
11+
ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "Directive \"%V\" ignored",
12+
&command->name);
13+
return NGX_CONF_OK;
14+
}
15+
16+
char *alias_directive(ngx_conf_t *cf, ngx_command_t *command, void *) noexcept {
17+
if (command->post == nullptr) {
18+
return static_cast<char *>(NGX_CONF_ERROR);
19+
}
20+
21+
auto src_directive = static_cast<char *>(command->post);
22+
1123
const auto elements = static_cast<ngx_str_t *>(cf->args->elts);
1224
assert(cf->args->nelts >= 1);
1325

14-
ngx_log_error(
15-
NGX_LOG_WARN, cf->log, 0,
16-
"Directive \"%V\" is deprecated. Use datadog_tracing on/off instead",
17-
&elements[0]);
26+
const ngx_str_t new_name_ngx{.len = strlen(src_directive),
27+
.data = (u_char *)src_directive};
28+
ngx_conf_log_error(NGX_LOG_DEBUG, cf, 0, "Alias \"%V\" to \"%V\"",
29+
&command->name, &new_name_ngx);
30+
31+
// Rename the command and let `datadog_conf_handler` dispatch to the
32+
// appropriate handler.
33+
elements[0] = new_name_ngx;
34+
auto rcode = datadog_conf_handler({.conf = cf, .skip_this_module = false});
35+
if (rcode != NGX_OK) {
36+
return static_cast<char *>(NGX_CONF_ERROR);
37+
}
38+
39+
return NGX_CONF_OK;
40+
}
41+
42+
char *warn_deprecated_command(ngx_conf_t *cf, ngx_command_t *command,
43+
void *) noexcept {
44+
u_char buf[NGX_MAX_ERROR_STR] = {0};
45+
u_char *last = buf + NGX_MAX_ERROR_STR;
46+
u_char *p =
47+
ngx_slprintf(buf, last, "Directive \"%V\" is deprecated", &command->name);
48+
49+
if (command->post != nullptr) {
50+
auto reason = static_cast<char *>(command->post);
51+
ngx_slprintf(p, last, ". %s", reason);
52+
}
53+
54+
ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "%s", buf);
55+
return NGX_CONF_OK;
56+
}
57+
58+
char *err_deprecated_command(ngx_conf_t *cf, ngx_command_t *command,
59+
void *) noexcept {
60+
u_char buf[NGX_MAX_ERROR_STR] = {0};
61+
u_char *last = buf + NGX_MAX_ERROR_STR;
62+
u_char *p =
63+
ngx_slprintf(buf, last, "Directive \"%V\" is deprecated", &command->name);
64+
65+
if (command->post != nullptr) {
66+
auto reason = static_cast<char *>(command->post);
67+
ngx_slprintf(p, last, ". %s", reason);
68+
}
1869

19-
return NGX_OK;
70+
ngx_conf_log_error(NGX_LOG_WARN, cf, 0, "%s", buf);
71+
return static_cast<char *>(NGX_CONF_ERROR);
2072
}
2173

2274
} // namespace nginx

src/datadog_directive.h

+31-3
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,39 @@ constexpr auto generate_directives(const T &...directives) {
7272
return merge_directives(directives...);
7373
}
7474

75+
#define IGNORE_COMMAND(NAME, TYPE) \
76+
{ NAME, TYPE, silently_ignore_command, NGX_HTTP_LOC_CONF_OFFSET, 0, nullptr }
77+
78+
#define ALIAS_COMMAND(SRC_DIRECTIVE, TARGET_DIRECTIVE, TYPE) \
79+
{ \
80+
TARGET_DIRECTIVE, TYPE, alias_directive, NGX_HTTP_LOC_CONF_OFFSET, 0, \
81+
(void *)SRC_DIRECTIVE \
82+
}
83+
84+
#define WARN_DEPRECATED_COMMAND(NAME, TYPE, MSG) \
85+
{ \
86+
NAME, TYPE, warn_deprecated_command, NGX_HTTP_LOC_CONF_OFFSET, 0, \
87+
(void *)MSG \
88+
}
89+
90+
#define ERROR_DEPRECATED_COMMAND(NAME, TYPE, MSG) \
91+
{ \
92+
NAME, TYPE, err_deprecated_command, NGX_HTTP_LOC_CONF_OFFSET, 0, \
93+
(void *)MSG \
94+
}
95+
96+
char *silently_ignore_command(ngx_conf_t *, ngx_command_t *, void *);
97+
98+
char *alias_directive(ngx_conf_t *cf, ngx_command_t *command,
99+
void *conf) noexcept;
100+
75101
char *set_datadog_agent_url(ngx_conf_t *, ngx_command_t *, void *conf) noexcept;
76102

77-
char *warn_deprecated_command_datadog_tracing(ngx_conf_t *cf,
78-
ngx_command_t * /*command*/,
79-
void * /*conf*/) noexcept;
103+
char *warn_deprecated_command(ngx_conf_t *cf, ngx_command_t *command,
104+
void *conf) noexcept;
105+
106+
char *err_deprecated_command(ngx_conf_t *cf, ngx_command_t *command,
107+
void *) noexcept;
80108

81109
} // namespace nginx
82110
} // namespace datadog

0 commit comments

Comments
 (0)