You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@trafficserver.apache.org by 오재경 <ja...@nimbusnetworks.co.kr> on 2012/06/08 03:24:47 UTC

a plugin to specific domain. need helps.

hello. This is jay and it’s been 2 weeks since I started to work on
traffic server.

I’m working on a throttling plugin. can I assign the plugin to a specific
domain like remap plugin?

For example, a throttle plugin serves www.exampleA.com and another plugin
serves www.exampleB.com.

A throttling plugin originated from null-transform plugin works well. i
tried to implement a throttling in remap plugin but it doesn’t work.

I traced log files and there was a difference in ending. 

The ending of normal throttling plugin log file is…

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[Jun  6 11:30:26.318] Server {47016656885504} DEBUG: (http) [32]
[&HttpSM::tunnel_handler_transform_read, VC_EVENT_EOS]
[Jun  6 11:30:26.318] Server {47016656885504} DEBUG: (http_tunnel) [32]
consumer_handler [cache write t VC_EVENT_WRITE_COMPLETE]
[Jun  6 11:30:26.318] Server {47016656885504} DEBUG: (http) [32]
[&HttpSM::tunnel_handler_cache_write, VC_EVENT_WRITE_COMPLETE]
[Jun  6 11:30:26.318] Server {47016656885504} DIAG: (h264-transform) final
bitrate = [1426801]
[Jun  6 11:30:26.319] Server {47016657938176} DEBUG: (http_tunnel) [32]
consumer_handler [user agent VC_EVENT_WRITE_COMPLETE]
[Jun  6 11:30:26.319] Server {47016657938176} DEBUG: (http) [32]
[&HttpSM::tunnel_handler_ua, VC_EVENT_WRITE_COMPLETE]
[Jun  6 11:30:26.319] Server {47016657938176} DEBUG: (http_cs) [32] session
closed
[Jun  6 11:30:26.319] Server {47016657938176} DEBUG: (http_cs) [32] session
destroy
[Jun  6 11:30:26.319] Server {47016657938176} DEBUG: (http) [32]
[HttpSM::main_handler, HTTP_TUNNEL_EVENT_DONE]
[Jun  6 11:30:26.319] Server {47016657938176} DEBUG: (http) [32]
[&HttpSM::tunnel_handler, HTTP_TUNNEL_EVENT_DONE]
[Jun  6 11:30:26.319] Server {47016657938176} DEBUG: (http_redirect)
[HttpTunnel::deallocate_postdata_copy_buffers]
[Jun  6 11:30:26.319] Server {47016657938176} DEBUG: (http) [32] calling
plugin on hook TS_HTTP_TXN_CLOSE_HOOK at hook 0x1CDB260
[Jun  6 11:30:26.327] Server {47016657938176} DEBUG: (http) [32]
[&HttpSM::state_api_callback, HTTP_API_CONTINUE]
[Jun  6 11:30:26.327] Server {47016657938176} DEBUG: (http) [32]
[&HttpSM::state_api_callout, HTTP_API_CONTINUE]
[Jun  6 11:30:26.327] Server {47016657938176} DEBUG: (http_seq)
[HttpStateMachineGet::update_stats] Logging transaction
[Jun  6 11:30:26.327] Server {47016657938176} DEBUG: (http) [32]
dellocating sm
----------------------------------------------------------------------------
----------

I put the codes of throttling plugin into remap plugin but throttling in
remap plugin ends like this.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
[Jun  7 17:47:58.313] Server {48011842122016} DEBUG: (http_tunnel) [2]
producer_handler [transform read VC_EVENT_EOS]
[Jun  7 17:47:58.313] Server {48011842122016} DEBUG: (http_redirect)
[HttpTunnel::producer_handler] enable_redirection: [1 0 0] event: 104
[Jun  7 17:47:58.313] Server {48011842122016} DEBUG: (http) [2]
[&HttpSM::tunnel_handler_transform_read, VC_EVENT_EOS]
[Jun  7 17:47:58.313] Server {48011842122016} DEBUG: (http_tunnel) [2]
consumer_handler [cache write t VC_EVENT_WRITE_COMPLETE]
[Jun  7 17:47:58.313] Server {48011842122016} DEBUG: (http) [2]
[&HttpSM::tunnel_handler_cache_write, VC_EVENT_WRITE_COMPLETE]
[Jun  7 17:47:58.314] Server {48011850979072} DEBUG: (http_tunnel) [2]
consumer_handler [user agent VC_EVENT_WRITE_READY]
[Jun  7 17:47:58.314] Server {48011850979072} DEBUG: (http_tunnel) [2]
consumer_handler [user agent VC_EVENT_WRITE_READY]
[Jun  7 17:47:58.314] Server {48011850979072} DEBUG: (http_tunnel) [2]
consumer_handler [user agent VC_EVENT_WRITE_COMPLETE]
[Jun  7 17:47:58.314] Server {48011850979072} DEBUG: (http) [2]
[&HttpSM::tunnel_handler_ua, VC_EVENT_WRITE_COMPLETE]
[Jun  7 17:47:58.314] Server {48011850979072} DEBUG: (http_cs) [2] session
released by sm [2]         <------------------ where is session closed?
[Jun  7 17:47:58.314] Server {48011850979072} DEBUG: (http_cs) [2]
initiating io for next header
[Jun  7 17:47:58.314] Server {48011850979072} DEBUG: (http) [2]
[HttpSM::main_handler, HTTP_TUNNEL_EVENT_DONE]
[Jun  7 17:47:58.314] Server {48011850979072} DEBUG: (http) [2]
[&HttpSM::tunnel_handler, HTTP_TUNNEL_EVENT_DONE]
[Jun  7 17:47:58.314] Server {48011850979072} DEBUG: (http_redirect)
[HttpTunnel::deallocate_postdata_copy_buffers]
[Jun  7 17:47:58.314] Server {48011850979072} DEBUG: (http) [2] calling
plugin on hook TS_HTTP_TXN_CLOSE_HOOK at hook 0xA4CDD2E0
[Jun  7 17:47:58.324] Server {48011850979072} DEBUG: (http) [2]
[&HttpSM::state_api_callback, HTTP_API_CONTINUE]
[Jun  7 17:47:58.324] Server {48011850979072} DEBUG: (http) [2]
[&HttpSM::state_api_callout, HTTP_API_CONTINUE]
[Jun  7 17:47:58.324] Server {48011850979072} DEBUG: (http_seq)
[HttpStateMachineGet::update_stats] Logging transaction
[Jun  7 17:47:58.324] Server {48011850979072} DEBUG: (http) [2] dellocating
sm
----------------------------------------------------------------------------
-----------------------------------

if I was wrong let me know how I can make a plugin specific to a domain. 

Thanks and regards. 

RE: a plugin to specific domain. need helps.

Posted by 오재경 <ja...@nimbusnetworks.co.kr>.
Sorry. i missed "rules.h" sorry to bother you. 

I'll try it. Thanks.

-----Original Message-----
From: 오재경 [mailto:jaekyung.oh@nimbusnetworks.co.kr] 
Sent: Sunday, June 10, 2012 11:30 AM
To: 'Leif Hedstrom'; dev@trafficserver.apache.org
Subject: RE: a plugin to specific domain. need helps.

I've overviewed the source code and it seems I have to develop the plugin
in 3.1.4 or higher of traffic server.

A new global variable "Rules", I can't find it in 3.0.4 on which I'm
working.

Is it possible to develop a plugin which can do both a transform and a
remap on 3.0.4 without "Rules"?

or to Make a header-filter style plugin should I move to 3.1.4 or higher?

Thanks.


-----Original Message-----
From: Leif Hedstrom [mailto:zwoop@apache.org]
Sent: Friday, June 08, 2012 1:15 PM
To: dev@trafficserver.apache.org
Cc: 오재경
Subject: Re: a plugin to specific domain. need helps.

On 6/7/12 7:24 PM, 오재경 wrote:
> hello. This is jay and it’s been 2 weeks since I started to work on 
> traffic server.
>
> I’m working on a throttling plugin. can I assign the plugin to a 
> specific domain like remap plugin?
>
> For example, a throttle plugin serves www.exampleA.com and another 
> plugin serves www.exampleB.com.
>
>

The easiest is to make your plugin both a transform and a remap plugin.
For an example how to do that, look at the header_filter plugin. It is used
to basically "activate" a hook at a later stage, triggered by which
remap.config rule matched.

I think that's what you are asking to do ?

-- Leif


RE: a plugin to specific domain. need helps.

Posted by 오재경 <ja...@nimbusnetworks.co.kr>.
I've overviewed the source code and it seems I have to develop the plugin
in 3.1.4 or higher of traffic server.

A new global variable "Rules", I can't find it in 3.0.4 on which I'm
working.

