Skip to content

Comments

Implement strict yaml unmarshalling.#1318

Merged
stuartnelson3 merged 1 commit intoprometheus:masterfrom
manosf:master
Apr 17, 2018
Merged

Implement strict yaml unmarshalling.#1318
stuartnelson3 merged 1 commit intoprometheus:masterfrom
manosf:master

Conversation

@manosf
Copy link
Contributor

@manosf manosf commented Apr 10, 2018

As with prometheus/prometheus#4033 and prometheus/common/pull/127, I updated the yaml vendor package in order to implement strict yaml unmarshalling. Thus, checkOverflow() is no longer needed since UnmarshalStrict() covers duplicate and unknown fields in yaml files.
Also some cleanup after deleting some -no longer necessary- variables and checkOverflow() calls.
cc @krasi-georgiev

@krasi-georgiev
Copy link

@simonpasquier can you have a look if you have a minute as I am stuck with some other issues.

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for updating vendor/gopkg.in/yaml.v2, the other changes to vendor/... should be reverted (vendored code shouldn't be gofmt'ed).

Also you now need to sign your commits to pass the DCO CI (eg git commit -s ...).

config/config.go Outdated
return fmt.Errorf("missing name in receiver")
}
return checkOverflow(c.XXX, "receiver config")
return unmarshal((*plain)(c))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L551-553 shouldn't be removed and return nil here.

c.Headers = normalizedHeaders

return checkOverflow(c.XXX, "email config")
return unmarshal((*plain)(c))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

return fmt.Errorf("missing service or routing key in PagerDuty config")
}
return checkOverflow(c.XXX, "pagerduty config")
return unmarshal((*plain)(c))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

}

return checkOverflow(c.XXX, "hipchat config")
return unmarshal((*plain)(c))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

return fmt.Errorf("missing Wechat CorpID in Wechat config")
}
return checkOverflow(c.XXX, "Wechat config")
return unmarshal((*plain)(c))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

return fmt.Errorf("missing Routing key in VictorOps config")
}
return checkOverflow(c.XXX, "victorops config")
return unmarshal((*plain)(c))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

return fmt.Errorf("missing token in Pushover config")
}
return checkOverflow(c.XXX, "pushover config")
return unmarshal((*plain)(c))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change needs to be reverted.

@@ -392,19 +392,19 @@ func AssetNames() []string {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change needs to be reverted.

@manosf
Copy link
Contributor Author

manosf commented Apr 11, 2018

@simonpasquier I reverted all of the unnecessary formatting and refactoring changes as you suggested.
The DCO test fails even though I signed off my last commit (the previous one that I made too).
Thank you for your help!

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor remark otherwise this is good for me.

`
conf := &Config{}
err := yaml.Unmarshal([]byte(in), conf)
err := yaml.UnmarshalStrict([]byte(in), conf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to use the same pattern as in the other tests:

-       conf := &Config{}
-       err := yaml.Unmarshal([]byte(in), conf)
+       _, err := Load(in)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it. It was doing the same job predefined in Load, so there is no need for it. Thanks!

@simonpasquier
Copy link
Member

@manosf you need to sign all the commits IIUC.

Copy link
Member

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks! You still need to sign the commits to comply with DCO (the easier is probably to squash them all).

@manosf
Copy link
Contributor Author

manosf commented Apr 12, 2018

@simonpasquier Done, thanks!

@stuartnelson3
Copy link
Contributor

Can you resolve the conflict?

@manosf
Copy link
Contributor Author

manosf commented Apr 17, 2018

@stuartnelson3 I just removed the file from staging since it no longer uses yaml unmarshalling.

@stuartnelson3 stuartnelson3 merged commit 300a87e into prometheus:master Apr 17, 2018
Signed-off-by: manosf <manosf@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants