Giter VIP home page Giter VIP logo

ts_mruby's Introduction

ts_mruby

Build Status Coverage Status

Enchant Apache Traffic Server with mruby power.

what's ts_mruby?

ts_mruby is an Apache Traffic Server plugin that provides more flexible and extensible server configuration. You can write the configuration by mruby, and use mrbgems modules. ... And maybe the plugin support common syntax as part of the mod_mruby and ngx_mruby.

See Wiki for more documents.

Requirements

  • C++11

  • Apache Traffic Server >= 4.2.x with atscppapi

    • To enable atscppapi, you should give the below option when you execute ./configure
./configure --enable-cppapi
  • mruby

Examples

For example, you can write an ip filtering logic by using mruby like DSL:

whitelist = [
  "127.0.0.1"
]

# deny if client IP is listed in whitelist
conn = ATS::Connection.new
unless whitelist.include?(conn.remote_ip)
  ATS::echo "Your access is not allowed ..."
  ATS::return ATS::HTTP_FORBIDDEN
end

Quickstart

using Docker

  • Example docker image has already published to Docker Hub. The image contains a test script(simply responds by ATS::echo), so you can test ts_mruby quickly:
$ docker pull syucream/ts_mruby
$ docker run -it syucream/ts_mruby /bin/bash
root@ad7a82be8a65:/opt# trafficserver start
root@ad7a82be8a65:/opt# curl http://localhost:8080/
ts_mruby test

using Homebrew

  • If you're a Mac OS X user, you can use Homebrew to install ts_mruby:
$ brew install https://raw.githubusercontent.com/syucream/ts_mruby/master/Formula/trafficserver-atscppapi.rb
$ brew install --HEAD https://raw.githubusercontent.com/syucream/ts_mruby/master/Formula/ts_mruby.rb

Acknowledgement

Some components for mruby in this repository and sample scripts refer to mod_mruby and ngx_mruby's one under the MIT License.

ts_mruby's People

Contributors

syucream avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ts_mruby's Issues

records.config like interface for ATS::Records

From #32

records = ATS::Records.new

# getter
records.proxy.config.url_remap.pristine_host_hdr #=> 0
records.url_remap.pristine_host_hdr #=> 0
# setter as #= method
records.proxy.config.url_remap.pristine_host_hdr = 1
records.url_remap.pristine_host_hdr = 1
records = ATS::Records.new
records.set do |proxy|
  # records.config like accessor!
  proxy.config.url_remap.pristine_host_hdr = 1
end

ts_mruby build failed

My environment is Ubuntu 14.04 64bit.

FIrst, build trafficserver.

git clone https://github.com/apache/trafficserver.git
cd trafficserver
autoreconf -if
./configure --enable-cppapi --prefix=/usr/local/trafficserver-git-master
make
sudo make install

but, not found /usr/local/trafficserver-git-master/bin/tsxs. Then,

./configure --prefix=/usr/local/trafficserver-git-master
make
sudo make install

installed bin/tsxs and related binary.
Then, build ts_mruby after downloading mruby.

cd ts_mruby
autoreconf -if
./configure --with-ts-prefix-root=/usr/local/trafficserver-git-master/ --with-mruby-root=../mruby/
make build_mruby
make

But, a below error occurred.

$ make
/usr/local/trafficserver-git-master/bin/tsxs -I/usr/local/trafficserver-git-master/include -I../mruby/include -L/usr/local/trafficserver-git-master/lib/ts -L/usr/local/trafficserver-git-master/lib -L/home/matsumotory/DEV/mruby/build/host/lib -latscppapi -lmruby -lm -lreadline src/ts_mruby_*.cpp src/ts_mruby.cpp
  compiling src/ts_mruby_core.cpp -> src/ts_mruby_core.lo
In file included from /usr/local/trafficserver-git-master/include/atscppapi/Transaction.h:30:0,
                 from src/ts_mruby_core.cpp:13:
/usr/local/trafficserver-git-master/include/atscppapi/shared_ptr.h:28:26: fatal error: ink_autoconf.h: No such file or directory
 #include "ink_autoconf.h"
                          ^
compilation terminated.
tsxs: compilation failed: c++ -I/usr/local/trafficserver-git-master/include -I/usr/local/trafficserver-git-master/include -I../mruby/include -std=c++11 -g -pipe -Wall -O3 -feliminate-unused-debug-symbols -fno-strict-aliasing -Wno-invalid-offsetof -mcx16 -fpic -c src/ts_mruby_core.cpp -o src/ts_mruby_core.lo
make: *** [ts_mruby.la] Error 1

configure failed

Hi, @syucream

I try to install ts_mruby, but configure script failed.

$ autoreconf -if
$ ./configure --with-ts-prefix-root=/usr/local/trafficserver-git --with-mruby-root=../mruby
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
configure: creating ./config.status
config.status: error: cannot find input file: `Makefile.in'

Did I misunderstood the install process?

redesign around hooks

Current impl can support only PRE_REMAP hook or doRemap(), so ts_mruby can't support some methods(ATS::Headers_out#[], etc). In this issue I rethink about hooks to support those.

  • Create some designs.
  • Enable to separate init functions considering hooks.
  • Implement an example script.

Recompile mruby scripts when configuration reloaded.

Current implementation compiles mruby scripts when ts_mruby plugin is initialized.
However, To improve operations of ATS, it should enable to recompile when configuration reloaded. (For example, when traffic_line -x is executed.)

  • Check resources should be re-release/initialize when reloading
  • Implement re-release/initialize logic
  • Try $ traffic_ctl config reload

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.