-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: kong plugin #1073
feat: kong plugin #1073
Changes from all commits
69db17b
a992ec6
9c5a19d
84059ba
f7b23f1
b496092
9fbb39b
a9e7c6f
ef02112
153a415
173fd12
a4fd956
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
return { | ||
default = { | ||
verbose = true, | ||
coverage = false, | ||
output = "gtest", | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
charset = utf-8 | ||
|
||
[*.lua] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[kong/templates/nginx*] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.template] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[Makefile] | ||
indent_style = tab |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# servroot typically is the Kong working directory for tests | ||
servroot | ||
# exclude generated packed rocks | ||
*.rock | ||
# exclude Pongo shell history | ||
.pongo/.bash_history | ||
# exclude LuaCov statistics file | ||
luacov.stats.out | ||
# exclude LuaCov report | ||
luacov.report.out | ||
# exclude Pongo containerid file | ||
.containerid |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
std = "ngx_lua" | ||
unused_args = false | ||
redefined = false | ||
max_line_length = false | ||
|
||
|
||
include_files = { | ||
"**/*.lua", | ||
"*.rockspec", | ||
".busted", | ||
".luacheckrc", | ||
} | ||
|
||
|
||
globals = { | ||
"_KONG", | ||
"kong", | ||
"ngx.IS_CLI", | ||
} | ||
|
||
|
||
not_globals = { | ||
"string.len", | ||
"table.getn", | ||
} | ||
|
||
|
||
ignore = { | ||
"6.", -- ignore whitespace warnings | ||
} | ||
|
||
|
||
files["spec/**/*.lua"] = { | ||
std = "ngx_lua+busted", | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
include = { | ||
"%/kong%-plugin%/kong%/.+$", | ||
} | ||
|
||
statsfile = "/kong-plugin/luacov.stats.out" | ||
reportfile = "/kong-plugin/luacov.report.out" | ||
runreport = true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--postgres |
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"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# ReadMe Metrics + Kong | ||
|
||
<p align="center"> | ||
<img src="https://user-images.githubusercontent.com/33762/182927634-2aebeb46-c215-4ac3-9e98-61f931e33583.png" /> | ||
</p> | ||
|
||
<p align="center"> | ||
Track usage of your API and troubleshoot issues faster. | ||
</p> | ||
|
||
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: | ||
|
||
- Install this plugin into your Kong Gateway by copying the `kong` directory into your Kong environment or use the provided Dockerfile. see [this](https://docs.konghq.com/gateway/latest/plugin-development/get-started/deploy/) for details. | ||
- The plugin runs during the log phase of the Kong pipeline and 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. | ||
|
||
### 📦 Deploying locally | ||
anandkumarpatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```bash | ||
# Build kong image with the plugin | ||
docker build -t kong-readme-plugin:latest . | ||
# Run kong with the plugin | ||
curl -Ls https://get.konghq.com/quickstart | bash -s -- -r "" -i kong-readme-plugin -t latest | ||
# Enable the plugin | ||
curl -isX POST http://localhost:8001/plugins -d name=readme-plugin -d 'config.api_key=<Your API Key>' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why port There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if they ran the above script, its 8001. I am assuming if they don't follow the script they would know what they are doing. |
||
``` | ||
|
||
### 🧑🔬 Testing | ||
|
||
Requires [pongo](https://github.com/Kong/kong-pongo) to test and develop. | ||
|
||
```bash | ||
pongo up | ||
pongo shell | ||
kms | ||
|
||
# Check if the plugin is available | ||
curl -s localhost:8001 | jq '.plugins.available_on_server."readme-plugin"' | ||
``` | ||
|
||
#### Enable for all services | ||
anandkumarpatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```bash | ||
curl -sX POST http://localhost:8001/plugins -d name=readme-plugin -d 'config.api_key=<Your API Key>' | jq | ||
``` | ||
|
||
#### Enable for a specific service | ||
|
||
```bash | ||
# Add a new service | ||
curl -isX POST http://localhost:8001/services -d name=example_service -d url='http://httpbin.org' | ||
|
||
# Associate the custom plugin with the `example_service` service | ||
curl -isX POST http://localhost:8001/services/example_service/plugins -d 'name=readme-plugin' -d "config.queue.max_retry_time=1" | ||
|
||
# Add a new route for sending requests through the `example_service` service | ||
curl -iX POST http://localhost:8001/services/example_service/routes -d 'paths[]=/mock' -d name=example_route | ||
|
||
# Test | ||
curl -i http://localhost:8000/mock/anything | ||
``` | ||
|
||
### 🧙 Development tricks | ||
|
||
```bash | ||
# Get plugin config | ||
curl -s http://localhost:8001/plugins | jq '.data | map(select(.name == "readme-plugin")) | first' | ||
|
||
# Retrieve the plugin ID | ||
export PLUGIN_ID=$(curl -s http://localhost:8001/plugins | jq '.data | map(select(.name == "readme-plugin")) | first | .id' | tr -d '"') | ||
|
||
# Configure the plugin with your API key | ||
curl -sX PATCH http://localhost:8001/plugins/$PLUGIN_ID -d "config.api_key=<Your API Key>" | jq '.config.api_key' | ||
|
||
# Configure `hide_headers` | ||
curl -sX PATCH -H'Content-Type: application/json' http://localhost:8001/plugins/$PLUGIN_ID -d '{"config": {"hide_headers": {"foo": "", "bar": "default"}}}' | jq '.config.hide_headers' | ||
|
||
# Configure `id_header` | ||
curl -sX PATCH -H'Content-Type: application/json' http://localhost:8001/plugins/$PLUGIN_ID -d '{"config": {"id_header": "email"}}' | jq '.config.id_header' | ||
|
||
# Configure `group_by` | ||
curl -sX PATCH -H'Content-Type: application/json' http://localhost:8001/plugins/$PLUGIN_ID -d '{"config": {"group_by": {"x-user-email": "email", "x-org-name": "label"}}}' | jq '.config.group_by' | ||
|
||
# Delete the plugin | ||
curl -sX DELETE http://localhost:8001/plugins/$PLUGIN_ID | ||
``` | ||
|
||
> 🚧 Any Issues? | ||
> | ||
> Integrations can be tricky! [Contact support](https://docs.readme.com/guides/docs/contact-support) if you have any questions/issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anandkumarpatel do you have any tickets in place for these tasks? If not, can we start tracking them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not yet! where should I add these tickets to? (note, this is just for hackathon, so we wont work on the tickets unless there is traction so not sure if its worth adding them?)