Skip to content

Commit

Permalink
better docs and Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
anandkumarpatel committed Sep 5, 2024
1 parent 9c5a19d commit 84059ba
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
17 changes: 17 additions & 0 deletions packages/kong-plugin/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM kong/kong-gateway:3.7
# Ensure any patching steps are executed as root user
USER root

# Add custom plugin to the image
COPY ./kong/plugins/readme-plugin /usr/local/share/lua/5.1/kong/plugins/readme-plugin
ENV KONG_PLUGINS=bundled,readme-plugin

# Ensure kong user is selected for image execution
USER kong

# Run kong
ENTRYPOINT ["/entrypoint.sh"]
EXPOSE 8000 8443 8001 8444
STOPSIGNAL SIGQUIT
HEALTHCHECK --interval=10s --timeout=10s --retries=10 CMD kong health
CMD ["kong", "docker-start"]
18 changes: 13 additions & 5 deletions packages/kong-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@

With [ReadMe's Metrics API](https://readme.com/metrics) your team can get deep insights into your API's usage. If you're a developer, it takes a few small steps to send your API logs to [ReadMe](http://readme.com). Here's an overview of how the integration works:

- You add the Cloudflare Worker to your Cloudflare account
- The Cloudflare Worker sends ReadMe the details of your API's incoming requests and outgoing responses, with the option for you to redact any private parameters or headers.
- Install this plugin in Kong. You can the provided docker image or copy the plugin into your own Kong image.
- The plugin sends ReadMe the details of your API's incoming requests and outgoing responses, with the option for you to redact any private headers using the configuration options.
- ReadMe uses these request and response details to create an API Metrics Dashboard which can be used to analyze specific API calls or monitor aggregate usage data.

**For information on how to set it up, check out our [integration documentation](https://docs.readme.com/docs/sending-logs-to-readme-with-cloudflare).**
### Deploying locally

```bash
docker build -t kong-readme-plugin:1 .
curl -Ls https://get.konghq.com/quickstart | bash -s -- -r "" -i kong-readme-plugin -t 1
curl -i -s -X POST http://localhost:8001/plugins --data name=readme-plugin --data 'config.api_key=<Your API Key>'
# setup endpoints or test
curl -i http://localhost:8000/mock/anything
```

### testing
```bash
Expand All @@ -34,7 +42,7 @@ curl -i -s -X POST http://localhost:8001/plugins --data name=readme-plugin --dat
# add a new service
curl -i -s -X POST http://localhost:8001/services --data name=example_service --data url='http://httpbin.org'
# Associate the custom plugin with the example_service service
curl -is -X POST http://localhost:8001/services/example_service/plugins --data 'name=readme-plugin' -d "config.queue.max_retry_time=1"
curl -is -X POST http://localhost:8001/services/example_service/plugins --data 'name=readme-plugin' -d "config.queue.max_retry_time=1"
# Add a new route for sending requests through the example_service
curl -i -X POST http://localhost:8001/services/example_service/routes --data 'paths[]=/mock' --data name=example_route
# test
Expand All @@ -44,7 +52,7 @@ curl -i http://localhost:8000/mock/anything
### Development tricks
Get plugin config for a route
```bash
curl http://localhost:8001/plugins | jq '.data | map(select(.name == "readme-plugin")) | first'
curl -s http://localhost:8001/plugins | jq '.data | map(select(.name == "readme-plugin")) | first'
```

```bash
Expand Down
4 changes: 1 addition & 3 deletions packages/kong-plugin/kong/plugins/readme-plugin/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ local Queue = require "kong.tools.queue"
local cjson = require "cjson"
local url = require "socket.url"
local http = require "resty.http"
local kong_meta = require "kong.meta"


local kong = kong
local ngx = ngx
Expand Down Expand Up @@ -219,7 +217,7 @@ end

local HttpLogHandler = {
PRIORITY = 12,
VERSION = kong_meta.version,
VERSION = "0.0.1",
}

function HttpLogHandler:log(conf)
Expand Down

0 comments on commit 84059ba

Please sign in to comment.