Skip to content
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

add basic CUE definitions of Caddy config structure #2

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mohammed90
Copy link
Member

Warning: I'm building this as I'm learning/exploring CUE. It is very likely it's not done with best practices. Review/guidance is very welcome and needed!

This seems to work... to a point. The two sample config files I'm using exhibit 2 behaviors:
1- One seems to work fine and filled with default values for missing fields
2- The other.... causes CUE to panic with stack overflow (I know the change that caused it to start panicking)

Successful

Running cue eval *.cue -d Config --out json caddy.json against this config:

{
	"apps": {
		"http": {
			"servers": {
				"srv0": {
					"listen": [
						":8080"
					],
					"routes": [
						{
							"match": [
								{
									"host": [
										"localhost"
									],
									"path": [
										"/my-path"
									]
								}
							],
							"handle": [
								{
									"handler": "static_response",
									"status_code": "200",
									"body": "Hello!"
								}
							]
						},
						{
							"handle": [
								{
									"handler": "reverse_proxy",
									"transport": {
										"protocol": "http"
									},
									"circuit_breaker": {
										"type": "internal"
									},
									"upstreams": [
										{
											"dial": "tcp/10.1.1.1:2020",
											"max_requests": 5
										},
										{
											"dial": "tcp/10.1.1.1:2121",
											"max_requests": 5
										}
									]
								}
							]
						}
					]
				},
				"srv1": {
					"listen": [
						":9090"
					],
					"routes": [
						{
							"handle": [
								{
									"handler": "static_response",
									"status_code": "200",
									"body": "Hello!"
								}
							]
						}
					]
				}
			}
		}
	}
}
Results in this output (note the default values being filled in):
{
    "admin": {
        "disabled": false,
        "listen": "localhost:2019",
        "enforce_origin": false,
        "config": {
            "persist": true
        }
    },
    "apps": {
        "http": {
            "servers": {
                "srv0": {
                    "listen": [
                        ":8080"
                    ],
                    "routes": [
                        {
                            "match": [
                                {
                                    "path": [
                                        "/my-path"
                                    ],
                                    "host": [
                                        "localhost"
                                    ]
                                }
                            ],
                            "handle": [
                                {
                                    "body": "Hello!",
                                    "handler": "static_response",
                                    "status_code": "200"
                                }
                            ]
                        },
                        {
                            "handle": [
                                {
                                    "handler": "reverse_proxy",
                                    "transport": {
                                        "protocol": "http"
                                    },
                                    "circuit_breaker": {
                                        "type": "internal",
                                        "factor": "latency",
                                        "trip_time": "5s"
                                    },
                                    "upstreams": [
                                        {
                                            "dial": "tcp/10.1.1.1:2020",
                                            "max_requests": 5
                                        },
                                        {
                                            "dial": "tcp/10.1.1.1:2121",
                                            "max_requests": 5
                                        }
                                    ],
                                    "buffer_requests": false
                                }
                            ]
                        }
                    ]
                },
                "srv1": {
                    "listen": [
                        ":9090"
                    ],
                    "routes": [
                        {
                            "handle": [
                                {
                                    "body": "Hello!",
                                    "handler": "static_response",
                                    "status_code": "200"
                                }
                            ]
                        }
                    ]
                }
            }
        }
    }
}

Failed

Running cue eval *.cue -d Config --out json caddy.json against this config:

{
	"admin": {
		"disabled": false,
		"enforce_origin": false
	},
	"logging": {
		"logs": {
			"log0": {
				"writer": {
					"output": "discard"
				},
				"encoder": {
					"format": "json",
					"message_key": "some_key"
				}
			}
		}
	},
	"apps": {
		"http": {
			"servers": {
				"srv0": {
					"listen": [
						"80",
						"443"
					],
					"routes": [
						{
							"handle": [
								{
									"handler": "static_response",
									"status_code": "200",
									"body": "Hello!"
								}
							]
						}
					]
				},
				"srv1": {
					"listen": [
						"80",
						"443"
					],
					"routes": [
						{
							"handle": [
								{
									"handler": "static_response",
									"status_code": "200",
									"body": "Hello!"
								}
							]
						}
					]
				}
			}
		}
	}
}

Results in this output:

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc020660440 stack=[0xc020660000, 0xc040660000]
fatal error: stack overflow

runtime stack:
runtime.throw(0x185450a, 0xe)
/usr/local/go/src/runtime/panic.go:1114 +0x72
runtime.newstack()
/usr/local/go/src/runtime/stack.go:1034 +0x6ce
runtime.morestack()
/usr/local/go/src/runtime/asm_amd64.s:449 +0x8f

goroutine 1 [running]:
cuelang.org/go/cue.(*structLit).expandFields(0xc0003c4fc0, 0xc000593340, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/value.go:1115 +0x1055 fp=0xc020660450 sp=0xc020660448 pc=0x13d2df5
cuelang.org/go/cue.(*structLit).lookup(0xc0003c4fc0, 0xc000593340, 0x49e, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/value.go:999 +0x77 fp=0xc020660580 sp=0xc020660450 pc=0x13d1017
cuelang.org/go/cue.(*structLit).subsumesImpl(0xc0003df570, 0xc0112bda90, 0x1987680, 0xc0003c4fc0, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/subsume.go:209 +0x515 fp=0xc0206607f8 sp=0xc020660580 pc=0x13b7215
cuelang.org/go/cue.(*subsumer).subsumes(0xc0112bda90, 0x1987680, 0xc0003df570, 0x1987680, 0xc0003c4fc0, 0x13d6000)
/Users/mpvl/Documents/dev/release/cue/cue/subsume.go:160 +0x26c fp=0xc020660898 sp=0xc0206607f8 pc=0x13b686c
cuelang.org/go/cue.(*disjunction).normalize.func1(0xc000593340, 0x1987680, 0xc0003c4fc0, 0x0, 0x1987680, 0xc0003df570, 0xc000593301, 0x1988700)
/Users/mpvl/Documents/dev/release/cue/cue/value.go:1682 +0xc4 fp=0xc0206608e0 sp=0xc020660898 pc=0x13e8994
cuelang.org/go/cue.(*disjunction).normalize(0xc0003ea500, 0xc000593340, 0x197fca0, 0xc0003ea500, 0xc0003c50a0, 0xc020660a58, 0x13d1523)
/Users/mpvl/Documents/dev/release/cue/cue/value.go:1709 +0x736 fp=0xc0206609c0 sp=0xc0206608e0 pc=0x13d60f6
cuelang.org/go/cue.(*disjunction).evalPartial(0xc0003ea500, 0xc000593340, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/eval.go:546 +0x3cd fp=0xc020660b10 sp=0xc0206609c0 pc=0x1391f5d
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:408 +0x91 fp=0xc020661158 sp=0xc020660b10 pc=0x1399441
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0900, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc0206611c8 sp=0xc020661158 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc020661440 sp=0xc0206611c8 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc020661a88 sp=0xc020661440 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc0206620d0 sp=0xc020661a88 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0900, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc020662140 sp=0xc0206620d0 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc0206623b8 sp=0xc020662140 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc020662a00 sp=0xc0206623b8 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc020663048 sp=0xc020662a00 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0900, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc0206630b8 sp=0xc020663048 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc020663330 sp=0xc0206630b8 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc020663978 sp=0xc020663330 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc020663fc0 sp=0xc020663978 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0900, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc020664030 sp=0xc020663fc0 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc0206642a8 sp=0xc020664030 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc0206648f0 sp=0xc0206642a8 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc020664f38 sp=0xc0206648f0 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0900, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc020664fa8 sp=0xc020664f38 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc020665220 sp=0xc020664fa8 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc020665868 sp=0xc020665220 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc020665eb0 sp=0xc020665868 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0900, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc020665f20 sp=0xc020665eb0 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc020666198 sp=0xc020665f20 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc0206667e0 sp=0xc020666198 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc020666e28 sp=0xc0206667e0 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0800, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc020666e98 sp=0xc020666e28 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc020667110 sp=0xc020666e98 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc020667758 sp=0xc020667110 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc020667da0 sp=0xc020667758 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0800, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc020667e10 sp=0xc020667da0 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc020668088 sp=0xc020667e10 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc0206686d0 sp=0xc020668088 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc020668d18 sp=0xc0206686d0 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0800, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc020668d88 sp=0xc020668d18 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc020669000 sp=0xc020668d88 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc020669648 sp=0xc020669000 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc020669c90 sp=0xc020669648 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0800, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc020669d00 sp=0xc020669c90 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc020669f78 sp=0xc020669d00 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc02066a5c0 sp=0xc020669f78 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc02066ac08 sp=0xc02066a5c0 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0800, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc02066ac78 sp=0xc02066ac08 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc02066aef0 sp=0xc02066ac78 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc02066b538 sp=0xc02066aef0 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc02066bb80 sp=0xc02066b538 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0800, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc02066bbf0 sp=0xc02066bb80 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc02066be68 sp=0xc02066bbf0 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc02066c4b0 sp=0xc02066be68 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc02066caf8 sp=0xc02066c4b0 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0800, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc02066cb68 sp=0xc02066caf8 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc02066cde0 sp=0xc02066cb68 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc02066d428 sp=0xc02066cde0 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc02066da70 sp=0xc02066d428 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0800, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc02066dae0 sp=0xc02066da70 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc02066dd58 sp=0xc02066dae0 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc02066e3a0 sp=0xc02066dd58 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc02066e9e8 sp=0xc02066e3a0 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0700, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc02066ea58 sp=0xc02066e9e8 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc02066ecd0 sp=0xc02066ea58 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc02066f318 sp=0xc02066ecd0 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc02066f960 sp=0xc02066f318 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0700, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc02066f9d0 sp=0xc02066f960 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc02066fc48 sp=0xc02066f9d0 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc020670290 sp=0xc02066fc48 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc0206708d8 sp=0xc020670290 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0700, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc020670948 sp=0xc0206708d8 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc020670bc0 sp=0xc020670948 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc020671208 sp=0xc020670bc0 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc020671850 sp=0xc020671208 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0700, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc0206718c0 sp=0xc020671850 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc020671b38 sp=0xc0206718c0 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc020672180 sp=0xc020671b38 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc0206727c8 sp=0xc020672180 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0700, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc020672838 sp=0xc0206727c8 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc020672ab0 sp=0xc020672838 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc0206730f8 sp=0xc020672ab0 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc020673740 sp=0xc0206730f8 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0700, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc0206737b0 sp=0xc020673740 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc020673a28 sp=0xc0206737b0 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc020674070 sp=0xc020673a28 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc0206746b8 sp=0xc020674070 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0700, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc020674728 sp=0xc0206746b8 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc0206749a0 sp=0xc020674728 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc020674fe8 sp=0xc0206749a0 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc020675630 sp=0xc020674fe8 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0700, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc0206756a0 sp=0xc020675630 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc020675918 sp=0xc0206756a0 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc020675f60 sp=0xc020675918 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc0206765a8 sp=0xc020675f60 pc=0x139c607
cuelang.org/go/cue.(*exporter).recExpr(0xc0000a42a0, 0x1987500, 0xc0003c1a70, 0x1989260, 0xc0003ea500, 0xc012ce0600, 0x0, 0x1)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:387 +0x294 fp=0xc020676618 sp=0xc0206765a8 pc=0x1398cc4
cuelang.org/go/cue.(*exporter).structure(0xc0000a42a0, 0xc0003c4fc0, 0xc0003c4f00, 0x1987680, 0xc0003c4fc0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:887 +0xffb fp=0xc020676890 sp=0xc020676618 pc=0x139fbdb
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1987680, 0xc0003c4fc0, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:587 +0x13f3 fp=0xc020676ed8 sp=0xc020676890 pc=0x139a7a3
cuelang.org/go/cue.(*exporter).expr.func2(...)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:571
cuelang.org/go/cue.(*exporter).expr(0xc0000a42a0, 0x1986fc0, 0xc0003ea500, 0x0, 0x0)
/Users/mpvl/Documents/dev/release/cue/cue/export.go:579 +0x3257 fp=0xc020677520 sp=0xc020676ed8 pc=0x139c607

Removing the default indicator * from *"json" and *KeyedEncoder in log.cue resolves the stack overflow.

@mholt mholt added the help wanted Extra attention is needed label Apr 18, 2020
@mohammed90 mohammed90 marked this pull request as draft April 24, 2020 10:28
@mohammed90
Copy link
Member Author

In regards to the cue eval issue, Marcel van Lohuizen (mpvl) helped me on the CUE slack with this:

cue eval is a bit weird as it tried to represent both data and definitions.
In practice these two use cases are hard to marry. Evaluating either in pure schema or data mode seems to work.

Lesson: use cue export or cue def

So with that, running cue export *.cue caddy.json -d Config against this config:

{
	"admin": {
		"disabled": false,
		"enforce_origin": false
	},
	"logging": {
		"logs": {
			"log0": {
				"writer": {
					"output": "discard"
				},
				"encoder": {
					"format": "json",
					"message_key": "some_key"
				}
			}
		}
	},
	"apps": {
		"http": {
			"servers": {
				"srv0": {
					"listen": [
						"80",
						"443"
					],
					"routes": [
						{
							"handle": [
								{
									"handler": "static_response",
									"status_code": "200",
									"body": "Hello!"
								}
							]
						}
					]
				},
				"srv1": {
					"listen": [
						"80",
						"443"
					],
					"routes": [
						{
							"handle": [
								{
									"handler": "static_response",
									"status_code": "200",
									"body": "Hello!"
								}
							]
						}
					]
				}
			}
		}
	}
}

Produces this config (notice how the default logger is injected in and other default values are injected too):

{
    "admin": {
        "disabled": false,
        "listen": "localhost:2019",
        "enforce_origin": false,
        "config": {
            "persist": true
        }
    },
    "logging": {
        "logs": {
            "default": {
                "level": "INFO",
                "writer": {
                    "output": "stderr"
                },
                "encoder": {
                    "format": "json"
                },
                "sampling": {
                    "interval": 1000000000,
                    "first": 100,
                    "thereafter": 100
                }
            },
            "log0": {
                "level": "INFO",
                "writer": {
                    "output": "discard"
                },
                "encoder": {
                    "format": "json",
                    "message_key": "some_key"
                }
            }
        }
    },
    "apps": {
        "http": {
            "servers": {
                "srv0": {
                    "listen": [
                        "80",
                        "443"
                    ],
                    "routes": [
                        {
                            "handle": [
                                {
                                    "body": "Hello!",
                                    "handler": "static_response",
                                    "status_code": "200"
                                }
                            ]
                        }
                    ]
                },
                "srv1": {
                    "listen": [
                        "80",
                        "443"
                    ],
                    "routes": [
                        {
                            "handle": [
                                {
                                    "body": "Hello!",
                                    "handler": "static_response",
                                    "status_code": "200"
                                }
                            ]
                        }
                    ]
                }
            }
        }
    }
}

The latest pending issue I have currently is merging the values of the default logger with the config provided by the user. Meaning, if the user has config values for the default logger, it should override/merge against the default hard-coded values of matching keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants