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

DAOS-10028 client: Add Go bindings for libdaos (Pool) #15659

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mjmac
Copy link
Contributor

@mjmac mjmac commented Dec 22, 2024

Start the work of converting the raw cgo in the daos
tool into proper Go bindings for libdaos. This patch
covers pool functionality and adds some new infrastructure
common to both pools and containers.

Features: daos_cmd pool
Required-githooks: true
Signed-off-by: Michael MacDonald [email protected]

Copy link

Ticket title is 'Update golang binding for the DAOS API'
Status is 'In Progress'
Labels: 'SODACODE2022'
https://daosio.atlassian.net/browse/DAOS-10028

@mjmac mjmac force-pushed the mjmac/DAOS-10028-pool branch from 20e923c to 68a15e1 Compare December 22, 2024 01:09
@daosbuild1
Copy link
Collaborator

Test stage Build RPM on EL 9 completed with status FAILURE. https://build.hpdd.intel.com//job/daos-stack/job/daos/view/change-requests/job/PR-15659/2/execution/node/345/log

@daosbuild1
Copy link
Collaborator

Test stage Build RPM on EL 8 completed with status FAILURE. https://build.hpdd.intel.com//job/daos-stack/job/daos/view/change-requests/job/PR-15659/2/execution/node/346/log

@daosbuild1
Copy link
Collaborator

Test stage Build RPM on Leap 15.5 completed with status FAILURE. https://build.hpdd.intel.com//job/daos-stack/job/daos/view/change-requests/job/PR-15659/2/execution/node/337/log

@daosbuild1
Copy link
Collaborator

Test stage Build DEB on Ubuntu 20.04 completed with status FAILURE. https://build.hpdd.intel.com//job/daos-stack/job/daos/view/change-requests/job/PR-15659/2/execution/node/340/log

@daosbuild1
Copy link
Collaborator

@daosbuild1
Copy link
Collaborator

Test stage Build on Leap 15.5 with Intel-C and TARGET_PREFIX completed with status FAILURE. https://build.hpdd.intel.com//job/daos-stack/job/daos/view/change-requests/job/PR-15659/2/execution/node/508/log

@mjmac mjmac force-pushed the mjmac/DAOS-10028-pool branch 2 times, most recently from 785f5c7 to d94cc38 Compare December 22, 2024 16:02
@daosbuild1
Copy link
Collaborator

Test stage Functional Hardware Large completed with status FAILURE. https://build.hpdd.intel.com//job/daos-stack/job/daos/view/change-requests/job/PR-15659/4/execution/node/1483/log

@daosbuild1
Copy link
Collaborator

Test stage Functional Hardware Large completed with status FAILURE. https://build.hpdd.intel.com//job/daos-stack/job/daos/view/change-requests/job/PR-15659/5/execution/node/544/log

@daosbuild1
Copy link
Collaborator

Test stage Functional Hardware Medium completed with status FAILURE. https://build.hpdd.intel.com//job/daos-stack/job/daos/view/change-requests/job/PR-15659/5/execution/node/560/log

@mjmac mjmac force-pushed the mjmac/DAOS-10028-pool branch 2 times, most recently from 5a76de4 to 628f3ce Compare December 28, 2024 00:03
@daosbuild1
Copy link
Collaborator

Test stage NLT on EL 8.8 completed with status UNSTABLE. https://build.hpdd.intel.com/job/daos-stack/job/daos//view/change-requests/job/PR-15659/7/testReport/

@mjmac mjmac force-pushed the mjmac/DAOS-10028-pool branch 2 times, most recently from 510d64b to 90ef6d7 Compare December 28, 2024 18:58
@daosbuild1
Copy link
Collaborator

Test stage Functional Hardware Large completed with status FAILURE. https://build.hpdd.intel.com//job/daos-stack/job/daos/view/change-requests/job/PR-15659/9/execution/node/1405/log

@daosbuild1
Copy link
Collaborator

Test stage Functional Hardware Medium completed with status FAILURE. https://build.hpdd.intel.com//job/daos-stack/job/daos/view/change-requests/job/PR-15659/9/execution/node/1415/log

@mjmac mjmac force-pushed the mjmac/DAOS-10028-pool branch from 90ef6d7 to ad55ebd Compare December 31, 2024 12:32
@mjmac mjmac force-pushed the mjmac/DAOS-10028-pool branch 7 times, most recently from 6d9b688 to 5f28018 Compare January 13, 2025 23:04
@mjmac mjmac force-pushed the mjmac/DAOS-10028-pool branch 2 times, most recently from 7a1ccde to aae584f Compare January 17, 2025 21:24
@mjmac mjmac force-pushed the mjmac/DAOS-10028-pool branch from aae584f to cf8ef8a Compare January 17, 2025 22:59
Start the work of converting the raw cgo in the daos
tool into proper Go bindings for libdaos. This patch
covers pool functionality and adds some new infrastructure
common to both pools and containers.

Features: daos_cmd
Required-githooks: true
Signed-off-by: Michael MacDonald <[email protected]>
@mjmac mjmac force-pushed the mjmac/DAOS-10028-pool branch from cf8ef8a to 9b0d824 Compare January 17, 2025 23:01
@mjmac mjmac marked this pull request as ready for review January 18, 2025 16:36
@mjmac mjmac requested review from a team as code owners January 18, 2025 16:36
@mjmac mjmac self-assigned this Jan 18, 2025
@mjmac
Copy link
Contributor Author

