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

feat(admin) sugar method to delete upstream target #2256

Merged
merged 4 commits into from
Mar 27, 2017
Merged

Conversation

p0pr0ck5
Copy link
Contributor

No description provided.

local target

before_each(function()
assert(helpers.dao.targets:insert {
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't an upstream be created here? reusing an existing one might interfere with the test results 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.

But it doesn't :)

My understanding of before_each means that it runs before each nested test, meaning that we recreate the upstream and shut down kong after every test. And actually, the anti-pattern that I used in the previous PR to create upstream3 is unnecessary as well.

Nevertheless, I'll add it.

balancer.clean_history(self.params.upstream_id, dao_factory)

-- this is just a wrapper around POSTing a new target with weight=0
local target = self.params
Copy link
Member

Choose a reason for hiding this comment

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

It would be more explicit to use self.upstream 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.

Hmm? self.params represents the target (a table with a target key), not an upstream.

Copy link
Member

Choose a reason for hiding this comment

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

self.params represents the request parameters, with modifications from the before handler.

I'd consider it cleaner to create a new target table here

local data, err = dao_factory.targets:insert( {
  target = params.target,
  upstream_id = self.upstream.id,
  weight = 0,
})

Then line 109 above can be dropped as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

wfm!

return app_helpers.yield_error(err)
end

return responses.send_HTTP_NO_CONTENT()
Copy link
Member

Choose a reason for hiding this comment

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

Wondering if we should not send HTTP 201 still here. Yes, this is a DELETE and stays consistent with the rest of the API, but it isn't a traditional DELETE endpoint. It is known that this is a sugar method. Might bring confusion, but might also raise awareness about targets. However, this is mostly internal implementation details, so probably good to hide it away.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think if we were to return 201 here, we might as well not bother with this method at all ;)

tbh, i dont even think this is a valid PR. I don't think adding this endpoint makes it any easier for consumers to work with the upstream/target interface. But that's just my $0.02 ;)

@thibaultcha thibaultcha added the pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. label Mar 25, 2017
@p0pr0ck5 p0pr0ck5 force-pushed the feat/delete-target branch from 8ca5ea3 to 830c95f Compare March 25, 2017 03:30
@p0pr0ck5 p0pr0ck5 added pr/status/needs review and removed pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. labels Mar 25, 2017
" removed ", tostring(cnt), " target entries")
end
end
balancer.clean_history(self.params.upstream_id, dao_factory)
Copy link
Member

Choose a reason for hiding this comment

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

I'm having doubts on whether we should be moving this code. So far (at least the way I see it) the code for the management api and the Kong runtime have remained fairly separate. By moving this code into the balancer module, we change that, as this code is strictly management api.

Not sure though...

@thibaultcha wat do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wasn't sure about the style of putting local functions in routes files, only reason I thought to put it in kong/core/balancer. Ill move it back :)

balancer.clean_history(self.params.upstream_id, dao_factory)

-- this is just a wrapper around POSTing a new target with weight=0
local target = self.params
Copy link
Member

Choose a reason for hiding this comment

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

self.params represents the request parameters, with modifications from the before handler.

I'd consider it cleaner to create a new target table here

local data, err = dao_factory.targets:insert( {
  target = params.target,
  upstream_id = self.upstream.id,
  weight = 0,
})

Then line 109 above can be dropped as well.

@p0pr0ck5 p0pr0ck5 force-pushed the feat/delete-target branch from 830c95f to a8b3170 Compare March 27, 2017 15:00
@Tieske Tieske added pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release) and removed pr/status/needs review labels Mar 27, 2017
@Tieske
Copy link
Member

Tieske commented Mar 27, 2017

As this is fully backward compatible, this could as well go in master imo, so it can be shipped with 0.10.1

@p0pr0ck5 p0pr0ck5 changed the base branch from next to master March 27, 2017 16:10
@p0pr0ck5
Copy link
Contributor Author

@Tieske that also brings in #2230, since this was based on that PR. if youre okay with that, ill merge these to master and back-merge to next

@Tieske Tieske added this to the 0.10.1 milestone Mar 27, 2017
@Tieske
Copy link
Member

Tieske commented Mar 27, 2017

tagged them both for milestone 0.10.1

@p0pr0ck5 p0pr0ck5 merged commit 0d461d7 into master Mar 27, 2017
@p0pr0ck5 p0pr0ck5 deleted the feat/delete-target branch March 27, 2017 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/ready (but hold merge) No more concerns, but do not merge yet (probably a conflict of interest with another PR or release)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants