Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
eeliu committed Oct 16, 2024
1 parent 68476eb commit 7015b2c
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 4 deletions.
Binary file added testapps/libevent_http_server/image-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added testapps/libevent_http_server/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 18 additions & 2 deletions testapps/libevent_http_server/pp_ev_http.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright 2020 NAVER Corp
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
////////////////////////////////////////////////////////////////////////////////

#include "pp_ev_http.h"
#include "event2/http.h"
#include <malloc.h>
Expand Down Expand Up @@ -158,8 +174,6 @@ static int pp_evhttp_make_request(struct evhttp_connection *evcon,
req->cb = pp_sub_request_done;
req->cb_arg = ctx;

// todo add pinpoint-header

struct evkeyvalq *output_headers;
output_headers = evhttp_request_get_output_headers(req);

Expand Down Expand Up @@ -318,3 +332,5 @@ void pp_free_http_client(pp_http_client_t *client) {
free(client);
}
}

//@author eeliu
18 changes: 17 additions & 1 deletion testapps/libevent_http_server/pp_ev_http.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
#pragma once

////////////////////////////////////////////////////////////////////////////////
// Copyright 2020 NAVER Corp
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy
// of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
////////////////////////////////////////////////////////////////////////////////
#include <event2/buffer.h>
#include <event2/bufferevent.h>
#include <event2/event.h>
Expand Down Expand Up @@ -97,3 +111,5 @@ void pinpoint_set_agent_helper(const char *app_name, const char *app_id,
pinpoint_end_trace(node); \
} \
}

//@author eeliu
93 changes: 92 additions & 1 deletion testapps/libevent_http_server/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Command

```
$ mkdir build && cd build && make -j
$ mkdir build && cd build && cmake .. && make -j
$ # curl http://localhost:8080/http-client
```

### Thanks
Expand All @@ -21,3 +22,93 @@ $ mkdir build && cd build && make -j
![call stack ](call_stack.png)

## Introduction for pinpoint on asynchronous framework

> what's problem in asynchronous framework (event driver)?
In synchronous, we gets trace by it's called order, that is the logical order when handling request, but in asynchronous framework, trace are driven by event, it's the event order. So, we must find a way to recover the logical order.

### Synchronous call flow

![alt text](image.png)

### Asynchronous call flow

> Red line: user A logical flow \
Blue line: user B logical flow

![alt text](image-1.png)

Here is the question, how to separate A and B from mixed call chains ?

>Inspired by nginx
Pass `ctx` to everywhere

```c
#define CTX_MATIC_NUM 0x1357325l
typedef struct {
int magic_num_;
NodeID current_id_; // current trace ID
void *ori_arg_;
void (*on_complete_cb_origin_)(struct evhttp_request *, void *);
void *on_complete_cb_arg_origin_;

void (*http_client_request_cb_)(struct evhttp_request *, void *);
void *http_client_request_done_cb_arg_;
...
} pp_request_context_t;
```
If you want to trace `foo` function,
1. add `ctx` into parameter list
|Old | Now|
|----|----|
|void foo(int a, ...)| void foo(void* ctx, int a,...)|
2. wrapper `foo` function
```c
void foo(void *ctx,int a, ...);
void pp_foo(void *ctx,int a, ...){
...
NodeID trace_id = pinpoint_start_trace(ctx_.current_id_);
foo(ctx,a);
// end current trace and update current_id_
ctx_.current_id_ = pinpoint_end_trace(trace_id);
}
...
call_pp_foo();
...
```

3. what if needs to register a callback function?

Before
```
// some like
async_http_request(.. request_done_call_cb,request_done_call_cb_arg...);
```
Now
```
cxt->origin_request_done_call_cb = request_done_call_cb;
ctx->origin_request_done_call_cb_arg = request_done_call_cb_arg
int pp_request_done_call_cb(arg){
cxt->origin_request_done_call_cb(ctx->origin_request_done_call_cb_arg);
};
async_http_request(ctx,.. pp_request_done_call_cb,ctx,...);
```

While, there are many unknown cases in below list. If you have any question, [create an issue 🙋‍♂️ ](https://github.com/pinpoint-apm/pinpoint-c-agent/issues/new).






0 comments on commit 7015b2c

Please sign in to comment.