mjmac commented Jan 18, 2025

Note to reviewers... Yeah, this is big. It's the first of several patches, though, and contains a lot of the infrastructure needed to start the change over to using the client API instead of raw cgo in the daos tool. There is no new functionality here, and my focus will be on maintaining parity with the existing implementation for now. Most of the "new" code is just the existing cgo moved over into the API, along with extensive unit tests. Imagine that, unit tests!

For context, this is the first follow-on PR (still a WIP): #15721

Features: daos_cmd
Required-githooks: true
Signed-off-by: Michael MacDonald <[email protected]>
@daosbuild1
Copy link
Collaborator

Test stage NLT on EL 8.8 completed with status UNSTABLE. https://build.hpdd.intel.com/job/daos-stack/job/daos//view/change-requests/job/PR-15659/23/testReport/

@mjmac mjmac requested review from tanabarr, kjacque and knard38 January 29, 2025 12:53
@mjmac
Copy link
Contributor Author

mjmac commented Jan 29, 2025

If it's helpful, it may be easiest to focus on the changes to the daos command specifically, e.g.

Starting with those changes should give reviewers a sense of how the new API works, e.g.

	-poolInfo, err := queryPool(cmd.cPoolHandle, queryMask)
	+poolInfo, err := cmd.pool.Query(cmd.MustLogCtx(), queryMask)

The code under lib/daos/api is mostly not new, just moved from the tool and made unit-testable via a mocking framework.

Copy link
Contributor

@kjacque kjacque left a comment

Choose a reason for hiding this comment

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

A nice cleanup overall. I do find myself worrying about the rapidly-expanding stubs, though. I'm also curious how people are supposed to mock the API without the stubs, given that they are functions and not interfaces.

Comment on lines +51 to +52
/*case contAttr:
rc = daos_cont_list_attr(hdl, nil, &totalSize, nil)*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be enabled? Or removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was code moved over from the tool... The next PR (#15721) migrates a lot of the container logic into the API, and these are uncommented.

Comment on lines +72 to +73
/*case contAttr:
rc = daos_cont_list_attr(hdl, (*C.char)(buf), &totalSize, nil)*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question

Comment on lines +128 to +129
/*case contAttr:
rc = daos_cont_get_attr(hdl, C.int(numAttr), &attrNames[0], nil, &attrSizes[0], nil)*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question -- if these are being left as placeholders, it would be better to add a TODO with a ticket number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Next PR (#15721) is coming in hot right behind this one. :) Trying to make them a little easier to review in chunks.

Comment on lines +204 to +205
// Next, create a slice of C.size_t entries to hold the sizes of the values,
// and a slice of pointers to the actual values.
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason this step couldn't be done at the same time as the previous one? I understand why we couldn't do that for the getter, but the setter should be able to build all of these arrays at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code has been working as-is for a couple of years now. My inclination is to get it all moved inside the API with proper unit tests first, and then work on cleaning up inefficiencies with confidence that the unit tests will find any mistakes.

// this handle -- use of this method should be discouraged as
// it is provided for compatibility with older code that calls
// into libdaos directly.
func (ch *connHandle) FillHandle(cHandle unsafe.Pointer) error {
Copy link
Contributor

@kjacque kjacque Feb 1, 2025

Choose a reason for hiding this comment

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

The caller is a CGo function, right? Any reason cHandle shouldn't explicitly be a *C.daos_handle_t?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, this function is for users outside of the API boundary (e.g. the daos tool). Can't use C types in public function signatures. Eventually we should be able to remove this entirely once the API is complete and all of the tool code is cleaned up.

Comment on lines +20 to +21
// Long-term, this should be phased out as API users should mock
// the API instead of relying on the stubs.
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO we probably need a task to change any existing code at the higher level so people don't imitate it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good point. I see these as temporary scaffolding for the construction of the API. I'll update the comment to make that more explicit.

Comment on lines +92 to +99
/*static inline uint32_t
get_rebuild_state(struct daos_rebuild_status *drs)
{
if (drs == NULL)
return 0;

return drs->rs_state;
}*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I think that's cruft that I missed. I'll remove it if I need to make changes to this PR, or in the next one.

@mjmac
Copy link
Contributor Author

mjmac commented Feb 1, 2025

A nice cleanup overall. I do find myself worrying about the rapidly-expanding stubs, though.

I really don't see a better way to make the code testable, but I'm open to suggestions. Personally, I think it's fine for the long term because all of the stub stuff should eventually be hidden behind the API, so API users and external tests don't need to deal with them.

I'm also curious how people are supposed to mock the API without the stubs, given that they are functions and not interfaces.

I was thinking about this the other day. I started playing around with the api.Provider thing when I added the health check stuff. One option would be to expand that to include methods for all of the API functions. At the moment, though, I think that would be a maintenance headache.

I think a better way to do this is to delegate mocking to users of the API. So, e.g. out in the daos tool we can define interfaces for the parts of the API that we want to stub, and just create wrappers to implement those interfaces. This seems like a more maintainable and cleaner solution. I think it will be clearer as more of the tool code is moved into the API, and the code that remains under cmd/daos is mostly presentation layer, which means that the tests and stubs should be pretty simple.

There's already some precedent for this kind of thing in the http.HandlerFunc pattern. Basically you can wrap a function in a struct with a method to implement an interface. We use it in the server: https://github.com/daos-stack/daos/blob/master/src/control/server/server_utils.go#L692

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants