mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 22:01:31 +02:00
MEDIUM: stream: Make the unique_id
member of struct stream
a struct ist
The `unique_id` member of `struct stream` now is a `struct ist`.
This commit is contained in:
parent
0643b0e7e6
commit
a17e66289c
@ -66,7 +66,7 @@ void stream_shutdown(struct stream *stream, int why);
|
||||
void stream_dump(struct buffer *buf, const struct stream *s, const char *pfx, char eol);
|
||||
void stream_dump_and_crash(enum obj_type *obj, int rate);
|
||||
|
||||
int stream_generate_unique_id(struct stream *strm, struct list *format);
|
||||
struct ist stream_generate_unique_id(struct stream *strm, struct list *format);
|
||||
|
||||
void stream_process_counters(struct stream *s);
|
||||
void sess_change_server(struct stream *sess, struct server *newsrv);
|
||||
|
@ -177,7 +177,7 @@ struct stream {
|
||||
int pcli_next_pid; /* next target PID to use for the CLI proxy */
|
||||
int pcli_flags; /* flags for CLI proxy */
|
||||
|
||||
char *unique_id; /* custom unique ID */
|
||||
struct ist unique_id; /* custom unique ID */
|
||||
|
||||
/* These two pointers are used to resume the execution of the rule lists. */
|
||||
struct list *current_rule_list; /* this is used to store the current executed rule list. */
|
||||
|
@ -793,9 +793,9 @@ int http_process_request(struct stream *s, struct channel *req, int an_bit)
|
||||
* fetches only available in the HTTP request processing stage.
|
||||
*/
|
||||
if (!LIST_ISEMPTY(&sess->fe->format_unique_id)) {
|
||||
int length;
|
||||
struct ist unique_id = stream_generate_unique_id(s, &sess->fe->format_unique_id);
|
||||
|
||||
if ((length = stream_generate_unique_id(s, &sess->fe->format_unique_id)) < 0) {
|
||||
if (!isttest(unique_id)) {
|
||||
if (!(s->flags & SF_ERR_MASK))
|
||||
s->flags |= SF_ERR_RESOURCE;
|
||||
goto return_int_err;
|
||||
@ -803,7 +803,7 @@ int http_process_request(struct stream *s, struct channel *req, int an_bit)
|
||||
|
||||
/* send unique ID if a "unique-id-header" is defined */
|
||||
if (isttest(sess->fe->header_unique_id) &&
|
||||
!http_add_header(htx, sess->fe->header_unique_id, ist2(s->unique_id, length)))
|
||||
unlikely(!http_add_header(htx, sess->fe->header_unique_id, s->unique_id)))
|
||||
goto return_int_err;
|
||||
}
|
||||
|
||||
@ -5078,9 +5078,9 @@ void http_end_txn(struct stream *s)
|
||||
pool_free(pool_head_requri, txn->uri);
|
||||
pool_free(pool_head_capture, txn->cli_cookie);
|
||||
pool_free(pool_head_capture, txn->srv_cookie);
|
||||
pool_free(pool_head_uniqueid, s->unique_id);
|
||||
pool_free(pool_head_uniqueid, s->unique_id.ptr);
|
||||
|
||||
s->unique_id = NULL;
|
||||
s->unique_id = IST_NULL;
|
||||
txn->uri = NULL;
|
||||
txn->srv_cookie = NULL;
|
||||
txn->cli_cookie = NULL;
|
||||
|
@ -409,17 +409,17 @@ static int smp_fetch_stcode(const struct arg *args, struct sample *smp, const ch
|
||||
|
||||
static int smp_fetch_uniqueid(const struct arg *args, struct sample *smp, const char *kw, void *private)
|
||||
{
|
||||
int length;
|
||||
struct ist unique_id;
|
||||
|
||||
if (LIST_ISEMPTY(&smp->sess->fe->format_unique_id))
|
||||
return 0;
|
||||
|
||||
length = stream_generate_unique_id(smp->strm, &smp->sess->fe->format_unique_id);
|
||||
if (length < 0)
|
||||
unique_id = stream_generate_unique_id(smp->strm, &smp->sess->fe->format_unique_id);
|
||||
if (!isttest(unique_id))
|
||||
return 0;
|
||||
|
||||
smp->data.u.str.area = smp->strm->unique_id;
|
||||
smp->data.u.str.data = length;
|
||||
smp->data.u.str.area = smp->strm->unique_id.ptr;
|
||||
smp->data.u.str.data = smp->strm->unique_id.len;
|
||||
smp->data.type = SMP_T_STR;
|
||||
smp->flags = SMP_F_CONST;
|
||||
return 1;
|
||||
|
@ -2927,8 +2927,10 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
|
||||
|
||||
case LOG_FMT_UNIQUEID: // %ID
|
||||
ret = NULL;
|
||||
src = s ? s->unique_id : NULL;
|
||||
ret = lf_text(tmplog, src, maxsize - (tmplog - dst), tmp);
|
||||
if (s)
|
||||
ret = lf_text_len(tmplog, s->unique_id.ptr, s->unique_id.len, maxsize - (tmplog - dst), tmp);
|
||||
else
|
||||
ret = lf_text_len(tmplog, NULL, 0, maxsize - (tmplog - dst), tmp);
|
||||
if (ret == NULL)
|
||||
goto out;
|
||||
tmplog = ret;
|
||||
@ -2982,7 +2984,7 @@ void strm_log(struct stream *s)
|
||||
}
|
||||
|
||||
/* if unique-id was not generated */
|
||||
if (!s->unique_id && !LIST_ISEMPTY(&sess->fe->format_unique_id)) {
|
||||
if (!isttest(s->unique_id) && !LIST_ISEMPTY(&sess->fe->format_unique_id)) {
|
||||
stream_generate_unique_id(s, &sess->fe->format_unique_id);
|
||||
}
|
||||
|
||||
|
35
src/stream.c
35
src/stream.c
@ -170,8 +170,10 @@ static void strm_trace(enum trace_level level, uint64_t mask, const struct trace
|
||||
/* General info about the stream (htx/tcp, id...) */
|
||||
chunk_appendf(&trace_buf, " : [%u,%s]",
|
||||
s->uniq_id, ((s->flags & SF_HTX) ? "HTX" : "TCP"));
|
||||
if (s->unique_id)
|
||||
chunk_appendf(&trace_buf, " id=%s", s->unique_id);
|
||||
if (isttest(s->unique_id)) {
|
||||
chunk_appendf(&trace_buf, " id=");
|
||||
b_putist(&trace_buf, s->unique_id);
|
||||
}
|
||||
|
||||
/* Front and back stream-int state */
|
||||
chunk_appendf(&trace_buf, " SI=(%s,%s)",
|
||||
@ -399,7 +401,7 @@ struct stream *stream_new(struct session *sess, enum obj_type *origin)
|
||||
s->call_rate.curr_sec = s->call_rate.curr_ctr = s->call_rate.prev_ctr = 0;
|
||||
s->pcli_next_pid = 0;
|
||||
s->pcli_flags = 0;
|
||||
s->unique_id = NULL;
|
||||
s->unique_id = IST_NULL;
|
||||
|
||||
if ((t = task_new(tid_bit)) == NULL)
|
||||
goto out_fail_alloc;
|
||||
@ -605,8 +607,8 @@ static void stream_free(struct stream *s)
|
||||
offer_buffers(NULL, tasks_run_queue);
|
||||
}
|
||||
|
||||
pool_free(pool_head_uniqueid, s->unique_id);
|
||||
s->unique_id = NULL;
|
||||
pool_free(pool_head_uniqueid, s->unique_id.ptr);
|
||||
s->unique_id = IST_NULL;
|
||||
|
||||
hlua_ctx_destroy(s->hlua);
|
||||
s->hlua = NULL;
|
||||
@ -2663,25 +2665,28 @@ void stream_dump_and_crash(enum obj_type *obj, int rate)
|
||||
}
|
||||
|
||||
/* Generates a unique ID based on the given <format>, stores it in the given <strm> and
|
||||
* returns the length of the ID. -1 is returned on memory allocation failure.
|
||||
* returns the unique ID.
|
||||
|
||||
* If this function fails to allocate memory IST_NULL is returned.
|
||||
*
|
||||
* If an ID is already stored within the stream nothing happens and length of the stored
|
||||
* ID is returned.
|
||||
* If an ID is already stored within the stream nothing happens existing unique ID is
|
||||
* returned.
|
||||
*/
|
||||
int stream_generate_unique_id(struct stream *strm, struct list *format)
|
||||
struct ist stream_generate_unique_id(struct stream *strm, struct list *format)
|
||||
{
|
||||
if (strm->unique_id != NULL) {
|
||||
return strlen(strm->unique_id);
|
||||
if (isttest(strm->unique_id)) {
|
||||
return strm->unique_id;
|
||||
}
|
||||
else {
|
||||
char *unique_id;
|
||||
int length;
|
||||
if ((unique_id = pool_alloc(pool_head_uniqueid)) == NULL)
|
||||
return -1;
|
||||
return IST_NULL;
|
||||
|
||||
strm->unique_id = unique_id;
|
||||
strm->unique_id[0] = 0;
|
||||
length = build_logline(strm, unique_id, UNIQUEID_LEN, format);
|
||||
strm->unique_id = ist2(unique_id, length);
|
||||
|
||||
return build_logline(strm, strm->unique_id, UNIQUEID_LEN, format);
|
||||
return strm->unique_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user