Coder Social home page Coder Social logo

krakend-martian's Introduction

KrakenD martian

The krakend-martian package integrates the martian project into the KrakenD framework.

How to use it

Add your martian DSL definition under the "github.com/devopsfaith/krakend-martian" namespace of the backend section of the config file

"extra_config": {
  "github.com/devopsfaith/krakend-martian": {}
}

More details here: https://github.com/google/martian#modifiers-all-the-way-down

Check the example folder for a complete demo.

Example

  • Build and run krakend edition with martian
$ cd example
$ go install ./...
$ GOPATH/bin/example -c example/krakend.json -d -p 8000
  • Send a request to the configured endpoint
$ curl -i 127.0.0.1:8000/supu
  HTTP/1.1 200 OK
  Cache-Control: public, max-age=0
  Content-Type: application/json; charset=utf-8
  X-Krakend: Version undefined
  X-Krakend-Completed: true
  Date: Tue, 17 Jul 2018 11:56:33 GMT
  Content-Length: 19

  {"msg":"you rock!"}

And check the logs of the KrakenD: the request modifiers have done their job! See how {"msg":"you rock!"} was added to the payload.

[KRAKEND] ▶ DEBUG config: {[0xc4201839a0] 3s 3.6µs [] 8000 2  map[github_com/devopsfaith/krakend-gologging:map[prefix:[KRAKEND] stdout:true level:DEBUG syslog:false]] 0s 0s 0s 0s false false 0 250 0s 0s 0s 0s 0s 0s false <nil> true 1}
[KRAKEND] ▶ DEBUG Debug enabled
[KRAKEND] ▶ DEBUG Method: GET
[KRAKEND] ▶ DEBUG URL: /__debug/supu
[KRAKEND] ▶ DEBUG Query: map[]
[KRAKEND] ▶ DEBUG Params: [{param /supu}]
[KRAKEND] ▶ DEBUG Headers: map[User-Agent:[KrakenD Version undefined] Content-Length:[19] Content-Type:[] X-Forwarded-For:[127.0.0.1] Accept-Encoding:[gzip]]
[KRAKEND] ▶ DEBUG Body: {"msg":"you rock!"}
[GIN] | 200 |     313.798µs |       127.0.0.1 | GET      /__debug/supu
[GIN] | 200 |    1.556445ms |       127.0.0.1 | GET      /supu

krakend-martian's People

Contributors

alombarte avatar bartoszgolek avatar bgpearson avatar corinnekrych avatar dependabot[bot] avatar kpacha avatar ondram avatar rin8888work avatar taik0 avatar terraskye avatar trojanh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

krakend-martian's Issues

martian plugin

Hi. I tried to write martian plugin for correlation id.
There is the link to the repo https://github.com/JaSei/krakend-martian-correlation-header/tree/implementation.
My implementation is based on https://github.com/kpacha/martian-components.

But if I start krakend, there are warnings around the loading of plugins and the martian plugin doesn't work. My feeling is martian plugins didn't load. Because the code of martian-components is 3 years old at least, it's possible the plugin system is changed and doesn't support now martian plugins?

log output maybe looks strange, because it runs in docker-compose
image: devopsfaith/krakend:1.4.1

krakend_ce_1   | [KRAKEND] 2021/10/07 - 16:26:12.874 ▶ WARNIN loading plugins: plugin loader found 1 error(s):
krakend_ce_1   | opening plugin 0 (/opt/krakend/plugins/krakend-martian_correlation_header.so): plugin: symbol ClientRegisterer not found in plugin github.com/JaSei/krakend-martian-correlation-header
krakend_ce_1   | [KRAKEND] 2021/10/07 - 16:26:12.874 ▶ INFO total http executor plugins loaded: 0
krakend_ce_1   | [KRAKEND] 2021/10/07 - 16:26:12.874 ▶ WARNIN loading plugins: plugin loader found 1 error(s):
krakend_ce_1   | opening plugin 0 (/opt/krakend/plugins/krakend-martian_correlation_header.so): plugin: symbol HandlerRegisterer not found in plugin github.com/JaSei/krakend-martian-correlation-header

...

krakend_ce_1   | [KRAKEND] 2021/10/07 - 16:26:12.880 ▶ ERROR {<nil> parse: unknown modifier: header.Correlation} map[github.com/devopsfaith/krakend-martian:map[header.Correlation:map[header_name:X-Correlation-ID]]]

thanks for advice

panic: runtime error: invalid memory address or nil pointer dereference

When running example krakend.json we get following error

[GIN-debug] Listening and serving HTTP on XXXX
[GIN-debug] [ERROR] listen tcp: address XXXX: missing port in address
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x45d3279]

goroutine 1 [running]:
github.com/luraproject/lura/v2/router/gin.ginRouter.Run({{0xc00037d040, {0x0, 0x0, 0x0}, 0xc0003f39c0, {0x47e9440, 0xc000460840}, {0x47fea60, 0xc000427bf0}, 0x0}, ...}, ...)
	/Users/rajan/.gvm/pkgsets/go1.17/global/pkg/mod/github.com/luraproject/lura/[email protected]/router/gin/router.go:111 +0x219
main.main()
	/Users/rajan/Desktop/projects/krakend-martian/example/main.go:51 +0x6f8
exit status 2

I updated the krakend.json version to following

"version": 3,

Go version: go1.17
OS: MacOS 12.1
When I run the go file using go run example/main.go -c example/krakend.json -d -p 8080 I get above error.

EDIT:

I also tried to checkout v1.4.0 and tried running the old version but it did not work either and failed with the same error.

