Git Product home page Git Product logo

Comments (7)

CyberDem0n avatar CyberDem0n commented on July 22, 2024

I have a big experience of working with all projects mentioned above and I think approaches used by these projects are fine (they are solving it's purpose). The only difference with gRPC is that they had implement response object on their own (except python-consul, they simply used dict for that :)) due to protocol nature (kazoo is using binary protocol on very low level and python-etcd and python-consul are working with JSON).

Our situation is better (I think), because grpcio-tools already did a lot of work for us and classes are available for usage. Some of them could be used as it is, others make sense to inherit (and extend) and only in a few cases we need to implement something new.

from python-etcd3.

kragniz avatar kragniz commented on July 22, 2024

My current thought is to borrow from kazoo's api design, but make the stat optional. Something like:

>>> etcd.get("/key")
b"some-value"
>>> value, stat = etcd.get("/key", stat=True)

This keeps the basic api simple to use, but allows for access to the extra metadata if it's required. Having a function that changes its return type based of parameters is a little ugly, though.

from python-etcd3.

CyberDem0n avatar CyberDem0n commented on July 22, 2024

Having a function that changes its return type based of parameters is a little ugly, though.

Yes, it is very ugly...
And don't forget that together with key metadata we also need cluster-wide metadata (especially ResponseHeader.revision).
If the key hasn't been updated very long time watch on mod_revision will fail because history was already compacted, but if you use ResponseHeader.revision for that it will work fine.
In this sense python-etcd approach looks more sane, but the difference is - we don't have a tree structure anymore, so we will not have a root element and children, but only children (list).
And for the sanity it should remain list even for a single result. The only difference must be - if the single key was requested and it is not there - raise an exception.

from python-etcd3.

Lukasa avatar Lukasa commented on July 22, 2024

Why not simply always return the metadata? Users who don't want it can always indicate that they don't care by saying data, _ = etcd.get('/key').

Alternatively, have two separate functions: get and get_with_metadata. If a user decides they now need the metadata, they can simply change their function call to get it. Both options avoid the need to have return types that change based on context.

from python-etcd3.

kragniz avatar kragniz commented on July 22, 2024

@Lukasa you make a good point, it's not much extra effort to just throw away the extra data.

from python-etcd3.

CyberDem0n avatar CyberDem0n commented on July 22, 2024

@kragniz, I've noticed that you started implementing it, but you forgot one important thing:

together with key metadata we also need cluster-wide metadata (especially
ResponseHeader.revision). If the key hasn't been updated very long time, watch
on mod_revision will fail because history was already compacted. But, if you use
ResponseHeader.revision for that it will work fine.

I have experience of working with all three libraries mentioned above in the Patroni project. In order to implement everything reliable I had to override some of the methods and classes of original projects, therefore I am really familiar not only with their API but with internals as well.

from python-etcd3.

kragniz avatar kragniz commented on July 22, 2024

@CyberDem0n hang on, it's not finished yet!

from python-etcd3.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.