Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added unit section to status endpoint #928 #1089

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
2cb99ca
Add unit section to status endpoint
Pavlusha311245 Jan 25, 2024
6452ca1
Node.js: fixed "httpVersion" variable format
andrey-zelenkov Jan 25, 2024
37abe2e
HTTP: refactored out nxt_http_request_access_log().
hongzhidao Jan 23, 2024
4c91beb
HTTP: enhanced access log with conditional filtering.
hongzhidao Jan 23, 2024
dcbff27
Docs: Update changes.xml for conditional access logging
hongzhidao Jan 29, 2024
ad36450
Tests: "if" option in access logging.
andrey-zelenkov Jan 24, 2024
9919b50
Isolation: Add a new nxt_cred_t type
ac000 Jan 24, 2024
f7c9d3a
Isolation: Use an appropriate type for storing uid/gids
ac000 Jan 24, 2024
eba7378
Configuration: Use the NXT_CONF_VLDT_REQUIRED flag for procmap
ac000 Jan 24, 2024
990fbe7
Configuration: Remove procmap validation code
ac000 Jan 24, 2024
ecd5739
Configuration: Add nxt_conf_get_string_dup()
alejandro-colomar Feb 2, 2024
bb376c6
Simplify, by calling nxt_conf_get_string_dup()
alejandro-colomar Feb 2, 2024
46cef09
Configuration: Don't corrupt abstract socket names
alejandro-colomar Jan 31, 2024
9e98670
Configuration: Fix validation of "processes"
alejandro-colomar Feb 8, 2024
3a2687b
Packages: added Ubuntu 23.10 "mantic" support.
thresheek Oct 17, 2023
8ebe04f
contrib: Bump libunit-wasm to 0.3.0.
thresheek Oct 21, 2023
ca1bc06
contrib: updated njs to 0.8.2.
thresheek Oct 25, 2023
bad2c18
Packages: Added Fedora 39 support.
thresheek Nov 18, 2023
385df6d
Add unit section to status endpoint
Pavlusha311245 Jan 25, 2024
8efac48
Merge remote-tracking branch 'fork/feature/unit_about_section' into f…
Pavlusha311245 Oct 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/nxt_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
#include <nxt_conf.h>
#include <nxt_status.h>
#include <nxt_cert.h>
#include <nxt_script.h>


typedef struct {
nxt_conf_value_t *root;
Expand Down Expand Up @@ -1633,7 +1631,7 @@ nxt_controller_status_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg,
req = data;

if (msg->port_msg.type == NXT_PORT_MSG_RPC_READY) {
status = nxt_status_get((nxt_status_report_t *) msg->buf->mem.pos,
status = nxt_status_get(task, (nxt_status_report_t *) msg->buf->mem.pos,
req->conn->mem_pool);
} else {
status = NULL;
Expand Down Expand Up @@ -2432,6 +2430,9 @@ nxt_controller_conf_store(nxt_task_t *task, nxt_conf_value_t *conf)
nxt_buf_t *b;
nxt_port_t *main_port;
nxt_runtime_t *rt;
time_t rawtime;
u_char buffer[25];
struct tm *timeinfo;

rt = task->thread->runtime;

Expand Down Expand Up @@ -2466,6 +2467,17 @@ nxt_controller_conf_store(nxt_task_t *task, nxt_conf_value_t *conf)
NXT_PORT_MSG_CONF_STORE | NXT_PORT_MSG_CLOSE_FD,
fd, 0, -1, b);

rt->conf_gen++;

time(&rawtime);
timeinfo = gmtime(&rawtime); //convert to UTC
strftime((char*)buffer, 25, "%Y-%m-%dT%H:%M:%S.000Z", timeinfo);

rt->conf_ltime.length = nxt_strlen(buffer);
rt->conf_ltime.start = nxt_malloc(rt->conf_ltime.length + 1);

nxt_cpystr(rt->conf_ltime.start, buffer);

return;

fail:
Expand Down
13 changes: 13 additions & 0 deletions src/nxt_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,9 @@ nxt_runtime_conf_init(nxt_task_t *task, nxt_runtime_t *rt)
nxt_sockaddr_t *sa;
nxt_file_name_str_t file_name;
const nxt_event_interface_t *interface;
time_t rawtime;
u_char buffer[25];
struct tm *timeinfo;

rt->daemon = 1;
rt->engine_connections = 256;
Expand All @@ -789,6 +792,16 @@ nxt_runtime_conf_init(nxt_task_t *task, nxt_runtime_t *rt)
rt->state = NXT_STATEDIR;
rt->control = NXT_CONTROL_SOCK;
rt->tmp = NXT_TMPDIR;
rt->conf_gen = 0;

time(&rawtime);
timeinfo = gmtime(&rawtime); //convert to UTC
strftime((char*)buffer, 25, "%Y-%m-%dT%H:%M:%S.000Z", timeinfo);

rt->conf_ltime.length = nxt_strlen(buffer);
rt->conf_ltime.start = nxt_malloc(rt->conf_ltime.length + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for changing the malloc(3), but now my next question is, where does this memory get free(3)'d?.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know when memory should be released. Can you explain me?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually use nxt_mp_xxx api instead that you don't need to explicitly do memory free.
It will be released together with the mp destroy.


nxt_cpystr(rt->conf_ltime.start, buffer);

nxt_memzero(&rt->capabilities, sizeof(nxt_capabilities_t));

Expand Down
3 changes: 3 additions & 0 deletions src/nxt_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ struct nxt_runtime_s {
const char *control;
const char *tmp;

nxt_int_t conf_gen;
nxt_str_t conf_ltime;
Comment on lines +76 to +77
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Pavlusha311245

There is a nxt_status_report_t structure in src/nxt_status.h. I wonder if these would be better placed there?

Copy link
Author

@Pavlusha311245 Pavlusha311245 Mar 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Pavlusha311245

There is a nxt_status_report_t structure in src/nxt_status.h. I wonder if these would be better placed there?

Hmm... I can try 🙂 But I thought of leaving them in runtime so that I could use them anywhere else. Also I need it here to known time when config initialized. Have you suggestion how I can do it? @ac000

Copy link
Contributor

@hongzhidao hongzhidao Mar 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems they don't belong to nxt_runtime_t and nxt_status_report_t.
The nxt_status_report_t is a temporary structure to collect the status information from every engine between worker threads in the router process.
The configuration generation needs to increase when a new configuration is generated. But I can't see where it happens in the PR. The configuration time needs to be recorded on its corresponding configuration.
I feel you need to handle them first.
No clear idea on it yet, but you might start with nxt_router_conf_data_handler() which generates configuration structure through control API.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configuration generation needs to increase when a new configuration is generated. But I can't see where it happens in the PR. The configuration time needs to be recorded on its corresponding configuration. I feel you need to handle them first.

The update of the counter and time is now located in nxt_controller in thenxt_controller_conf_store() method

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configuration is updated by the control API which is created in the controller process.
I feel it has nothing to do with the structure nxt_runtime_t.
When a new configuration is applied, the last JSON value is stored as nxt_controller_conf.
We could consider putting the generation and updated time in this structure nxt_controller_conf_t.
Btw, debug information in error.log is useful.


nxt_str_t certs;
nxt_str_t scripts;

Expand Down
32 changes: 26 additions & 6 deletions src/nxt_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@


nxt_conf_value_t *
nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp)
nxt_status_get(nxt_task_t *task, nxt_status_report_t *report, nxt_mp_t *mp)
{
size_t i;
nxt_str_t name;
nxt_runtime_t *rt;
nxt_int_t ret;
nxt_str_t name;
nxt_status_app_t *app;
nxt_str_t version;
nxt_conf_value_t *status, *obj, *apps, *app_obj;

static nxt_str_t unit_str = nxt_string("unit");
static nxt_str_t ver_str = nxt_string("version");
static nxt_str_t gen_str = nxt_string("generation");
static nxt_str_t lconf_str = nxt_string("last_configured");
static nxt_str_t conns_str = nxt_string("connections");
static nxt_str_t acc_str = nxt_string("accepted");
static nxt_str_t active_str = nxt_string("active");
Expand All @@ -29,17 +35,31 @@ nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp)
static nxt_str_t run_str = nxt_string("running");
static nxt_str_t start_str = nxt_string("starting");

status = nxt_conf_create_object(mp, 3);
rt = task->thread->runtime;

status = nxt_conf_create_object(mp, 4);
if (nxt_slow_path(status == NULL)) {
return NULL;
}

obj = nxt_conf_create_object(mp, 3);
if (nxt_slow_path(obj == NULL)) {
return NULL;
}

nxt_conf_set_member(status, &unit_str, obj, 0);

nxt_str_set(&version, NXT_VERSION);
nxt_conf_set_member_string(obj, &ver_str, &version, 0);
nxt_conf_set_member_string(obj, &lconf_str, &rt->conf_ltime, 1);
nxt_conf_set_member_integer(obj, &gen_str, rt->conf_gen, 2);

obj = nxt_conf_create_object(mp, 4);
if (nxt_slow_path(obj == NULL)) {
return NULL;
}

nxt_conf_set_member(status, &conns_str, obj, 0);
nxt_conf_set_member(status, &conns_str, obj, 1);

nxt_conf_set_member_integer(obj, &acc_str, report->accepted_conns, 0);
nxt_conf_set_member_integer(obj, &active_str, report->accepted_conns
Expand All @@ -53,7 +73,7 @@ nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp)
return NULL;
}

nxt_conf_set_member(status, &reqs_str, obj, 1);
nxt_conf_set_member(status, &reqs_str, obj, 2);

nxt_conf_set_member_integer(obj, &total_str, report->requests, 0);

Expand All @@ -62,7 +82,7 @@ nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp)
return NULL;
}

nxt_conf_set_member(status, &apps_str, apps, 2);
nxt_conf_set_member(status, &apps_str, apps, 3);

for (i = 0; i < report->apps_count; i++) {
app = &report->apps[i];
Expand Down
2 changes: 1 addition & 1 deletion src/nxt_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ typedef struct {
} nxt_status_report_t;


nxt_conf_value_t *nxt_status_get(nxt_status_report_t *report, nxt_mp_t *mp);
nxt_conf_value_t *nxt_status_get(nxt_task_t *task, nxt_status_report_t *report, nxt_mp_t *mp);


#endif /* _NXT_STATUS_H_INCLUDED_ */