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

Port schema to MySQL 5.7 / MariaDB 10.2 #203

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 77 additions & 1 deletion .github/workflows/tests_with_database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,77 @@ on:
pull_request: {}

jobs:
mysql:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
image:
- mysql:5.7
- mysql:8.0
- mysql:8
- mysql:latest
- mariadb:10.2
- mariadb:10.3
- mariadb:10.4
- mariadb:10.5
- mariadb:10.6
- mariadb:10
- mariadb:11.0
- mariadb:11.1
- mariadb:11.2
- mariadb:latest

env:
NOTIFICATIONS_TESTS_DB_TYPE: mysql
NOTIFICATIONS_TESTS_DB: notifications
NOTIFICATIONS_TESTS_DB_USER: root
NOTIFICATIONS_TESTS_DB_PASSWORD: notifications
NOTIFICATIONS_TESTS_DB_HOST: 127.0.0.1
NOTIFICATIONS_TESTS_DB_PORT: 3306

services:
mysql:
image: ${{ matrix.image }}
env:
MYSQL_ROOT_PASSWORD: ${{ env.NOTIFICATIONS_TESTS_DB_PASSWORD }}
MYSQL_DATABASE: ${{ env.NOTIFICATIONS_TESTS_DB }}
# Wait until MySQL becomes ready
options: >-
--health-cmd "${{ (startsWith(matrix.image, 'mysql:') || startsWith(matrix.image, 'mariadb:10')) && 'mysqladmin ping' || 'healthcheck.sh --connect --innodb_initialized' }}"
--health-interval 10s
--health-timeout 5s
--health-retries 10
ports:
- 3306:3306

steps:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: stable

- name: Checkout code
uses: actions/checkout@v4

- name: Importing Schema
run: >
mysql -h127.0.0.1 -u$NOTIFICATIONS_TESTS_DB_USER -p$NOTIFICATIONS_TESTS_DB_PASSWORD
$NOTIFICATIONS_TESTS_DB < ${{ github.workspace }}/schema/mysql/schema.sql

- name: Download dependencies
run: go get -v -t -d ./...

- name: Run tests
timeout-minutes: 10
# By default, multiple packages may be tested in parallel in different
# processes. Passing -p 1 reduces this to one process to prevent test
# cases in different packages from accessing the same database. Note
# that t.Parallel() only affects parallelism within one process, i.e.
# within the tests of one package.
run: go test -v -timeout 5m -p 1 ./...

postgresql:
name: PostgreSQL ${{ matrix.version }}
runs-on: ubuntu-latest
Expand Down Expand Up @@ -59,4 +130,9 @@ jobs:

- name: Run tests
timeout-minutes: 10
run: go test -v -timeout 5m ./...
# By default, multiple packages may be tested in parallel in different
# processes. Passing -p 1 reduces this to one process to prevent test
# cases in different packages from accessing the same database. Note
# that t.Parallel() only affects parallelism within one process, i.e.
# within the tests of one package.
run: go test -v -timeout 5m -p 1 ./...
10 changes: 1 addition & 9 deletions doc/02-Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,12 @@ or install [from source](02-Installation.md.d/From-Source.md).

## Setting up the Database

A MySQL (≥5.5), MariaDB (≥10.1), or PostgreSQL (≥9.6) database is required to run Icinga Notifications.
A MySQL (≥5.7.9), MariaDB (≥10.2.2), or PostgreSQL (≥9.6) database is required to run Icinga Notifications.
Please follow the steps listed for your target database,
which guide you through setting up the database and user and importing the schema.

### Setting up a MySQL or MariaDB Database

If you use a version of MySQL < 5.7 or MariaDB < 10.2, the following server options must be set:

```
innodb_file_format=barracuda
innodb_file_per_table=1
innodb_large_prefix=1
```

Set up a MySQL database for Icinga Notifications:

```
Expand Down
4 changes: 4 additions & 0 deletions internal/channel/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,5 +230,9 @@ func ValidateType(t string) error {
return fmt.Errorf("type contains invalid chars, may only contain a-zA-Z0-9, %q given", t)
}

if len(t) > 255 {
return fmt.Errorf("type is too long, at most 255 chars allowed, %d given", len(t))
}

return nil
}
14 changes: 14 additions & 0 deletions internal/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ func (e *Event) Validate() error {
return fmt.Errorf("invalid event: tags must not be empty")
}

for tag := range e.Tags {
if len(tag) > 255 {
return fmt.Errorf("invalid event: tag %q is too long, at most 255 chars allowed, %d given", tag, len(tag))
}
}
julianbrost marked this conversation as resolved.
Show resolved Hide resolved

for tag := range e.ExtraTags {
if len(tag) > 255 {
return fmt.Errorf(
"invalid event: extra tag %q is too long, at most 255 chars allowed, %d given", tag, len(tag),
)
}
}

if e.SourceId == 0 {
return fmt.Errorf("invalid event: source ID must not be empty")
}
Expand Down
Loading
Loading