Skip to content
This repository was archived by the owner on Mar 24, 2021. It is now read-only.

Conversation

rduplain
Copy link
Contributor

@rduplain rduplain commented Aug 7, 2015

Without this change, an exception in the kafka connection results in just Unable to connect to a broker to fetch metadata. without any information about the error. An alternative to this would be to pass the exception object to the log.exception call, but re-raising the exception puts the user code in control.

@yungchin
Copy link
Contributor

yungchin commented Aug 7, 2015

It looks like there's another small change in behaviour with this: if you fail to connect to a provided seed host, this no longer tries the next host (if more than one was provided), but excepts immediately. I'm not sure if that's a real objection: if you provide a bad host and a good one, you might as well hear about the bad one. But if we want to keep the old behaviour, something with a for ... else might do?

In any case, I'm with you in preferring to put user code in control here.

@yungchin
Copy link
Contributor

yungchin commented Aug 7, 2015

And one second thought, I'm also really bikeshedding here. This makes sense as-is.

@rduplain
Copy link
Contributor Author

rduplain commented Aug 7, 2015

I don't think that's bike-shedding; you are raising an important point. Is the goal of _get_metadata to talk to a broker or all brokers. The patch here is the latter, but it looks like the client need only talk to one broker, which means that the error should go into log.exception so that the programmer/user has feedback. It would help to have a specific exception, rather than Exception.

@yungchin
Copy link
Contributor

yungchin commented Aug 7, 2015

How about re-raising only after you fall off the end of the loop? That way you'd still inform user code directly.

@rduplain
Copy link
Contributor Author

rduplain commented Aug 7, 2015

How about re-raising only after you fall off the end of the loop? That way you'd still inform user code directly.

What should we do if we have multiple exceptions, i.e. different exceptions from different brokers?

@yungchin
Copy link
Contributor

yungchin commented Aug 7, 2015

I wouldn't know a really correct solution for that, but I suppose raising only the last one that occurred should be ok? If the user code deals with that problem and then retries, it should work because it can talk to at least the last broker.

And I guess the exceptions can still also be logged, so that if you did inspect the logs you could see all of them?

@rduplain
Copy link
Contributor Author

rduplain commented Aug 7, 2015

I propose passing each error to log.exception, then raising a RuntimeError instead of Exception.

@yungchin
Copy link
Contributor

yungchin commented Aug 7, 2015

Sounds good to me.

@rduplain
Copy link
Contributor Author

rduplain commented Aug 7, 2015

I propose passing each error to log.exception, then raising a RuntimeError instead of Exception.

The result of this proposal is less than ideal in my usecase. I'm connecting via streamparse (this might be an issue for that project), and the log message ends up in the logs directory instead of in the console, where a pykafka client is set in the initialization of a component.

@rduplain
Copy link
Contributor Author

rduplain commented Aug 7, 2015

I pushed a patch. This is ready if we all agree to the proposal.

@emmettbutler
Copy link
Contributor

Looks good to me. It's correct that this function should continue trying brokers until one succeeds or it's tried all of them.

@rduplain rduplain merged commit 5957c15 into master Aug 8, 2015
@rduplain rduplain deleted the dont-swallow-the-cap branch August 8, 2015 17:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants