-
Notifications
You must be signed in to change notification settings - Fork 28
feat: kong plugin #1073
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
Merged
Merged
feat: kong plugin #1073
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
69db17b
init kong plugin
anandkumarpatel a992ec6
add group and id
anandkumarpatel 9c5a19d
add comments, fix test
anandkumarpatel 84059ba
better docs and Dockerfile
anandkumarpatel f7b23f1
docs: readme tweaks
erunion b496092
update docs
anandkumarpatel 9fbb39b
update docs
anandkumarpatel a9e7c6f
clean up docs
anandkumarpatel ef02112
prettier:write
anandkumarpatel 153a415
sha512 id
anandkumarpatel 173fd12
Update .github/MAINTAINERS.md
anandkumarpatel a4fd956
Update .github/MAINTAINERS.md
anandkumarpatel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
return { | ||
default = { | ||
verbose = true, | ||
coverage = false, | ||
output = "gtest", | ||
}, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--postgres |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# 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 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. | ||
|
||
### 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 | ||
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 | ||
```bash | ||
curl -i -s -X POST http://localhost:8001/plugins --data name=readme-plugin --data 'config.api_key=<Your API Key>' | ||
``` | ||
|
||
#### Enable for a specific service route | ||
```bash | ||
# 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" | ||
# 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 | ||
curl -i http://localhost:8000/mock/anything | ||
``` | ||
|
||
### Development tricks | ||
anandkumarpatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Get plugin config for a route | ||
anandkumarpatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
```bash | ||
curl -s http://localhost:8001/plugins | jq '.data | map(select(.name == "readme-plugin")) | first' | ||
``` | ||
|
||
```bash | ||
# get 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 --data "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 --data '{"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 --data '{"config": {"id_header": "email"}}' | jq '.config.id_header' | ||
``` | ||
|
||
|
||
> 🚧 Any Issues? | ||
> | ||
> Integrations can be tricky! [Contact support](https://docs.readme.com/guides/docs/contact-support) if you have any questions/issues. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.