header.Filter not working without defined value

The Martian docs state:

In the case that the value is undefined, the contained modifier executes if a request or response contains a header with the defined name.

I am not able to produce the expected result. Here is my KrakenD config:

{
    "$schema": "https://www.krakend.io/schema/v3.json",
    "version": 3,
    "debug_endpoint": true,
    "endpoints": [
        {
            "endpoint": "/",
            "method": "GET",
            "input_headers": [
                "old",
                "new"
            ],
            "backend": [
                {
                    "host": [ "http://127.0.0.1:8080" ],
                    "url_pattern": "/__debug/",
                    "method": "GET",
                    "extra_config": {
                        "modifier/martian": {
                            "header.Filter": {
                                "scope": [ "request" ],
                                "name": "old",
                                "modifier": {
                                    "header.Copy": {
                                        "scope": [ "request" ],
                                        "from": "old",
                                        "to": "new"
                                    }
                                }
                            }
                        }
                    }
                }
            ]
        }
    ]
}

With that configuration I run curl http://127.0.0.1:8080/ -H 'old: testval' and get this result:
Screenshot from 2023-05-18 08-58-24

If I add "value": "testval" to the header.Filter object then it works:
Screenshot from 2023-05-18 08-59-18

I've tried setting "value": null as well. That yields the same result as not including the property.

Modify the url from the request's query params to backend path params

Hello, I would like to modify the url from the request's query params to backend path params.

For example:

from

/settings?id=test

to

/settings/{id}

May I know how I should write the config?

"extra_config": {
    "github.com/devopsfaith/krakend-martian":
       {
          "url.Modifier": {
             "scope": ["request"],
             "path": [WHAT SHOUlD I WRITE HERE?]
          }
       }
 }

access to application logger

hi, all
when i using krakend
i add in config file some extraconfig construction
github.com/devopsfaith/krakend-martian
how in krakend-martian component
get access to application logger?
now my code looks like this

func init() {
    parse.Register("collection.modifier", collectionModifierFromJSON)
}
....
func collectionModifierFromJSON(b []byte) (*parse.Result, error) {
...
logger.GetLogger().Debug("...")

id_modifier error

I'm trying to use id_modifier to add transaction ID to header, and configured KrakenD like this.

"extra_config": {
  "github.com/devopsfaith/krakend-martian": {
    "header.Id": {
      "scope": ["request"]
    }
  }
}

But KrakenD is giving me error like,

2021/09/01 09:09:37 [Recovery] 2021/09/01 - 09:09:37 panic recovered:
runtime error: invalid memory address or nil pointer dereference
/usr/local/go/src/runtime/panic.go:212 (0xd4e35a)
/usr/local/go/src/runtime/signal_unix.go:734 (0xd67512)
/go/pkg/mod/github.com/google/[email protected]+incompatible/context.go:185 (0x1790d38)
/go/pkg/mod/github.com/google/[email protected]+incompatible/header/id_modifier.go:53 (0x1790d2a)
/go/pkg/mod/github.com/devopsfaith/[email protected]/martian.go:102 (0x179b2f8)
/go/pkg/mod/github.com/devopsfaith/[email protected]/martian.go:63 (0x179c1a4)
/go/pkg/mod/github.com/luraproject/[email protected]/proxy/http.go:68 (0x10ed22f)
/go/pkg/mod/github.com/luraproject/[email protected]/proxy/balancing.go:76 (0x10ebfb6)
/go/pkg/mod/github.com/luraproject/[email protected]/proxy/http.go:109 (0x10ed950)
/go/pkg/mod/github.com/luraproject/[email protected]/router/gin/endpoint.go:40 (0x191d611)
/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x1917a79)
/go/pkg/mod/github.com/gin-gonic/[email protected]/recovery.go:99 (0x1917a60)
/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x1916b53)
/go/pkg/mod/github.com/gin-gonic/[email protected]/logger.go:241 (0x1916b12)
/go/pkg/mod/github.com/gin-gonic/[email protected]/context.go:165 (0x190cd09)
/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:489 (0x190ccef)
/go/pkg/mod/github.com/gin-gonic/[email protected]/gin.go:445 (0x190c7db)
/go/pkg/mod/github.com/rs/[email protected]/cors.go:207 (0x1e2d910)
/usr/local/go/src/net/http/server.go:2069 (0x10acc43)
/go/pkg/mod/github.com/rs/[email protected]/cors.go:207 (0x1e2d910)
/usr/local/go/src/net/http/server.go:2069 (0x10acc43)
/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)

Is my configuration wrong? or is it a bug?

Martian status modifier is not supported.

"github.com/devopsfaith/krakend-martian": {
                            "fifo.Group": {
                                "scope": ["response"],
                                "modifiers": [
                                    {
                                        "header.Filter": {
                                            "scope": ["response"],
                                            "name" : "X-Redirect-Status",
                                            "value" : "302",
                                            "modifier": {
                                                "status.Modifier": {
                                                "scope": ["response"],
                                                "statusCode": "302"
                                                }
                                            }
                                        }
                                    }
                                ]
                            }
                        }

resulting in the following error :

{<nil> parse: unknown modifier: status.Modifier} map[github.com/devopsfaith/krakend-martian:map[fifo.Group:map[modifiers:[map[header.Filter:map[scope:[response] name:X-Redirect-Status value:302 modifier:map[status.Modifier:map[scope:[response] statusCode:302]]]]] scope:[response]]]] 

now i did some digging and it seems we are missing :

https://github.com/google/martian/status from the configuration krakend-martian/martian.go

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.