luraproject / lura

Ultra performant API Gateway with middlewares. A project hosted at The Linux Foundation
https://luraproject.org
Other
6.35k stars 563 forks source link

Possibility of add static response on kafka publisher #387

Closed saffari-m closed 3 years ago

saffari-m commented 4 years ago

Hi. I have some problems with defining the Kafka publisher endpoints. when I try to add a static response on Kafka endpoint, I received an exception.

It's my endpoint :

{
  "endpoint": "/foo",
  "method": "POST",
  "output_encoding": "no-op",
  "extra_config": {
    "github.com/devopsfaith/krakend/proxy": {
      "static": {
        "strategy": "complete",
        "data": {
          "status": 200,
          "message": "OK"
        }
      }
    }
  },
  "backend": [
    {
      "host": ["kafka://"],
      "disable_host_sanitize": true,
      "extra_config": {
        "github.com/devopsfaith/krakend-pubsub/publisher": {
          "topic_url": "foo_topic"
        }
      }
    }
  ]
}

Exception:

assignment to entry in nil map
/usr/local/go/src/runtime/map_faststr.go:204 (0xcde902)
/go/pkg/mod/github.com/devopsfaith/krakend@v1.1.1/proxy/static.go:30 (0x105c2af)
/go/pkg/mod/github.com/devopsfaith/krakend@v1.1.1/router/gin/endpoint.go:39 (0x1748814)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147 (0x17305ea)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/recovery.go:83 (0x17437af)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147 (0x17305ea)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/logger.go:241 (0x17428e0)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/context.go:147 (0x17305ea)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/gin.go:403 (0x1739f32)
/go/pkg/mod/github.com/gin-gonic/gin@v1.5.0/gin.go:364 (0x173963c)
/usr/local/go/src/net/http/server.go:2807 (0x10230d2)
/usr/local/go/src/net/http/server.go:1895 (0x101ea4b)
/usr/local/go/src/runtime/asm_amd64.s:1373 (0xd313c0)

is there any idea for solving that? I can't find any examples in the documentation.

reytech-dev commented 3 years ago

@saffari-m Did you find a solution to serve a static response? I'm having the same issue and I'm running out of ideas how to solve it.

kpacha commented 3 years ago

I'm not sure this is the main reason for the panic but keep in mind you can't mix no-op with static response

reytech-dev commented 3 years ago

@kpacha Thanks for your input. I tested the following config:


{
  "version": 2,
  "timeout": "3000ms",
  "name": "redpanda poc",
  "endpoints": [
    {
      "endpoint": "/redpanda",
      "method": "POST",
      "output_encoding": "json",
      "extra_config": {
        "github.com/devopsfaith/krakend/proxy": {
            "static": {
                "strategy": "success",
                "data": {
                    "status": 200,
                    "message": "OK"
                }
            }
        }
      },
      "backend": [
        {
          "extra_config": {
            "github.com/devopsfaith/krakend-pubsub/publisher": {
              "topic_url": "chat-rooms"
            }
          },
          "host": ["kafka://"],
          "disable_host_sanitize": true
        }
      ]
    }
  ],
  "port": 8080
}

Im receiving the following exception:

2021/07/19 19:49:43 [Recovery] 2021/07/19 - 19:49:43 panic recovered:
POST /redpanda HTTP/1.1
Host: 172.17.255.200:8000
Accept: application/json
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 93
Content-Type: application/json

assignment to entry in nil map
/usr/local/go/src/runtime/map_faststr.go:204 (0xd2ccec)
/go/pkg/mod/github.com/luraproject/lura@v1.4.1/proxy/static.go:31 (0x10f0132)
/go/pkg/mod/github.com/luraproject/lura@v1.4.1/router/gin/endpoint.go:40 (0x191d611)
/go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/context.go:165 (0x1917a79)
/go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/recovery.go:99 (0x1917a60)
/go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/context.go:165 (0x1916b53)
/go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/logger.go:241 (0x1916b12)
/go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/context.go:165 (0x190cd09)
/go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/gin.go:489 (0x190ccef)
/go/pkg/mod/github.com/gin-gonic/gin@v1.7.2/gin.go:445 (0x190c7db)
/usr/local/go/src/net/http/server.go:2887 (0x10b0302)
/usr/local/go/src/net/http/server.go:1952 (0x10ab72c)
/usr/local/go/src/runtime/asm_amd64.s:1371 (0xd88e40)

Please let me know, if I should open a new issue with my comment. If you need a local environment to reproduce the exception, I can create a git repository with my local k8s setup. If it is intentional behavior, I will test it with a small lua script to manipulate the response body. Thanks in advance.

kpacha commented 3 years ago

thanks for the update. I think now I got the issue in the static middleware: it is not checking if the response.Data map is null before adding the content defined at the configuration.

the fix is quite simple, so I'm doing it in a moment and it will be available at the lura project. but I can't give you any estimates on the next krakend release date

Edit: It's weird because I found a test that should cover the scenario. I think I need some more digging before pushing any fix

reytech-dev commented 3 years ago

@kpacha Thank you very much. Let me now if I can provide you with more information or assist you in any way.

kpacha commented 3 years ago

fixed!

thanks

reytech-dev commented 3 years ago

Thank you, for the insane fast fix!

saffari-m commented 3 years ago

@kpacha Thanks.

github-actions[bot] commented 2 years ago

This issue was marked as resolved a long time ago and now has been automatically locked as there has not been any recent activity after it. You can still open a new issue and reference this link.