Skip to content

Commit

Permalink
Merge pull request #48 from sorc1/feature/rwlock
Browse files Browse the repository at this point in the history
Restore dynamic graphics
  • Loading branch information
kirimedia authored Mar 29, 2022
2 parents b6c4781 + 0d4401a commit 450ea38
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 83 deletions.
66 changes: 64 additions & 2 deletions lua_module_v0_10_12.patch
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
From 9a1e0a0ec78c8281e1ccd006554b1c3dca2742a8 Mon Sep 17 00:00:00 2001
From: Mikhail Kirichenko <m.kirichenko@corp.mail.ru>
Date: Mon, 19 Apr 2021 20:21:23 +0300
Subject: [PATCH 1/2] initial patch
Subject: [PATCH 1/3] initial patch

---
config | 2 +
Expand Down Expand Up @@ -225,7 +225,7 @@ index f7a537ee..6292d8b5 100644
From 49a877588691ea7136a7472ab95df2665d546c64 Mon Sep 17 00:00:00 2001
From: Alexander Drozdov <aleksandr.drozdov@corp.mail.ru>
Date: Mon, 19 Apr 2021 20:09:05 +0300
Subject: [PATCH 2/2] add ngx.graphite.param feature
Subject: [PATCH 2/3] add ngx.graphite.param feature

Add ngx.graphite.param() function that returns an object by graphite
parameter name. We name it 'parameter link'. The link then
Expand Down Expand Up @@ -375,3 +375,65 @@ index 9178553d..142c6e9f 100644
--
2.25.1


From c40cf28bbf35da8c18668f5b8f165aa89a6202dc Mon Sep 17 00:00:00 2001
From: Alexander Drozdov <aleksandr.drozdov@corp.mail.ru>
Date: Sat, 19 Jun 2021 12:39:39 +0300
Subject: [PATCH 3/3] add new graphite parameters on-the-fly

---
src/ngx_http_lua_graphite.c | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/ngx_http_lua_graphite.c b/src/ngx_http_lua_graphite.c
index 142c6e9f..9c660ad1 100644
--- a/src/ngx_http_lua_graphite.c
+++ b/src/ngx_http_lua_graphite.c
@@ -62,10 +62,16 @@ ngx_http_lua_graphite(lua_State *L) {
return 0;
else {
ngx_str_t name;
+ ngx_str_t config, *pconfig = NULL;
+
name.data = (u_char*)lua_tolstring(L, 2, &name.len);
if (name.data == NULL)
return 0;
- ngx_http_graphite(r, &name, lua_tonumber(L, 3));
+ if (n >= 3) {
+ config.data = (u_char*)lua_tolstring(L, 4, &config.len);
+ pconfig = &config;
+ }
+ ngx_http_graphite(r, &name, lua_tonumber(L, 3), pconfig);
}

return 0;
@@ -75,8 +81,8 @@ static int
ngx_http_lua_graphite_param(lua_State *L) {

int n = lua_gettop(L);
- if (n != 1) {
- return luaL_error(L, "ngx.graphite.param expecting 1 argument got %d", n);
+ if (n != 1 && n != 2) {
+ return luaL_error(L, "ngx.graphite.param expecting 1 or 2 arguments, got %d", n);
}

ngx_http_request_t *r;
@@ -86,9 +92,14 @@ ngx_http_lua_graphite_param(lua_State *L) {
return luaL_error(L, "no request object found");
}
ngx_str_t name;
+ ngx_str_t config, *pconfig = NULL;
const ngx_http_graphite_link_t *link;
name.data = (u_char*)lua_tolstring(L, 1, &name.len);
- if (name.data == NULL || (link = ngx_http_graphite_link(r, &name)) == NULL) {
+ if (n >= 2) {
+ config.data = (u_char*)lua_tolstring(L, 2, &config.len);
+ pconfig = &config;
+ }
+ if (name.data == NULL || (link = ngx_http_graphite_link(r, &name, pconfig)) == NULL) {
lua_pushboolean(L, 0);
return 1;
}
--
2.25.1

5 changes: 3 additions & 2 deletions src/ngx_http_graphite_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ ngx_http_graphite_array_push(ngx_http_graphite_array_t *a) {
void *
ngx_http_graphite_array_push_n(ngx_http_graphite_array_t *array, ngx_uint_t n) {

if (array->nelts == array->nalloc) {
ngx_uint_t new_nelts = array->nelts + n;
if (new_nelts > array->nalloc) {

ngx_http_graphite_allocator_t *allocator = array->allocator;
ngx_uint_t nalloc = 2 * ((n >= array->nalloc) ? n : array->nalloc);
Expand All @@ -65,7 +66,7 @@ ngx_http_graphite_array_push_n(ngx_http_graphite_array_t *array, ngx_uint_t n) {
}

void *elt = (u_char*)array->elts + array->size * array->nelts;
array->nelts += n;
array->nelts = new_nelts;

return elt;
}
Expand Down
Loading

0 comments on commit 450ea38

Please sign in to comment.