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

Direct settings updates (API) #5237

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

friofry
Copy link
Contributor

@friofry friofry commented May 27, 2024

Adds 2 API endpoints for direct settings modification see status-im/status-desktop#12918

  • SaveNewWakuNode
  • SetMaxLogBackups

Closes status-im/status-desktop#12918

Further changes:

@status-im-auto
Copy link
Member

status-im-auto commented May 27, 2024

Jenkins Builds

Click to see older builds (32)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 3fcf2ec #1 2024-05-27 13:40:09 ~4 min linux 📦zip
✔️ 3fcf2ec #1 2024-05-27 13:41:47 ~6 min android 📦aar
✔️ 3fcf2ec #1 2024-05-27 13:45:21 ~9 min ios 📦zip
✔️ 3fcf2ec #1 2024-05-27 14:21:11 ~45 min tests 📄log
✔️ 5598aa1 #2 2024-05-29 18:47:52 ~2 min linux 📦zip
✔️ 5598aa1 #2 2024-05-29 18:48:13 ~3 min android 📦aar
✔️ 5598aa1 #2 2024-05-29 18:49:17 ~4 min ios 📦zip
✔️ 5598aa1 #2 2024-05-29 19:28:23 ~43 min tests 📄log
✔️ 230f96d #3 2024-05-29 20:26:12 ~1 min android 📦aar
✔️ 230f96d #3 2024-05-29 20:26:36 ~2 min linux 📦zip
✔️ 230f96d #3 2024-05-29 20:27:44 ~3 min ios 📦zip
✔️ 230f96d #3 2024-05-29 21:07:35 ~43 min tests 📄log
✖️ cdb936d #4 2024-05-30 11:15:59 ~2 min tests 📄log
✔️ cdb936d #4 2024-05-30 11:17:28 ~4 min linux 📦zip
✔️ cdb936d #4 2024-05-30 11:18:53 ~5 min ios 📦zip
✔️ cdb936d #4 2024-05-30 11:18:56 ~5 min android 📦aar
✖️ 4a442ab #5 2024-06-04 14:09:29 ~2 min tests 📄log
✔️ 4a442ab #5 2024-06-04 14:10:44 ~3 min ios 📦zip
✔️ 4a442ab #5 2024-06-04 14:10:58 ~4 min linux 📦zip
✔️ 4a442ab #5 2024-06-04 14:12:41 ~5 min android 📦aar
✖️ 31365a0 #6 2024-06-04 14:10:46 ~1 min tests 📄log
✔️ 31365a0 #6 2024-06-04 14:13:38 ~2 min linux 📦zip
✔️ 31365a0 #6 2024-06-04 14:14:32 ~3 min ios 📦zip
✔️ 31365a0 #6 2024-06-04 14:18:01 ~5 min android 📦aar
✔️ 054e5b3 #7 2024-06-04 14:22:29 ~2 min android 📦aar
✔️ 054e5b3 #7 2024-06-04 14:23:48 ~3 min ios 📦zip
✔️ 054e5b3 #7 2024-06-04 14:24:19 ~4 min linux 📦zip
✖️ 054e5b3 #7 2024-06-04 14:22:45 ~2 min tests 📄log
✖️ 721896d #8 2024-06-04 14:30:42 ~1 min tests 📄log
✔️ 721896d #8 2024-06-04 14:31:18 ~2 min android 📦aar
✔️ 721896d #8 2024-06-04 14:32:58 ~3 min ios 📦zip
✔️ 721896d #8 2024-06-04 14:33:30 ~4 min linux 📦zip
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ d2d463b #9 2024-06-04 14:51:43 ~2 min linux 📦zip
✔️ d2d463b #9 2024-06-04 14:52:49 ~3 min ios 📦zip
✔️ d2d463b #9 2024-06-04 14:55:08 ~5 min android 📦aar
✔️ d2d463b #9 2024-06-04 15:29:42 ~40 min tests 📄log

@friofry friofry changed the title Ab/issue 12918 setting update with diffs API to direct settings updates May 27, 2024
@friofry friofry changed the title API to direct settings updates Direct settings updates (API) May 27, 2024
Copy link
Member

@jrainville jrainville left a comment

Choose a reason for hiding this comment

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

Looks good. I'd just add some simple validation, since it comes from user inputs

@@ -20,10 +20,18 @@ func (m *Messenger) SetLogLevel(request *requests.SetLogLevel) error {
return nodecfg.SetLogLevel(m.database, request.LogLevel)
}

func (m *Messenger) SetMaxLogBackups(request *requests.SetMaxLogBackups) error {
return nodecfg.SetMaxLogBackups(m.database, request.MaxLogBackups)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should do some validations on the request first? Like make sure MaxLogBackups is not empty and not smaller than 0?

We have a couple Validate() functions in the code to check the content of the requests. You can take inspiration (copy paste 😄 )

Copy link
Member

Choose a reason for hiding this comment

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

we should make it an uint, that's going to be granted that is 0 or greater

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

func (m *Messenger) SetCustomNodes(request *requests.SetCustomNodes) error {
return nodecfg.SetWakuV2CustomNodes(m.database, request.CustomNodes)
}

func (m *Messenger) SaveNewWakuNode(request *requests.SaveNewWakuNode) error {
return nodecfg.SaveNewWakuNode(m.database, request.NodeAddress)
Copy link
Member

Choose a reason for hiding this comment

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

Same thing here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a fix.

I think it's a general check and we shouldn't be testing these here:

peer.AddrInfoFromP2pAddr
addr.ValueForProtocol

@igor-sirotin
Copy link
Contributor

igor-sirotin commented May 29, 2024

@friofry, can you please add a test for the new functions?

This doesn't look good 🙂

image

package requests

type SaveNewWakuNode struct {
NodeAddress string `json:"nodeAddress"`
Copy link
Member

Choose a reason for hiding this comment

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

you want to validate this most likely

@jrainville
Copy link
Member

@friofry I think you forgot to push. There were no new changes

@friofry friofry force-pushed the ab/issue-12918-setting-update-with-diffs branch from 3fcf2ec to 5598aa1 Compare May 29, 2024 18:44
@friofry
Copy link
Contributor Author

friofry commented May 29, 2024

@friofry, can you please add a test for the new functions?

This doesn't look good 🙂

image

Hey @igor-sirotin
It's hard to have 50% tests here because most of the functions either call other functions or insert something into the db.
I'll add a test for the Validate() function.

@friofry
Copy link
Contributor Author

friofry commented May 29, 2024

@friofry I think you forgot to push. There were no new changes

Yes, my mistake, it should be pushed now

@friofry
Copy link
Contributor Author

friofry commented May 29, 2024

@friofry, can you please add a test for the new functions?

This doesn't look good 🙂

image

Added TestMessengerValidateRequestSuite

@igor-sirotin
Copy link
Contributor

igor-sirotin commented May 29, 2024

It's hard to have 50% tests

I don't mean that it should be 50. I mean it shouldn't be 0 😄
The 50% check is not required yet 🙂

We discussed your PR today with the Snow Blowers crew, as a good example of when 50% threshold might not be reached because most of the added code is some wrapper functions. We're aware of this and We will exclude such API files from calculation for test coverage.


Nevertheless, it's not expected to cover the 50% threshold now, my comment is actually about the ... insert something into db. This must be covered by tests.

We have many persistence_test.go files in our codebase, you can take take ActivityCenterPersistenceTestSuite as an example.

@friofry friofry requested a review from jrainville May 30, 2024 05:55
@friofry
Copy link
Contributor Author

friofry commented May 30, 2024

It's hard to have 50% tests

I don't mean that it should be 50. I mean it shouldn't be 0 😄 The 50% check is not required yet 🙂

We discussed your PR today with the Snow Blowers crew, as a good example of when 50% threshold might not be reached because most of the added code is some wrapper functions. We're aware of this and We will exclude such API files from calculation for test coverage.

Nevertheless, it's not expected to cover the 50% threshold now, my comment is actually about the ... insert something into db. This must be covered by tests.

We have many persistence_test.go files in our codebase, you can take take ActivityCenterPersistenceTestSuite as an example.

Now I got it, thanks for the example! I'll add a test for all these "direct" settings updaters

@friofry friofry force-pushed the ab/issue-12918-setting-update-with-diffs branch from 230f96d to cdb936d Compare May 30, 2024 11:12
@friofry
Copy link
Contributor Author

friofry commented May 30, 2024

We have many persistence_test.go files in our codebase, you can take take ActivityCenterPersistenceTestSuite as an example.

Done 👍 Added node_config_persistence_test.go
Writing small tests is rewarding. Found out that we shouldn't call these methods until the database is initialised for the first time

Copy link
Contributor

@igor-sirotin igor-sirotin left a comment

Choose a reason for hiding this comment

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

Thanks for the test, looks good! 👍
Left a few minor suggestions

}

func (s *MessengerValidateRequestSuite) TestSaveNewWakuNodeRequestValidate_Enrtree() {
alice := s.newMessenger()
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. You can reuse m from MessengerBaseTestSuite
  2. IF that one is not enough and you need to create another messenger instance, then use newTestMessenger

protocol/messenger_validate_requests_test.go Outdated Show resolved Hide resolved
Comment on lines 24 to 25
var testWakuNodeEnrtree = "enrtree://AL65EKLJAUXKKPG43HVTML5EFFWEZ7L4LOKTLZCLJASG4DSESQZEC@prod.status.nodes.status.im"
var testWakuNodeMultiaddr = "/ip4/127.0.0.1/tcp/34012"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
var testWakuNodeEnrtree = "enrtree://AL65EKLJAUXKKPG43HVTML5EFFWEZ7L4LOKTLZCLJASG4DSESQZEC@prod.status.nodes.status.im"
var testWakuNodeMultiaddr = "/ip4/127.0.0.1/tcp/34012"
const (
testWakuNodeEnrtree = "enrtree://AL65EKLJAUXKKPG43HVTML5EFFWEZ7L4LOKTLZCLJASG4DSESQZEC@prod.status.nodes.status.im"
testWakuNodeMultiaddr = "/ip4/127.0.0.1/tcp/34012"
)

Comment on lines 32 to 34
config, err := nodecfg.GetNodeConfigFromDB(s.db)
s.Require().NoError(err)
s.config = config
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
config, err := nodecfg.GetNodeConfigFromDB(s.db)
s.Require().NoError(err)
s.config = config
s.config, err = nodecfg.GetNodeConfigFromDB(s.db)
s.Require().NoError(err)

@friofry friofry force-pushed the ab/issue-12918-setting-update-with-diffs branch 4 times, most recently from 054e5b3 to 721896d Compare June 4, 2024 14:28
* add waku nodeaddr and max log backups validation
* Allow to set new waku node
* Allow to set custom max backups
* add tests
@friofry friofry force-pushed the ab/issue-12918-setting-update-with-diffs branch from 721896d to d2d463b Compare June 4, 2024 14:49
@friofry friofry merged commit fe25d97 into develop Jun 4, 2024
10 checks passed
@friofry friofry deleted the ab/issue-12918-setting-update-with-diffs branch June 4, 2024 15:52
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.

Do not modify the node configuration directly
5 participants