Skip to content

Commit

Permalink
fix: add missing protocols field to plugins
Browse files Browse the repository at this point in the history
All plugin entities are expected to have a `protocols` schema field,
but some plugin schemas are missing it. From a functional point
of view, this doesn't have any impact, since the `protocols` field
is still injected in the overall schema. But when plugin schemas
are retrieved via the Admin API using the `/schemas/plugins/<name>`
endpoint, then the "original" schema is returned. For example:

```
$ http :8001/schemas/plugins/prometheus
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Connection: keep-alive
Content-Length: 354
Content-Type: application/json; charset=utf-8
Date: Tue, 11 Oct 2022 06:42:47 GMT
Server: kong/3.0.0
X-Kong-Admin-Latency: 6

{
    "fields": [
        {
            "config": {
                "fields": [
                    {
                        "per_consumer": {
                            "default": false,
                            "type": "boolean"
                        }
                    },
                    {
                        "status_code_metrics": {
                            "default": false,
                            "type": "boolean"
                        }
                    },
                    {
                        "latency_metrics": {
                            "default": false,
                            "type": "boolean"
                        }
                    },
                    {
                        "bandwidth_metrics": {
                            "default": false,
                            "type": "boolean"
                        }
                    },
                    {
                        "upstream_health_metrics": {
                            "default": false,
                            "type": "boolean"
                        }
                    }
                ],
                "required": true,
                "type": "record"
            }
        }
    ]
}
```

This is problematic for decK, which uses this endpoint to
inject schema defaults before doing a deployment, which can
cause unnecessary/misleading diffs:

```
$ cat kong.yaml
_format_version: "3.0"
plugins:
  - name: prometheus

$ deck sync
updating plugin prometheus (global)  {
   "config": {
     "bandwidth_metrics": false,
     "latency_metrics": false,
     "per_consumer": false,
     "status_code_metrics": false,
     "upstream_health_metrics": false
   },
   "enabled": true,
   "id": "93aece4b-b813-4d9b-af28-f4c1c874f128",
   "name": "prometheus",
-  "protocols": [
-    "grpc",
-    "grpcs",
-    "http",
-    "https"
-  ]
 }

Summary:
  Created: 0
  Updated: 1
  Deleted: 0
```
  • Loading branch information
GGabriele committed Oct 31, 2022
1 parent 98ff366 commit abc8e08
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@

#### Plugins

- Add missing `protocols` field to various plugin schemas.
[#9525](https://github.com/Kong/kong/pull/9525)
- **AWS Lambda**: Fix an issue that is causing inability to
read environment variables in ECS environment.
[#9460](https://github.com/Kong/kong/pull/9460)
Expand Down
3 changes: 3 additions & 0 deletions kong/plugins/azure-functions/schema.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local typedefs = require "kong.db.schema.typedefs"

return {
name = "azure-functions",
fields = {
{ protocols = typedefs.protocols },
{ config = {
type = "record",
fields = {
Expand Down
3 changes: 3 additions & 0 deletions kong/plugins/grpc-gateway/schema.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local typedefs = require "kong.db.schema.typedefs"

return {
name = "grpc-gateway",
fields = {
{ protocols = typedefs.protocols },
{ config = {
type = "record",
fields = {
Expand Down
3 changes: 3 additions & 0 deletions kong/plugins/grpc-web/schema.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
local typedefs = require "kong.db.schema.typedefs"

return {
name = "grpc-web",
fields = {
{ protocols = typedefs.protocols },
{ config = {
type = "record",
fields = {
Expand Down
1 change: 1 addition & 0 deletions kong/plugins/pre-function/_schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ return function(plugin_name)
name = plugin_name,
fields = {
{ consumer = typedefs.no_consumer },
{ protocols = typedefs.protocols },
{
config = {
type = "record",
Expand Down
3 changes: 3 additions & 0 deletions kong/plugins/prometheus/schema.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local typedefs = require "kong.db.schema.typedefs"

local function validate_shared_dict()
if not ngx.shared.prometheus_metrics then
return nil,
Expand All @@ -10,6 +12,7 @@ end
return {
name = "prometheus",
fields = {
{ protocols = typedefs.protocols },
{ config = {
type = "record",
fields = {
Expand Down
2 changes: 2 additions & 0 deletions kong/plugins/proxy-cache/schema.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local strategies = require "kong.plugins.proxy-cache.strategies"
local typedefs = require "kong.db.schema.typedefs"


local ngx = ngx
Expand All @@ -16,6 +17,7 @@ end
return {
name = "proxy-cache",
fields = {
{ protocols = typedefs.protocols },
{ config = {
type = "record",
fields = {
Expand Down
1 change: 1 addition & 0 deletions kong/plugins/request-transformer/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ table.insert(colon_strings_array_record_plus_uri.fields, uri)
return {
name = "request-transformer",
fields = {
{ protocols = typedefs.protocols },
{ config = {
type = "record",
fields = {
Expand Down
1 change: 1 addition & 0 deletions kong/plugins/session/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ return {
name = "session",
fields = {
{ consumer = typedefs.no_consumer },
{ protocols = typedefs.protocols },
{ config = {
type = "record",
fields = {
Expand Down
1 change: 1 addition & 0 deletions kong/plugins/zipkin/schema.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ end
return {
name = "zipkin",
fields = {
{ protocols = typedefs.protocols },
{ config = {
type = "record",
fields = {
Expand Down

0 comments on commit abc8e08

Please sign in to comment.