Skip to content

IcingaDB::PrepareObject(): convert non-null Checkable#check_timeout to number #9792

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

Conversation

Al2Klimov
Copy link
Member

and, in case of null, fall back to Checkable#check_command.timeout, just like IcingaDB#SerializeState(). Otherwise the Go daemon crashes. It expects a number.

fixes #9791

Setup

  • Icinga 2: standard config, api setup, feature enable icingadb, object Host "42" { check_command = "dummy"; check_timeout = "42" }
  • Redis, Icinga DB, MySQL: nothing special

Before

2023-06-15T12:26:34.024+0200	INFO	config-sync	Inserting 33 items of type notificationcommand argument
2023-06-15T12:26:34.025+0200	WARN	config-sync	Aborted initial state sync after 96.537249ms
2023-06-15T12:26:34.025+0200	WARN	config-sync	Aborted config sync after 96.637219ms
2023-06-15T12:26:34.026+0200	FATAL	icingadb	json: cannot unmarshal string into Go struct field Host.check_timeout of type float64
can't unmarshal JSON into *v1.Host
github.com/icinga/icingadb/internal.UnmarshalJSON
	/Users/aklimov/NET/WS/icingadb/internal/internal.go:47
github.com/icinga/icingadb/pkg/icingaredis.CreateEntities.func1.1
	/Users/aklimov/NET/WS/icingadb/pkg/icingaredis/utils.go:56
golang.org/x/sync/errgroup.(*Group).Go.func1
	/Users/aklimov/go/pkg/mod/golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c/errgroup/errgroup.go:57
runtime.goexit
	/usr/local/Cellar/go/1.20.4/libexec/src/runtime/asm_amd64.s:1598

After

2023-06-15T12:28:38.526+0200	INFO	config-sync	Finished initial state sync in 219.779129ms
2023-06-15T12:28:38.532+0200	INFO	config-sync	Inserting 1 items of type user
2023-06-15T12:28:38.535+0200	INFO	config-sync	Inserting 520 items of type customvar flat
2023-06-15T12:28:38.546+0200	INFO	config-sync	Inserting 3 items of type servicegroup
2023-06-15T12:28:38.768+0200	INFO	icingadb	Starting config runtime updates sync
2023-06-15T12:28:38.768+0200	INFO	icingadb	Starting history retention
2023-06-15T12:28:38.768+0200	INFO	config-sync	Finished config sync in 461.861837ms

…o number

and, in case of null, fall back to Checkable#check_command.timeout, just like
IcingaDB#SerializeState(). Otherwise the Go daemon crashes. It expects a number.
@Al2Klimov Al2Klimov added this to the 2.14.0 milestone Jun 15, 2023
@cla-bot cla-bot bot added the cla/signed label Jun 15, 2023
@icinga-probot icinga-probot bot added area/icingadb New backend bug Something isn't working labels Jun 15, 2023
@Al2Klimov Al2Klimov requested a review from julianbrost June 19, 2023 13:20
@julianbrost julianbrost requested a review from yhabteab June 19, 2023 14:07
Copy link
Member

@yhabteab yhabteab left a comment

Choose a reason for hiding this comment

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

Is CheckCommand#timeout guaranteed to be non-empty and doesn't need any type-casting?

@Al2Klimov
Copy link
Member Author

ObjectImpl<Command>::GetTimeout() returns an int, so yes.

@yhabteab
Copy link
Member

I've been checking the types on the Icinga DB side and to me it doesn't make much sense to use uint32 for Command#Timeout and float64 for Checkable#CheckTimeout. It would be great if you could fix this inconsistency in Icinga DB as well.

@julianbrost
Copy link
Contributor

I've been checking the types on the Icinga DB side and to me it doesn't make much sense to use uint32 for Command#Timeout and float64 for Checkable#CheckTimeout. It would be great if you could fix this inconsistency in Icinga DB as well.

That inconsistency already starts on the Icinga 2 side:

[config] int timeout {
default {{{ return 60; }}}
};

[config] Value check_timeout;

@julianbrost julianbrost merged commit 5350aa3 into master Jun 26, 2023
@julianbrost julianbrost deleted the icingadb-conversion-of-strings-to-number-types-to-avoid-crashes-9791 branch June 26, 2023 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/icingadb New backend bug Something isn't working cla/signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IcingaDB conversion of strings to number types, to avoid crashes
3 participants