Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ You can then configure it using the following directives:
| --------------------------------- | ---------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| `firetail_api_token` | `http` | Your API token from the FireTail platform | `PS-02-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` |
| `firetail_url` | `http` | The URL of the API endpoint the FireTail NGINX module will send logs to. | `https://api.logging.eu-west-1.prod.firetail.app/logs/bulk` |
| `firetail_disable` | `http` | Disables Firetail by default. Firetail will only be enabled for locations in which you use the `firetail_enable` directive. | This directive takes no arguments. |
| `firetail_enable` | `location` | Use this in every location block for which you want FireTail to be enabled. | This directive takes no arguments. |
| `firetail_allow_undefined_routes` | `http` | If set to `1`, `t`, `T`, `TRUE`, `true`, or `True`, requests to routes not defined in your OpenAPI specification will not be blocked. | `1`, `t`, `T`, `TRUE`, `true`, `True`, `0`, `f`, `F`, `FALSE`, `false`, `False` |

Expand Down
6 changes: 6 additions & 0 deletions dev/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ http {
# You should use lua-nginx-module to pull the API token in from an environment variable here
firetail_api_token "YOUR-API-TOKEN";
firetail_url "https://api.logging.eu-west-1.prod.firetail.app/logs/bulk";
firetail_disable;
firetail_allow_undefined_routes "true";

server {
Expand Down Expand Up @@ -54,22 +55,27 @@ http {
}

location /proxy/health {
firetail_enable;
proxy_pass http://localhost:80/health;
}

location /proxy/notfound {
firetail_enable;
proxy_pass http://localhost:80/notexists;
}

location /proxy/unhealthy {
firetail_enable;
proxy_pass http://localhost:80/unhealth;
}

location /proxy/profile/alice/comment {
firetail_enable;
proxy_pass http://localhost:80/profile/alice/comment;
}

location /proxy/profile/bob {
firetail_enable;
proxy_pass http://localhost:80/profile/bob;
}
}
Expand Down
1 change: 0 additions & 1 deletion src/nginx_module/access_phase_handler.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <ngx_core.h>
#include <ngx_http.h>
#include "access_phase_handler.h"
#include "filter_context.h"
#include "firetail_config.h"
#include "firetail_module.h"
Expand Down
2 changes: 1 addition & 1 deletion src/nginx_module/filter_headers.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <ngx_core.h>
#include <ngx_http.h>
#include "filter_context.h"
#include "filter_headers.h"
#include "firetail_config.h"
#include "firetail_module.h"

Expand Down
3 changes: 1 addition & 2 deletions src/nginx_module/filter_response_body.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#include <ngx_core.h>
#include <curl/curl.h>
#include <ngx_http.h>
#include <json-c/json.h>
#include "filter_context.h"
#include "filter_response_body.h"
#include "firetail_config.h"
#include "firetail_module.h"

Expand Down
5 changes: 2 additions & 3 deletions src/nginx_module/firetail_context.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include "access_phase_handler.h"
#include "filter_headers.h"
Expand Down Expand Up @@ -41,14 +40,14 @@ void *CreateFiretailConfig(ngx_conf_t *configuration_object) {
ngx_str_t firetail_url = ngx_string("");
firetail_config->FiretailApiToken = firetail_api_token;
firetail_config->FiretailUrl = firetail_url;
firetail_config->FiretailEnabled = 0;
firetail_config->FiretailEnabled = NGX_CONF_UNSET;

return firetail_config;
}

char *InitFiretailMainConfig(ngx_conf_t *configuration_object, void *http_main_config) { return NGX_CONF_OK; }

char *MergeFiretailLocationConfig(ngx_conf_t *cf, void *parent, void *child) {
ngx_conf_merge_value(((FiretailConfig *)child)->FiretailEnabled, ((FiretailConfig *)parent)->FiretailEnabled, 0);
ngx_conf_merge_value(((FiretailConfig *)child)->FiretailEnabled, ((FiretailConfig *)parent)->FiretailEnabled, 1);
return NGX_CONF_OK;
}
11 changes: 11 additions & 0 deletions src/nginx_module/firetail_directives.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <ngx_core.h>
#include <ngx_http.h>

char *FiretailApiTokenDirectiveCallback(ngx_conf_t *configuration_object, ngx_command_t *command_definition,
Expand Down Expand Up @@ -52,3 +53,13 @@ char *FiretailEnableDirectiveCallback(ngx_conf_t *configuration_object, ngx_comm

return NGX_CONF_OK;
}

char *FiretailDisableDirectiveCallback(ngx_conf_t *configuration_object, ngx_command_t *command_definition,
void *http_main_config) {
// Find the firetail_enable_field given the config pointer & offset in cmd
char *firetail_config = http_main_config;
ngx_int_t *firetail_enabled_field = (ngx_int_t *)(firetail_config + command_definition->offset);
*firetail_enabled_field = 0;

return NGX_CONF_OK;
}
12 changes: 10 additions & 2 deletions src/nginx_module/firetail_directives.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include <ngx_core.h>
#include <ngx_http.h>
#include "firetail_config.h"

char *FiretailApiTokenDirectiveCallback(ngx_conf_t *configuration_object, ngx_command_t *command_definition,
Expand All @@ -10,8 +9,10 @@ char *FiretailAllowUndefinedRoutesDirectiveCallback(ngx_conf_t *configuration_ob
void *http_main_config);
char *FiretailEnableDirectiveCallback(ngx_conf_t *configuration_object, ngx_command_t *command_definition,
void *http_main_config);
char *FiretailDisableDirectiveCallback(ngx_conf_t *configuration_object, ngx_command_t *command_definition,
void *http_main_config);

ngx_command_t kFiretailCommands[5] = {
ngx_command_t kFiretailCommands[6] = {
{// Name of the directive
ngx_string("firetail_api_token"),
// Valid in the main config and takes one arg
Expand Down Expand Up @@ -41,4 +42,11 @@ ngx_command_t kFiretailCommands[5] = {
// A callback function to be called when the directive is found in the
// configuration
FiretailEnableDirectiveCallback, NGX_HTTP_LOC_CONF_OFFSET, offsetof(FiretailConfig, FiretailEnabled), NULL},
{// Name of the directive
ngx_string("firetail_disable"),
// Valid in location configs and takes no args
NGX_HTTP_MAIN_CONF | NGX_CONF_NOARGS,
// A callback function to be called when the directive is found in the
// configuration
FiretailDisableDirectiveCallback, NGX_HTTP_LOC_CONF_OFFSET, offsetof(FiretailConfig, FiretailEnabled), NULL},
ngx_null_command};
8 changes: 0 additions & 8 deletions src/nginx_module/firetail_module.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>
#include "access_phase_handler.h"
#include "filter_context.h"
#include "filter_headers.h"
#include "filter_response_body.h"
#include "firetail_context.h"
#include "firetail_directives.h"
#include "firetail_module.h"
#include <json-c/json.h>

#define SIZE 65536

Expand Down
1 change: 1 addition & 0 deletions src/nginx_module/firetail_module.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef FIRETAIL_MODULE_INCLUDED
#define FIRETAIL_MODULE_INCLUDED

#include <ngx_core.h>
#include <ngx_http.h>

// The header and body filters of the filter that was added just before ours.
Expand Down
Loading