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

roles: introduce role for http servers #197

Merged
merged 2 commits into from
Sep 12, 2024

Conversation

DerekBum
Copy link
Contributor

@DerekBum DerekBum commented Sep 5, 2024

This patch adds roles.http_server. This role allows to configurate one or more HTTP servers. Those servers could be reused by several other roles.

Servers could be accessed by their names (from the config).

get_server(name) method returns a server by its name. If nil is passed, default server is returned. The server is default, if it has DEFAULT_SERVER_NAME ("default") as a name.

This patch also adds a httpd:delete(name) method to delete named routes.

Closes #196

@DerekBum DerekBum force-pushed the DerekBum/gh-196-add-http-role branch 5 times, most recently from a9c76da to 0c6784e Compare September 5, 2024 17:32
Copy link
Member

@DifferentialOrange DifferentialOrange left a comment

Choose a reason for hiding this comment

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

Thank you for the patch! I think we may improve it in a couple of ways.

roles/http.lua Outdated Show resolved Hide resolved
roles/http.lua Outdated Show resolved Hide resolved
roles/http.lua Outdated Show resolved Hide resolved
roles/http.lua Outdated Show resolved Hide resolved
http-scm-1.rockspec Outdated Show resolved Hide resolved
roles/http.lua Outdated Show resolved Hide resolved
test/unit/http_role_test.lua Outdated Show resolved Hide resolved
roles/http.lua Outdated Show resolved Hide resolved
@oleg-jukovec
Copy link
Contributor

Let's also add a public API call for this functionality in the scope of the task, so that there is no need to access internal structures directly:

https://github.com/tarantool/metrics-export-role/blob/36130b73c0a5975ff26f0c26f78ee7a368c1207b/roles/metrics-export.lua#L26-L37

@DerekBum DerekBum force-pushed the DerekBum/gh-196-add-http-role branch 11 times, most recently from 04cfd9b to 246dc67 Compare September 7, 2024 17:32
@DerekBum
Copy link
Contributor Author

DerekBum commented Sep 7, 2024

Updated the PR according to the comments.

README.md Outdated Show resolved Hide resolved
roles/http_server.lua Outdated Show resolved Hide resolved
@DerekBum DerekBum force-pushed the DerekBum/gh-196-add-http-role branch 8 times, most recently from dcf425f to d410fae Compare September 9, 2024 12:12
@DerekBum DerekBum force-pushed the DerekBum/gh-196-add-http-role branch 3 times, most recently from 6eb9a58 to 54efff0 Compare September 9, 2024 17:52
@DerekBum
Copy link
Contributor Author

DerekBum commented Sep 9, 2024

CI is finally green, all comments are fixed.

.github/workflows/test.yml Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
deps.sh Show resolved Hide resolved
deps.sh Outdated Show resolved Hide resolved
@DerekBum DerekBum force-pushed the DerekBum/gh-196-add-http-role branch 8 times, most recently from c4036a9 to 2e3dbd2 Compare September 10, 2024 14:11
@DerekBum
Copy link
Contributor Author

Updated the PR according to comments.

Copy link
Contributor

@oleg-jukovec oleg-jukovec left a comment

Choose a reason for hiding this comment

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

Thank you for the patch, just few non-critical notes.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
### Added

- `roles.httpd` role to configure one or more HTTP servers (#196)
- `httpd:delete(name)` method to delete named routes (#197)
Copy link
Member

Choose a reason for hiding this comment

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

I have never seen anyone using name option for a route. Until now, I didn't know it even exists. As far as I understand, it actually works not only with named routes, but with unnamed ones as well by using path as a key?

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, we can't use just path. Routes are stored as opts (which is a table of many fields, some of them are filled inside of add_route function).

http/http/server.lua

Lines 1248 to 1259 in 2e3dbd2

if opts.name ~= nil then
if opts.name == 'current' then
error("Route can not have name 'current'")
end
if self.iroutes[ opts.name ] ~= nil then
errorf("Route with name '%s' is already exists", opts.name)
end
table.insert(self.routes, opts)
self.iroutes[ opts.name ] = #self.routes
else
table.insert(self.routes, opts)
end

And those opts stored in the map with the name as a key. If there are no name, then we can't get opts.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it is. It uses name, BUT we could delete a route by path too. I don't see any problems.

Copy link
Contributor

@oleg-jukovec oleg-jukovec Sep 11, 2024

Choose a reason for hiding this comment

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

The only problem is to create a nice and non-confusing API for the call. Maybe:

httpd:delete(path, name)
httpd:delete(path)
httpd:delete(nil, name)

But it looks a little strange.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it is. It uses name, BUT we could delete a route by path too. I don't see any problems.

I'm not sure, but as far as I remember that httpd has that weird thing that allows to set multiple handlers on the same route since route is not a unique identificator (and only one of handlers will be invoked).

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
.github/workflows/test.yml Show resolved Hide resolved
README.md Show resolved Hide resolved
roles/httpd.lua Outdated Show resolved Hide resolved
test/integration/httpd_role_test.lua Show resolved Hide resolved
test/integration/httpd_role_test.lua Outdated Show resolved Hide resolved
@DerekBum DerekBum force-pushed the DerekBum/gh-196-add-http-role branch 2 times, most recently from 5a16f8a to ab288f1 Compare September 11, 2024 13:07
@DerekBum
Copy link
Contributor Author

Updated everything according to comments.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
roles/CMakeLists.txt Outdated Show resolved Hide resolved
This patch adds `roles.httpd`. This role allows to configure one or
more HTTP servers. Those servers could be reused by several other roles.

Servers could be accessed by their names (from the config).

`get_server(name)` method returns a server by its name. If `nil` is passed,
default server is returned. The server is default, if it has
`DEFAULT_SERVER_NAME` (`"default"`) as a name.

Closes #196
This patch adds a `httpd:delete(name)` method to delete
named routes.
@DerekBum
Copy link
Contributor Author

Updated everything according to comments.

### Added

- `roles.httpd` role to configure one or more HTTP servers (#196)
- `httpd:delete(name)` method to delete named routes (#197)
Copy link
Member

Choose a reason for hiding this comment

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

Yes, it is. It uses name, BUT we could delete a route by path too. I don't see any problems.

I'm not sure, but as far as I remember that httpd has that weird thing that allows to set multiple handlers on the same route since route is not a unique identificator (and only one of handlers will be invoked).

@oleg-jukovec oleg-jukovec merged commit 125263a into master Sep 12, 2024
34 checks passed
@oleg-jukovec oleg-jukovec deleted the DerekBum/gh-196-add-http-role branch September 12, 2024 09:35
oleg-jukovec added a commit that referenced this pull request Sep 13, 2024
The release introduces a role for Tarantool 3.

Fixed

- Fixed request crash with empty body and unexpected header
  Content-Type (#189).

Added

- `roles.httpd` role to configure one or more HTTP servers (#196).
- `httpd:delete(name)` method to delete named routes (#197).
@oleg-jukovec oleg-jukovec mentioned this pull request Sep 13, 2024
oleg-jukovec added a commit that referenced this pull request Sep 13, 2024
The release introduces a role for Tarantool 3.

Fixed

- Fixed request crash with empty body and unexpected header
  Content-Type (#189).

Added

- `roles.httpd` role to configure one or more HTTP servers (#196).
- `httpd:delete(name)` method to delete named routes (#197).
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.

Introduce server setup through Tarantool 3 role
3 participants