Skip to content

Commit

Permalink
[#465] [#466] Management: All commands need to support JSON output
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperpedersen committed Nov 9, 2024
1 parent 7298300 commit d03a53d
Show file tree
Hide file tree
Showing 56 changed files with 5,809 additions and 3,746 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ jobs:
run: sudo apt update
- name: Install libev
run: sudo apt install -y libev4 libev-dev
- name: Install cJSON
run: sudo apt install -y libcjson1 libcjson-dev
- name: Install systemd
run: sudo apt install -y libsystemd-dev
- name: Install rst2man
run: sudo apt install -y python3-docutils
- name: Install zstd
run: sudo apt install -y libzstd-dev
- name: Install lz4
run: sudo apt install -y liblz4-dev
- name: Install graphviz
run: sudo apt install graphviz
- name: Install doxygen
Expand Down Expand Up @@ -113,8 +115,10 @@ jobs:
run: brew install openssl
- name: Install libev
run: brew install libev
- name: Install cJSON
run: brew install cjson
- name: Install zstd
run: brew install libzstd
- name: Install lz4
run: brew install liblz4
- name: Install rst2man
run: brew install docutils
- name: Install graphviz
Expand Down
37 changes: 28 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,34 @@ if(NOT COMPILER_SUPPORTS_C17)
message(FATAL_ERROR "The compiler ${CMAKE_C_COMPILER} has no C17 support. Please use a different C compiler.")
endif()

find_package(ZLIB)
if (ZLIB_FOUND)
message(STATUS "zlib found")
else ()
message(FATAL_ERROR "zlib needed")
endif()

find_package(BZip2)
if (BZIP2_FOUND)
message(STATUS "bzip2 found")
else ()
message(FATAL_ERROR "bzip2 needed")
endif()

find_package(Zstd)
if (ZSTD_FOUND)
message(STATUS "zstd found")
else ()
message(FATAL_ERROR "zstd needed")
endif()

find_package(Lz4)
if (LZ4_FOUND)
message(STATUS "lz4 found")
else ()
message(FATAL_ERROR "lz4 needed")
endif()

find_package(Libev 4.11)
if (LIBEV_FOUND)
message(STATUS "libev found")
Expand Down Expand Up @@ -87,15 +115,6 @@ else ()
message(FATAL_ERROR "pthread needed")
endif()

# search for cJSON library
# <https://github.com/DaveGamble/cJSON>
find_package(cJSON)
if (cJSON_FOUND)
message(STATUS "cJSON found version ${CJSON_VERSION}")
else ()
message(FATAL_ERROR "cJSON needed")
endif()

find_package(Pandoc)
if (PANDOC_FOUND)
message(STATUS "pandoc found")
Expand Down
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ See [Architecture](./doc/ARCHITECTURE.md) for the architecture of [**pgagroal**]
* [systemd](https://www.freedesktop.org/wiki/Software/systemd/)
* [rst2man](https://docutils.sourceforge.io/)
* [libatomic](https://gcc.gnu.org/wiki/Atomic)
* [cJSON](https://github.com/DaveGamble/cJSON)
* [zlib](https://zlib.net)
* [zstd](http://www.zstd.net)
* [lz4](https://lz4.github.io/lz4/)
* [bzip2](http://sourceware.org/bzip2/)

On Rocky Linux (and similar) operating systems, the dependencies
can be installed via `dnf(8)` as follows:
Expand All @@ -77,8 +80,11 @@ dnf install git gcc cmake make \
openssl openssl-devel \
systemd systemd-devel \
python3-docutils \
libatomic \
cjson cjson-devel
libatomic \
zlib zlib-devel \
libzstd libzstd-devel \
lz4 lz4-devel \
bzip2 bzip2-devel
```

Please note that, on Rocky Linux, in order to install the `python3-docutils`
Expand Down
21 changes: 21 additions & 0 deletions cmake/FindLz4.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# LZ4 Support
#

find_path(LZ4_INCLUDE_DIR
NAMES lz4.h
)
find_library(LZ4_LIBRARY
NAMES lz4
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Lz4 DEFAULT_MSG
LZ4_LIBRARY LZ4_INCLUDE_DIR)

if(LZ4_FOUND)
set(LZ4_LIBRARIES ${LZ4_LIBRARY})
set(LZ4_INCLUDE_DIRS ${LZ4_INCLUDE_DIR})
endif()

mark_as_advanced(LZ4_INCLUDE_DIR LZ4_LIBRARY)
21 changes: 21 additions & 0 deletions cmake/FindZstd.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# ZSTD support
#

find_path(ZSTD_INCLUDE_DIR
NAMES zstd.h
)
find_library(ZSTD_LIBRARY
NAMES zstd
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Zstd REQUIRED_VARS
ZSTD_LIBRARY ZSTD_INCLUDE_DIR)

if(ZSTD_FOUND)
set(ZSTD_LIBRARIES ${ZSTD_LIBRARY})
set(ZSTD_INCLUDE_DIRS ${ZSTD_INCLUDE_DIR})
endif()

mark_as_advanced(ZSTD_INCLUDE_DIR ZSTD_LIBRARY)
51 changes: 0 additions & 51 deletions cmake/FindcJSON.cmake

This file was deleted.

55 changes: 40 additions & 15 deletions doc/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,51 @@ The memory interface is defined in [memory.h](../src/include/memory.h) ([memory.

## Management

[**pgagroal**](https://github.com/agroal/pgagroal) has a management interface which serves two purposes.
`pgagroal` has a management interface which defines the administrator abilities that can be performed when it is running.
This include for example taking a backup. The `pgagroal-cli` program is used for these operations ([cli.c](../src/cli.c)).

First, it defines the administrator abilities that can be performed on the pool when it is running. This include
for example flushing the pool. The `pgagroal-cli` program is used for these operations ([cli.c](../src/cli.c)).
The management interface is defined in [management.h](../src/include/management.h). The management interface
uses its own protocol which uses JSON as its foundation.

Second, the interface is used internally to transfer the connection (socket descriptor) from the child process
to the main [**pgagroal**](https://github.com/agroal/pgagroal) process after a new connection has been created. This is necessary since the socket descriptor
needs to be available to subsequent client and hence processes.
### Write

The management interface use Unix Domain Socket for communication.
The client sends a single JSON string to the server,

The management interface is defined in [management.h](../src/include/management.h). The management interface
uses its own protocol which always consist of a header
| Field | Type | Description |
| :------------ | :----- | :------------------------------ |
| `compression` | uint8 | The compression type |
| `encryption` | uint8 | The encryption type |
| `length` | uint32 | The length of the JSON document |
| `json` | String | The JSON document |

The server sends a single JSON string to the client,

| Field | Type | Description |
| :------------ | :----- | :------------------------------ |
| `compression` | uint8 | The compression type |
| `encryption` | uint8 | The encryption type |
| `length` | uint32 | The length of the JSON document |
| `json` | String | The JSON document |

### Read

The server sends a single JSON string to the client,

| Field | Type | Description |
| :------------ | :----- | :------------------------------ |
| `compression` | uint8 | The compression type |
| `encryption` | uint8 | The encryption type |
| `length` | uint32 | The length of the JSON document |
| `json` | String | The JSON document |

| Field | Type | Description |
|------------|------|-------------|
| `id` | Byte | The identifier of the message type |
| `slot` | Int | The slot that the message is for |
The client sends to the server a single JSON documents,

The rest of the message is depending on the message type.
| Field | Type | Description |
| :------------ | :----- | :------------------------------ |
| `compression` | uint8 | The compression type |
| `encryption` | uint8 | The encryption type |
| `length` | uint32 | The length of the JSON document |
| `json` | String | The JSON document |

### Remote management

Expand Down Expand Up @@ -245,7 +270,7 @@ However, some configuration settings requires a full restart of [**pgagroal**](h
* Limit rules defined by `pgagroal_databases.conf`
* TLS rules defined by server section

The configuration can also be reloaded using `pgagroal-cli -c pgagroal.conf reload`. The command is only supported
The configuration can also be reloaded using `pgagroal-cli -c pgagroal.conf conf reload`. The command is only supported
over the local interface, and hence doesn't work remotely.

## Prometheus
Expand Down
6 changes: 3 additions & 3 deletions doc/DEVELOPERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dnf install postgresql-server
#### Basic dependencies

``` sh
dnf install git gcc cmake make libev libev-devel openssl openssl-devel systemd systemd-devel python3-docutils libatomic cjson cjson-devel
dnf install git gcc cmake make libev libev-devel openssl openssl-devel systemd systemd-devel python3-docutils libatomic zlib zlib-devel libzstd libzstd-devel lz4 lz4-devel bzip2 bzip2-devel
```

#### Generate user and developer guide
Expand Down Expand Up @@ -257,10 +257,10 @@ pgagroal -c pgagroal.conf -a pgagroal_hba.conf
psql -h localhost -p 2345 -U myuser mydb
```
#### Stop pgagroal
#### Shutdown pgagroal
``` sh
pgagroal-cli -c pgagroal.conf stop
pgagroal-cli -c pgagroal.conf shutdown
```
## Basic git guide
Expand Down
10 changes: 5 additions & 5 deletions doc/man/pgagroal-admin.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ COMMANDS
master-key
Create or update the master key. The master key will be created in the pgagroal user home directory under ~/.pgagroal

add-user
user add
Add a user

update-user
user edit
Update a user

remove-user
Remove a user
user del
Delete a user

list-users
user ls
List all users

REPORTING BUGS
Expand Down
12 changes: 9 additions & 3 deletions doc/manual/02-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,20 @@ We recommend using Fedora to test and run [**pgagroal**][pgagroal], but other Li
* [systemd](https://www.freedesktop.org/wiki/Software/systemd/)
* [rst2man](https://docutils.sourceforge.io/)
* [libatomic](https://gcc.gnu.org/wiki/Atomic)
* [cJSON](https://github.com/DaveGamble/cJSON)
* [zlib](https://zlib.net)
* [zstd](http://www.zstd.net)
* [lz4](https://lz4.github.io/lz4/)
* [bzip2](http://sourceware.org/bzip2/)

```sh
dnf install git gcc cmake make libev libev-devel \
openssl openssl-devel \
systemd systemd-devel \
python3-docutils libatomic \
cjson cjson-devel
zlib zlib-devel \
libzstd libzstd-devel \
lz4 lz4-devel \
bzip2 bzip2-devel
```

Alternative [clang 8+](https://clang.llvm.org/) can be used.
Expand Down Expand Up @@ -101,7 +107,7 @@ On FreeBSD, `pkg` is used instead of `dnf` or `yum`.
Use `pkg install <package name>` to install the following packages

``` sh
git gcc cmake libev openssl libssh py39-docutils libcjson
git gcc cmake libev openssl libssh py39-docutils
```

### Build
Expand Down
1 change: 0 additions & 1 deletion doc/manual/99-references.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
[openssl]: http://www.openssl.org/
[systemd]: https://www.freedesktop.org/wiki/Software/systemd/
[rst2man]: https://docutils.sourceforge.io/
[cjson]: https://github.com/DaveGamble/cJSON
[pandoc]: https://pandoc.org/
[pandoc_latex_template]: https://github.com/Wandmalfarbe/pandoc-latex-template
[texlive]: https://www.tug.org/texlive/
Expand Down
Loading

0 comments on commit d03a53d

Please sign in to comment.