Is it possible to develop a plugin which can do both a transform and a
remap on 3.0.4 without "Rules"?

or to Make a header-filter style plugin should I move to 3.1.4 or higher?

Thanks.


-----Original Message-----
From: Leif Hedstrom [mailto:zwoop@apache.org] 
Sent: Friday, June 08, 2012 1:15 PM
To: dev@trafficserver.apache.org
Cc: 오재경
Subject: Re: a plugin to specific domain. need helps.

On 6/7/12 7:24 PM, 오재경 wrote:
> hello. This is jay and it’s been 2 weeks since I started to work on 
> traffic server.
>
> I’m working on a throttling plugin. can I assign the plugin to a 
> specific domain like remap plugin?
>
> For example, a throttle plugin serves www.exampleA.com and another 
> plugin serves www.exampleB.com.
>
>

The easiest is to make your plugin both a transform and a remap plugin.
For an example how to do that, look at the header_filter plugin. It is used
to basically "activate" a hook at a later stage, triggered by which
remap.config rule matched.

I think that's what you are asking to do ?

-- Leif


RE: a plugin to specific domain. need helps.

Posted by 오재경 <ja...@nimbusnetworks.co.kr>.
Thank you. I'll try it.

-----Original Message-----
From: Leif Hedstrom [mailto:zwoop@apache.org] 
Sent: Friday, June 08, 2012 1:15 PM
To: dev@trafficserver.apache.org
Cc: 오재경
Subject: Re: a plugin to specific domain. need helps.

On 6/7/12 7:24 PM, 오재경 wrote:
> hello. This is jay and it’s been 2 weeks since I started to work on 
> traffic server.
>
> I’m working on a throttling plugin. can I assign the plugin to a 
> specific domain like remap plugin?
>
> For example, a throttle plugin serves www.exampleA.com and another 
> plugin serves www.exampleB.com.
>
>

The easiest is to make your plugin both a transform and a remap plugin.
For an example how to do that, look at the header_filter plugin. It is used
to basically "activate" a hook at a later stage, triggered by which
remap.config rule matched.

I think that's what you are asking to do ?

-- Leif


RE: a plugin to specific domain. need helps.

Posted by 오재경 <ja...@nimbusnetworks.co.kr>.
Thank you so much. I'll take a code review more carefully today and make a
plugin as you guided.

-----Original Message-----
From: Leif Hedstrom [mailto:zwoop@apache.org] 
Sent: Monday, June 11, 2012 12:16 PM
To: dev@trafficserver.apache.org
Cc: 오재경
Subject: Re: a plugin to specific domain. need helps.

On 6/10/12 9:03 PM, Leif Hedstrom wrote:
> Not sure how else to explain this. -- leif

If it still doesn't help, maybe hop on IRC tomorrow and we can walk through
the header_filter plugin, and I'll show you how to do it using remap.config
rules.

ALso, you always have the option to implement your own "rules" for your
hooks. I.e. there's nothing preventing your from making your own config
file, telling the plugin when, and when not, to create the transform hook.
Using remap.config and the remap plugin "pattern" makes it easier though,
since you can use already existing configs / tools.

-- Leif

This would be your entire remap plugin:

TSRemapStatus
TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo *rri) {
TSHttpTxnArgSet(rh, arg_idx, static_cast<void*>1); // Tell a later hook to
create the transform return TSREMAP_NO_REMAP; }


In the hook, before creating the transform, you do e.g.

if (1 == static_cast<int>(TSHttpTxnArgGet(txnp, arg_idx))) { // create the
transform ...
} else { // just reenable the transaction, and do nothing }


arg_ix is a global in this case, registered when your plugin is first
loaded, e.g.

TSHttpArgIndexReserve(PLUGIN_NAME, "Decide if the transform should be
created or not", &arg_idx);


Re: a plugin to specific domain. need helps.

Posted by Leif Hedstrom <zw...@apache.org>.
On 6/10/12 9:03 PM, Leif Hedstrom wrote:
> Not sure how else to explain this. -- leif 

If it still doesn't help, maybe hop on IRC tomorrow and we can walk through
the header_filter plugin, and I'll show you how to do it using remap.config
rules.

ALso, you always have the option to implement your own "rules" for your
hooks. I.e. there's nothing preventing your from making your own config
file, telling the plugin when, and when not, to create the transform hook.
Using remap.config and the remap plugin "pattern" makes it easier though,
since you can use already existing configs / tools.

-- Leif

This would be your entire remap plugin:

TSRemapStatus
TSRemapDoRemap(void* ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
{
TSHttpTxnArgSet(rh, arg_idx, static_cast<void*>1); // Tell a later hook to
create the transform
return TSREMAP_NO_REMAP;
}


In the hook, before creating the transform, you do e.g.

if (1 == static_cast<int>(TSHttpTxnArgGet(txnp, arg_idx))) {
// create the transform
...
} else { // just reenable the transaction, and do nothing }


arg_ix is a global in this case, registered when your plugin is first
loaded, e.g.

TSHttpArgIndexReserve(PLUGIN_NAME, "Decide if the transform should be
created or not", &arg_idx);


RE: a plugin to specific domain. need helps.

Posted by 오재경 <ja...@nimbusnetworks.co.kr>.
Thank you so much. After all i've got what I want.

-----Original Message-----
From: Leif Hedstrom [mailto:zwoop@apache.org] 
Sent: Monday, June 11, 2012 12:04 PM
To: dev@trafficserver.apache.org
Cc: 오재경
Subject: Re: a plugin to specific domain. need helps.

On 6/10/12 8:53 PM, 오재경 wrote:
> Well.....What I want to do is to make a transform plugin only for a 
> specific domain(or specified url) and I think I can't make that 
> through TrafficServer SDK.
>
> TrafficServer seems to have two types of plugins, the one is remap 
> type and the other one is transform type. remap type plugin can do 
> something for a specific domain(or specified url) while transform 
> plugin can't be configured to be called only for a domain.
>
> For example, I'd like to make a throttling plugin to be called only 
> for the request "http://exampleA.com/mp4/big.mp4" but I don't  want it 
> to be called for the request "http://exampleA.com/normal/small.htm"


You can combine two into one plugin. You make a remap plugin that the only
thing it does it to tell the transform plugin that it should be activated
or not. Just like the header_filter plugin does.

So, what you do is e.g.

map http://exampleA.com http://origin.exampleA.com @plugin=your_plugin.so

your_plugin.so implements both the remap plugin, and creates a transform
hook. In plugins.config, you also add your_plugin.so. When the remap plugin
triggers, you set a transaction specific state, telling the READ_RESPONSE
header hook to create the transform or not (using TSHttpTxnArgSet() and
Get()).

I did not tell you to try the header_filter plugin, i said to look how it
implements this exact behavior. Look at it more carefully, and you will see
that it's both a remap plugin (activated via remap.config) and a normal
plugin (activated via plugins.config).

You can not use the TSContCreate etc. APIs in the remap plugin. Again, what
you should do is tell your other global hook plugins if they should do
something or not, just like header_filter does.

Not sure how else to explain this.

-- leif


Re: a plugin to specific domain. need helps.

Posted by Leif Hedstrom <zw...@apache.org>.
On 6/10/12 8:53 PM, 오재경 wrote:
> Well.....What I want to do is to make a transform plugin only for a
> specific domain(or specified url) and I think I can't make that through
> TrafficServer SDK.
>
> TrafficServer seems to have two types of plugins, the one is remap type and
> the other one is transform type. remap type plugin can do something for a
> specific domain(or specified url) while transform plugin can't be
> configured to be called only for a domain.
>
> For example, I'd like to make a throttling plugin to be called only for the
> request "http://exampleA.com/mp4/big.mp4" but I don't  want it to be called
> for the request "http://exampleA.com/normal/small.htm"


You can combine two into one plugin. You make a remap plugin that the only
thing it does it to tell the transform plugin that it should be activated or
not. Just like the header_filter plugin does.

So, what you do is e.g.

map http://exampleA.com http://origin.exampleA.com @plugin=your_plugin.so

your_plugin.so implements both the remap plugin, and creates a transform
hook. In plugins.config, you also add your_plugin.so. When the remap plugin
triggers, you set a transaction specific state, telling the READ_RESPONSE
header hook to create the transform or not (using TSHttpTxnArgSet() and Get()).

I did not tell you to try the header_filter plugin, i said to look how it
implements this exact behavior. Look at it more carefully, and you will see
that it's both a remap plugin (activated via remap.config) and a normal
plugin (activated via plugins.config).

You can not use the TSContCreate etc. APIs in the remap plugin. Again, what
you should do is tell your other global hook plugins if they should do
something or not, just like header_filter does.

Not sure how else to explain this.

-- leif

RE: a plugin to specific domain. need helps.

Posted by 오재경 <ja...@nimbusnetworks.co.kr>.
Well.....What I want to do is to make a transform plugin only for a
specific domain(or specified url) and I think I can't make that through
TrafficServer SDK.

TrafficServer seems to have two types of plugins, the one is remap type and
the other one is transform type. remap type plugin can do something for a
specific domain(or specified url) while transform plugin can't be
configured to be called only for a domain.

For example, I'd like to make a throttling plugin to be called only for the
request "http://exampleA.com/mp4/big.mp4" but I don't  want it to be called
for the request "http://exampleA.com/normal/small.htm"


I made a throttling plugin and it works well. but the problem is it is
called every http transaction. So I thought simply like this : 

why not put "TSHttpHookAdd(TS_HTTP_READ_RESPONSE_HDR_HOOK(or
TS_EVENT_HTTP_TXN_START), TSContCreate(transform_plugin, NULL));" into
TSRemapNewInstance() instead of TSPluginInit()?

At first it looked effective but I detected the http session never gets
stop. I think TrafficServer loses the control of flow if somebody calls
TSContCreate() in TSRemapNewInstance(). That's why the http session never
stops...

Leif Hedstrom advised me to try header-filter plugin but it looks same to
remap plugin intrinsically...

Am I wrong?

Thank you.


-----Original Message-----
From: Nick Kew [mailto:niq@apache.org] 
Sent: Sunday, June 10, 2012 7:02 PM
To: dev@trafficserver.apache.org
Subject: Re: a plugin to specific domain. need helps.


On 10 Jun 2012, at 04:43, 오재경 wrote:

> before I try it let ask you a question.
> 
> Isn't it allowed to use TS_HTTP_TXN_START_HOOK in header_filter 
> plugin? why does it HookAdd from TS_HTTP_READ_REQUEST_HDR_HOOK?

Depends what you want to do.  If you want to work with the data (as in
either a remap or a filter), you don't yet have them in a TXN_START
function.

--
Nick Kew


Re: a plugin to specific domain. need helps.

Posted by Nick Kew <ni...@apache.org>.
On 10 Jun 2012, at 04:43, 오재경 wrote:

> before I try it let ask you a question.
> 
> Isn't it allowed to use TS_HTTP_TXN_START_HOOK in header_filter plugin? why
> does it HookAdd from TS_HTTP_READ_REQUEST_HDR_HOOK?

Depends what you want to do.  If you want to work with the data (as in either a
remap or a filter), you don't yet have them in a TXN_START function.

-- 
Nick Kew

RE: a plugin to specific domain. need helps.

Posted by 오재경 <ja...@nimbusnetworks.co.kr>.
before I try it let ask you a question.

Isn't it allowed to use TS_HTTP_TXN_START_HOOK in header_filter plugin? why
does it HookAdd from TS_HTTP_READ_REQUEST_HDR_HOOK?

Thanks.

-----Original Message-----
From: Leif Hedstrom [mailto:zwoop@apache.org] 
Sent: Friday, June 08, 2012 1:15 PM
To: dev@trafficserver.apache.org
Cc: 오재경
Subject: Re: a plugin to specific domain. need helps.

On 6/7/12 7:24 PM, 오재경 wrote:
> hello. This is jay and it’s been 2 weeks since I started to work on 
> traffic server.
>
> I’m working on a throttling plugin. can I assign the plugin to a 
> specific domain like remap plugin?
>
> For example, a throttle plugin serves www.exampleA.com and another 
> plugin serves www.exampleB.com.
>
>

The easiest is to make your plugin both a transform and a remap plugin.
For an example how to do that, look at the header_filter plugin. It is used
to basically "activate" a hook at a later stage, triggered by which
remap.config rule matched.

I think that's what you are asking to do ?

-- Leif


Re: a plugin to specific domain. need helps.

Posted by Leif Hedstrom <zw...@apache.org>.
On 6/7/12 7:24 PM, 오재경 wrote:
> hello. This is jay and it’s been 2 weeks since I started to work on
> traffic server.
>
> I’m working on a throttling plugin. can I assign the plugin to a specific
> domain like remap plugin?
>
> For example, a throttle plugin serves www.exampleA.com and another plugin
> serves www.exampleB.com.
>
>

The easiest is to make your plugin both a transform and a remap plugin.
For an example how to do that, look at the header_filter plugin. It is
used to basically "activate" a hook at a later stage, triggered by which
remap.config rule matched.

I think that's what you are asking to do ?

-- Leif