• This repository has been archived on 12/Jul/2023
  • Stars
    star
    152
  • Rank 244,685 (Top 5 %)
  • Language
    Lua
  • License
    Apache License 2.0
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lua DNS client, load balancer, and utility library

Overview

Lua library containing a dns client, several utilities, and a load-balancer.

The module is currently OpenResty only, and builds on top of the lua-resty-dns library

Features

  • resolves A, AAAA, CNAME and SRV records, including port
  • parses /etc/hosts
  • parses /resolv.conf and applies LOCALDOMAIN and RES_OPTIONS variables
  • caches dns query results in memory
  • synchronizes requests (a single request for many requestors, eg. when cached ttl expires under heavy load)
  • toip applies a local (weighted) round-robin scheme on the query results
  • (weighted) round-robin balancer
  • consistent-hashing balancer
  • least-connections balancer

Copyright and license

Copyright: (c) 2016-2021 Kong, Inc.

Author: Thijs Schreijer

License: Apache 2.0

Testing

Tests are executed using busted, but because they run inside the resty cli tool, you must use the rbusted script.

For troubleshooting purposes: see the /extra folder for how to parse logs

History

Versioning is strictly based on Semantic Versioning

Release process:

  1. update the changelog below
  2. update the rockspec file
  3. generate the docs using ldoc .
  4. commit and tag the release
  5. upload rock to LuaRocks

6.0.2 (05-Jul-2021)

  • Fix: validTtl should not be used for host-file entries. PR 134

6.0.1 (22-Jun-2021)

  • Performance: reduce amount of timers on init_worker. PR 130

6.0.0 (05-Apr-2021)

  • BREAKING: the round-robin balancing algorithm is now implemented in resty.dns.round_robin and has no consistent-hashing algorithm features, which are now all restricted to resty.dns.consistent_hashing. PR 123
  • Added: option to enable or disable nameservers randomization. Note: this feature depends on the to-be-released feature in lua-resty-dns. PR 119

5.2.3 (19-Mar-2021)

  • Fix: potential synchronisation issue in the least-connections balancer. PR 126

5.2.2 (11-Mar-2021)

  • Fix: do not iterate over all the search domains when resolving an unambiguous fully-qualified domain name (FQDN), i.e. ended in a dot. PR 122

5.2.1 (21-Jan-2021)

  • Fix: balancer DNS updates could go into a busy loop upon renewal. Reported as Kong issue #6739, fixed with PR 116.

5.2.0 (7-Jan-2021)

  • Fix: now a single timer is used to check for expired records instead of one per host, significantly reducing the number of resources required for DNS resolution. PR 112

5.1.1 (7-Oct-2020)

  • Dependency: Bump lua-resty-timer to 1.0

5.1.0 (28-Sep-2020)

  • Fix: workaround for LuaJIT/ARM bug, see Issue 93.
  • Fix: table reduction was calculated wrong. Not a "functional" bug, just causing slightly less agressive memory releasing.
  • Added: alternative implementation of the consistent-hashing balancing algorithm, which does not rely on the addresses addition and removal order to build the same request distribution among different instances. See PR 97.

5.0.0 (14-May-2020)

  • BREAKING: getPeer now returns the host-header value instead of the hostname that was used to add the address. This is only breaking if a host was added through addHost with an ip-address. In that case getPeer will no longer return the ip-address as the hostname, but will now return nil. See PR 89.
  • Added: option useSRVname, if truthy then getPeer will return the name as found in the SRV record, instead of the hostname as added to the balancer. See PR 89.
  • Added: callback return an extra parameter; the host-header for the address added/removed.
  • Fix: using the module instance instead of the passed one for dns resolution in the balancer (only affected testing). See PR 88.

4.2.0 (23-Mar-2020)

  • Change: export DNS source type on status report. See PR 86.

4.1.3 (24-Jan-2020)

  • Fix: fix ttl-0 records issues with the balancer, see Kong issue Kong/kong#5477
    • the previous record was not properly detected as a ttl=0 record by checking on the __ttl0flag we now do
    • since the "fake" SRV record wasn't updated with a new expiry time the expiry-check-timer would keep updating that record every second

4.1.2 (10-Dec-2019)

  • Fix: handle cases when lastQuery is nil, see PR 81 and PR 82.

4.1.1 (14-Nov-2019)

  • Fix: added logging of try-list to the TCP/UDP wrappers, see PR 75.
  • Fix: reduce logging noise of the requery timer

4.1.0 (7-Aug-2019)

  • Fix: unhealthy balancers would not recover because they would not refresh the DNS records used. See PR 73.
  • Added: automatic background resolving of hostnames, expiry will be checked every second, and if needed DNS (and balancer) will be updated. See PR 73.

4.0.0 (26-Jun-2019)

  • BREAKING: the balancer callback is called with a new event; "health" whenever the health status of the balancer changes.
  • BREAKING: renamed setPeerStatus to setAddressStatus to be in line with the new setHostStatus, and prevent confusion.
  • Added: keep track of unavailable weight. Added the getStatus method to return health, of the entire balancer structure. Health itself is determined based on the new property healthThreshold.
  • Added: prevention of cascading failures when balancer is unhealthy. Use the healthThreshold value to set when the balancer is considered unhealthy.
  • Added: method setHostStatus, to set the availability/health state of all addresses belonging to a host at once.
  • Fix: when an asyncquery failed to create the timer, it would silently ignore the error. Error is now being logged.

3.0.2 (8-Mar-2019) Bugfix

  • Fix: callback for adding an address did not pass the address object, but instead passed the balancer object twice.

3.0.1 (5-Mar-2019) Bugfix

  • Fix: "balancer is nil" error, see issue #49.

3.0.0 (7-Nov-2018) Refactor & least-connections balancer

  • Refactor: split the balancer in a base class (handling DNS resolution) and the ring-balancer, implementing the algorithm.
  • Added: new least-connections balancer
  • Fix: since addresses could occasionally hold names instead of IP addresses, it could happen that a call to setPeerStatus was unsuccessful, because the IP address would not match the name in the address object. Now a handle is returned by getPeer.
  • BREAKING: getPeer signature (and return values) changed, making this a breaking change.

2.2.0 (28-Aug-2018) Fixes and a new option

  • Added: a new option validTtl that, if set, will forcefully override the ttl value of any valid answer received. Issue 48.
  • Fix: remove multiline log entries, now encoded as single-line json. Issue 52.
  • Fix: always inject a localhost value, even if not in /etc/hosts. Issue 54.
  • Fix: added a workaround for Amazon Route 53 nameservers replying with a ttl=0 whilst the record has a non-0 ttl. Issue 56.

2.1.0 (21-May-2018) Fixes

  • Fix: the round-robin scheme for the balancer starts at a randomized position to prevent all workers from starting with the same peer.
  • Fix: the balancer no longer returns port = 0 for SRV records without a port, the default port is now returned.
  • Fix: ipv6 nameservers with a scope in their address are not supported. This fix will simply skip them instead of throwing errors upon resolving. Fixes issue 43.
  • Minor: improved logging in the balancer
  • Minor: relax requery default interval for failed dns queries from 1 to 30 seconds.

2.0.0 (22-Feb-2018) Major performance improvement (balancer) and bugfixes

  • BREAKING: improved performance and memory footprint for large balancers. 80-85% less memory will be used, while creation time dropped by 85-90%. Since the host:getPeer() function signature changed, this is a breaking change.
  • Change: BREAKING the errors for cache-only lookup failures and empty records have been changed.
  • Fix: do not fail initialization without nameservers.
  • Fix: properly recognize IPv6 in square brackets from the /etc/hosts file.
  • Fix: do not set success-type to types we're not looking for. Fixes Kong issue #3210.
  • Fix: store records from the additional section in cache
  • Fix: do not overwrite stale data in the client cache with empty records

1.0.0 (14-Dec-2017) Fixes and IPv6

  • Change: BREAKING all IPv6 addresses are now returned with square brackets
  • Fix: properly recognize IPv6 addresses in square brackets

0.6.3 (27-Nov-2017) Fixes and flagging unhealthy peers

  • Added: flag to mark an address as failed/unhealthy, see setPeerStatus
  • Added: callback to receive balancer updates; addresses added-to/removed-from the balancer (after DNS updates for example).
  • fix: SRV record entries with a weight 0 are now supported
  • fix: failure of the last hostname to resolve (balancer)

0.6.2 (04-Sep-2017) Fixes and refactor

  • Fix: balancer not returning hostname for named SRV entries. See issue #17
  • Fix: fix an occasionally failing test
  • Refactor: remove metadata from the records, instead store it in its own cache

0.6.1 (28-Jul-2017) Randomization adjusted

  • Change: use a different randomizer for the ring-balancer to predictably recreate the balancer in the exact same state (adds the lrandom library as a new dependency)

0.6.0 (14-Jun-2017) Rewritten resolver core to resolve async

  • Added: resolution will be done async whenever possible. For this to work a new setting has been introduced staleTtl which determines for how long stale records will returned while a query is in progress in the background.
  • Change: BREAKING! several functions that previously returned and took a resolver object no longer do so.
  • Fix: no longer lookup ip adresses as names if the query type is not A or AAAA
  • Fix: normalize names to lowercase after query
  • Fix: set last-success types for hosts-file entries and ip-addresses

0.5.0 (25-Apr-2017) implement SEARCH and NDOTS

  • Removed: BREAKING! stdError function removed.
  • Added: implemented the search and ndots options.
  • Change: resolve no longer returns empty results or dns errors as a table but as lua errors (nil + error).
  • Change: toip() and resolve() have an extra result; history. A table with the list of tried names/types/results.
  • Fix: timeout and retrans options from resolv.conf were ignored by the client module.
  • Fix: nameservers with an ipv6 address would not be used properly. Also added a flag enable_ipv6 (default == false) to enable the usage of ipv6 nameservers.

0.4.1 (21-Apr-2017) Bugfix

  • Fix: cname record caching causing excessive dns queries, see Kong issue #2303.

0.4.0 (30-Mar-2017) Bugfixes

  • Change: BREAKING! modified hash treatment, must now be an integer > 0
  • Added: BREAKING! a retry counter to fall-through on hashed-retries (changes the getpeer signature)
  • Fix: the MAXNS (3) was not honoured, so more than 3 nameservers would be parsed from the resolv.conf file. Fixes Kong issue #2290.
  • Added: two convenience hash functions
  • Performance: some improvements (pre-allocated tables for the slot lists)

0.3.2 (6-Mar-2017) Bugfixes

  • Fix: Cleanup disabled addresses but did not delete them, causing errors when they were repeatedly added/removed
  • Fix: potential racecondition when re-querying dns records
  • Fix: potential memoryleak when a balancer object was released with a running timer

0.3.1 (22-Feb-2017) Bugfixes

  • Kubernetes dns returns an SRV record for individual nodes, where the target is the same name again (hence causing a recursive loop). Now those entries will be removed, and if nothing is left, it will fail the SRV lookup, causing a fall-through to the next record type.
  • Kubernetes tends to return a port of 0 if none is provided/set, hence the toip() function now ignores a port=0 and falls back on the port passed in.

0.3.0 (8-Nov-2016) Major breaking update

  • breaking: renamed a lot of things; method names, module names, etc. pretty much breaks everything... also releasing under a new name
  • feature: udp function setpeername added (client)
  • fix: do not synchronize dns queries for ttl=0 requests (client)
  • fix: full test coverage and accompanying fixes (ring-balancer)
  • feature: auto-retry for failed dns queries (ring-balancer)
  • feature: updating weights is now supported without removing/re-adding (ring-balancer)
  • change: auto-retry interval configurable for failed dns queries (ring-balancer)
  • change: max life-time interval configurable for ttl=0 dns records (ring-balancer)

0.2.1 (24-Oct-2016) Bugfix

  • fix: toip() failed on SRV records with only 1 entry

0.2 (18-Oct-2016) Added the balancer

  • fix: was creating resolver objects even if serving from cache
  • change: change resolver order (SRV is now first by default) for dns servers that create both SRV and A records for each entry
  • feature: make resolver order configurable
  • feature: ring-balancer (experimental, no full test coverage yet)
  • other: more test coverage for the dns client

0.1 (09-Sep-2016) Initial released version

More Repositories

1

kong

🦍 The Cloud-Native API Gateway and AI Gateway.
Lua
38,724
star
2

insomnia

The open-source, cross-platform API client for GraphQL, REST, WebSockets and gRPC.
JavaScript
30,407
star
3

unirest-java

Unirest in Java: Simplified, lightweight HTTP client library.
Java
2,602
star
4

kubernetes-ingress-controller

🦍 Kong for Kubernetes: The official Ingress Controller for Kubernetes.
Go
2,127
star
5

swrv

Stale-while-revalidate data fetching for Vue
TypeScript
2,089
star
6

mockbin

Mock, Test & Track HTTP Requests and Response for Microservices
JavaScript
1,988
star
7

mashape-oauth

OAuth Modules for Node.js - Supporting RSA, HMAC, PLAINTEXT, 2,3-Legged, 1.0a, Echo, XAuth, and 2.0
JavaScript
1,781
star
8

docker-kong

🐒 Docker distribution for Kong
Shell
1,392
star
9

unirest-php

Unirest in PHP: Simplified, lightweight HTTP client library.
PHP
1,282
star
10

httpsnippet

HTTP Request snippet generator for many languages & libraries
TypeScript
1,061
star
11

unirest-nodejs

Unirest in Node.js: Simplified, lightweight HTTP client library.
JavaScript
954
star
12

guardian

Remove the OAuth dance with one request.
JavaScript
640
star
13

deck

decK: Configuration management and drift detection for Kong
Go
437
star
14

unirest-python

Unirest in Python: Simplified, lightweight HTTP client library.
Python
432
star
15

apiembed

Embeddable API code snippets for your website, blog or API documentation
Pug
402
star
16

unirest-ruby

Unirest in Ruby: Simplified, lightweight HTTP client library.
Ruby
365
star
17

unirest-obj-c

Unirest in Objective-C: Simplified, lightweight HTTP client library.
Objective-C
276
star
18

kong-dist-kubernetes

Kubernetes managed Kong cluster
Shell
255
star
19

kong-manager

Admin GUI for Kong Gateway (Official)
TypeScript
242
star
20

kong-plugin

Simple template to get started with custom Kong plugins
Lua
238
star
21

charts

Helm chart for Kong
Mustache
224
star
22

lua-resty-worker-events

Cross Worker Events for Nginx in Pure Lua
Lua
190
star
23

unirest-net

Unirest in .NET: Simplified, lightweight HTTP client library.
C#
190
star
24

docs.konghq.com

🦍 Source code for docs.konghq.com website.
Ruby
186
star
25

kong-oauth2-hello-world

This is a simple node.js + express.js application that shows an authorization page for the OAuth 2.0 plugin on Kong.
JavaScript
173
star
26

kong-pongo

Tooling to run plugin tests with Kong and Kong Enterprise
Lua
154
star
27

kongponents

🦍 Kong Vue Component Library
Vue
134
star
28

go-pdk

Kong Go Plugin Development Kit
Go
126
star
29

kong-vagrant

🐒 Vagrantfile for Kong testing and development
Shell
124
star
30

lua-resty-healthcheck

Healthcheck library for OpenResty to validate upstream service status
Lua
119
star
31

kong-plugin-prometheus

Prometheus plugin for Kong - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
119
star
32

apiglossary

Open source glossary of API terms, acronyms and industry buzzwords.
95
star
33

go-kong

Go binding for Kong's admin API
Go
87
star
34

go-plugins

A collection of Kong plugins written in Go
Go
86
star
35

ngx_wasm_module

Nginx + WebAssembly
C
80
star
36

kong-terraform-aws

Kong Terraform Module for AWS
HCL
77
star
37

kong-build-tools

Build tools to package and release Kong
Shell
77
star
38

homebrew-kong

🐒 Homebrew tap for Kong
Ruby
69
star
39

kong-dist-cloudformation

🐒 Kong CloudFormation Stack
66
star
40

go-pluginserver

Kong Go Plugin Server
Go
66
star
41

kong-plugin-zipkin

A Kong plugin for propogating zipkin spans and reporting spans to a zipkin server - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
60
star
42

kong-operator

Kong Operator for Kubernetes and OpenShift
Mustache
58
star
43

lua-multipart

Multipart Parser for Lua
Lua
55
star
44

mashape-php-library

Mashape PHP Server Library - Easily create an API in PHP. You can use it for existing services or brand new cloud components.
PHP
50
star
45

gateway-operator

Kubernetes Operator for Kong Gateways
Go
46
star
46

gojira

Multi-purpose tool to ease development and testing of Kong by using Docker containers
Shell
45
star
47

kong-python-pdk

Write Kong plugins in Python (Experimental)
Python
44
star
48

HARchiver

[Deprecated] Universal Lightweight Proxy for Galileo
OCaml
41
star
49

atc-router

Expression based matching library for Kong
Rust
41
star
50

koko

koko - Control Plane for Kong Gateway [open-source]
Go
41
star
51

unirest-website

Simplified, lightweight HTTP libraries in multiple languages
HTML
39
star
52

go-srp

Secure Remote Password library for Go
Go
38
star
53

tcpbin

TCP Request & Response Service, written in node.js
HTML
37
star
54

kong-plugin-acme

Let's Encrypt and ACMEv2 integration with Kong - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
36
star
55

kong-portal-templates

Themes, components, and utilities to help you get started with the Kong Dev Portal.
CSS
35
star
56

kong-js-pdk

Kong PDK for Javascript and plugin server
JavaScript
35
star
57

kong-mesh-dist-kubernetes

Start Kong 1.0 as a K8s sidecar
Makefile
33
star
58

kubernetes-testing-framework

Golang Integration Testing Framework For Kubernetes APIs and Controllers.
Go
32
star
59

lua-kong-nginx-module

Nginx C module to allow deeper control of Nginx behaviors by Kong Lua code
Perl
32
star
60

demo-scene

🦍 a collection of demos and examples around Kong tools and technologies
JavaScript
30
star
61

konnect-portal

Konnect OSS Dev Portal
TypeScript
30
star
62

docker-java8

A Dockerfile for starting a container with Java 8 installed
30
star
63

Astronode-Broadcaster

A TCP replication server, or broadcaster, that replicates TCP commands to other TCP servers
Java
29
star
64

insomnia-docs

This repository houses all Insomnia documentation.
JavaScript
29
star
65

opentracing-lua

Opentracing Library for Lua
Lua
28
star
66

lua-resty-events

Inter process Pub/Sub pattern for Nginx worker processes
Raku
28
star
67

boss.js

Automatically load balance asyncronous jobs across multiple processes in a round-robin fashion.
JavaScript
27
star
68

kong-portal-cli

Kong Developer Portal CLI
TypeScript
25
star
69

lua-uuid

Lua library to generate UUIDs leveraging libuuid
Lua
25
star
70

lua-resty-aws

AWS SDK for OpenResty
Lua
24
star
71

lua-resty-lmdb

Safe API for manipulating LMDB databases using OpenResty/Lua.
C
24
star
72

kong-plugin-request-transformer

Kong request transformer plugin - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
22
star
73

lua-resty-timer

Extended timers for OpenResty
Perl
22
star
74

lua-resty-counter

Lock-free counter for OpenResty
Perl
21
star
75

kong-plugin-session

🍪 Session plugin for Kong - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
20
star
76

lua-pack

A library for packing and unpacking binary data.
C
20
star
77

go-apiops

Kong's Go based APIOps library
Go
19
star
78

swagger-ui-kong-theme

Plugin theme for Swagger-UI that adds snippets
JavaScript
19
star
79

terraform-provider-konnect

Terraform Provider for Kong Konnect
Go
18
star
80

api-log-format

Specification and examples of the new API logging format ALF
17
star
81

kong-plugin-serverless-functions

Kong Serverless Plugins - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
17
star
82

apistatus

API status is a simple tool that checks if an API is online. http://apistatus.org
JavaScript
15
star
83

changelog-generator

a changelog generator focused on flexibility and ease of use
TypeScript
14
star
84

openresty-patches

Moved to https://github.com/Kong/kong-build-tools
Perl
14
star
85

kong-plugin-grpc-gateway

Kong Plugin to transcode REST request to gRPC - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
14
star
86

lua-resty-consul-event

Consul Events HTTP API Wrapper
Perl
14
star
87

srp-js

Fork of node-srp modified to work in the browser
TypeScript
14
star
88

KongAir

An example Kong Konnect application deployed with Kong APIOps
JavaScript
13
star
89

harplayer

Replay HAR logs
JavaScript
13
star
90

kong-plugin-aws-lambda

AWS Lambda plugin - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
13
star
91

openresty-build-tools

Moved to https://github.com/Kong/kong-build-tools
Shell
13
star
92

priority-updater

Tool to quickly create a plugin with an updated priority
Lua
13
star
93

jenkins-infrastructure

Cloudformation to create and update an ECS cluster that runs jenkins
Shell
12
star
94

httpbin

Python
12
star
95

kong-custom-plugin-workshop

Lua
12
star
96

kong-apisecops-redhat

Self-paced demo of APISecOps with ROSA and Kong Konnect
Jinja
12
star
97

version.lua

Simple version comparison library
Lua
11
star
98

kong-license

Kong Inc internal script to manage your local test license
Shell
11
star
99

kong-plugin-proxy-cache

HTTP Proxy Caching for Kong - this plugin has been moved into https://github.com/Kong/kong, please open issues and PRs in that repo
Lua
11
star
100

openapi2kong

Lib to convert OpenAPI specs into Kong specs
Lua
11
star