Skip to content

Commit 28d253b

Browse files
committed
chore: various improvements across codebase (#7)
Signed-off-by: Imtiaz Uddin <[email protected]>
1 parent a08050f commit 28d253b

File tree

271 files changed

+8847
-24710
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

271 files changed

+8847
-24710
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ jobs:
6464
if: startsWith(github.ref, 'refs/tags/')
6565
with:
6666
files: |
67-
bin/wal-listener-linux-amd64.tar.gz
68-
bin/wal-listener-linux-arm64.tar.gz
69-
bin/wal-listener-checksums.txt
67+
bin/pgoutbox-linux-amd64.tar.gz
68+
bin/pgoutbox-linux-arm64.tar.gz
69+
bin/pgoutbox-checksums.txt
7070
env:
7171
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.lgtm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pattern = "(?)LGTM"
2+
self_approval_off = true
3+
ignore_maintainers_file = true

DCO

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Developer Certificate of Origin
2+
Version 1.1
3+
4+
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
5+
660 York Street, Suite 102,
6+
San Francisco, CA 94110 USA
7+
8+
Everyone is permitted to copy and distribute verbatim copies of this
9+
license document, but changing it is not allowed.
10+
11+
12+
Developer's Certificate of Origin 1.1
13+
14+
By making a contribution to this project, I certify that:
15+
16+
(a) The contribution was created in whole or in part by me and I
17+
have the right to submit it under the open source license
18+
indicated in the file; or
19+
20+
(b) The contribution is based upon previous work that, to the best
21+
of my knowledge, is covered under an appropriate open source
22+
license and I have the right under that license to submit that
23+
work with modifications, whether created in whole or in part
24+
by me, under the same open source license (unless I am
25+
permitted to submit under a different license), as indicated
26+
in the file; or
27+
28+
(c) The contribution was provided directly to me by some other
29+
person who certified (a), (b) or (c) and I have not modified
30+
it.
31+
32+
(d) I understand and agree that this project and the contribution
33+
are public and that a record of the contribution (including all
34+
personal information I submit with it, including my sign-off) is
35+
maintained indefinitely and may be redistributed consistent with
36+
this project or the open source license(s) involved.

Dockerfile.dbg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ FROM ghcr.io/appscode/dlv:1.24
1616

1717
FROM {ARG_FROM}
1818

19-
LABEL org.opencontainers.image.source https://github.com/bytebuilders/wal-listener
19+
LABEL org.opencontainers.image.source https://github.com/kubeops/pgoutbox
2020

2121
RUN set -x \
2222
&& apt-get update \

Dockerfile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
FROM {ARG_FROM}
1616

17-
LABEL org.opencontainers.image.source https://github.com/bytebuilders/wal-listener
17+
LABEL org.opencontainers.image.source https://github.com/kubeops/pgoutbox
1818

1919
RUN set -x \
2020
&& apk add --update --upgrade --no-cache pcre2 ca-certificates tzdata openssh-client \

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
SHELL=/bin/bash -o pipefail
1818

1919
PRODUCT_OWNER_NAME := appscode
20-
PRODUCT_NAME := wal-listener
20+
PRODUCT_NAME := pgoutbox
2121
ENFORCE_LICENSE ?=
2222

23-
GO_PKG := github.com/ihippik
23+
GO_PKG := kubeops.dev
2424
REPO := $(notdir $(shell pwd))
25-
BIN := wal-listener
25+
BIN := pgoutbox
2626
COMPRESS ?= no
2727

2828
# Where to push the docker image.
@@ -313,7 +313,7 @@ install:
313313
@cd ../installer; \
314314
kubectl create ns $(KUBE_NAMESPACE) || true; \
315315
kubectl label ns $(KUBE_NAMESPACE) pod-security.kubernetes.io/enforce=restricted; \
316-
helm upgrade -i cluster-importer charts/cluster-importer --wait \
316+
helm upgrade -i pgoutbox charts/pgoutbox --wait \
317317
--namespace=$(KUBE_NAMESPACE) --create-namespace \
318318
--set image.tag=$(TAG_PROD) \
319319
--set imagePullPolicy=$(IMAGE_PULL_POLICY) \
@@ -322,7 +322,7 @@ install:
322322
.PHONY: uninstall
323323
uninstall:
324324
@cd ../installer; \
325-
helm uninstall cluster-importer --namespace=$(KUBE_NAMESPACE) || true
325+
helm uninstall pgoutbox --namespace=$(KUBE_NAMESPACE) || true
326326

327327
.PHONY: purge
328328
purge: uninstall

README.md

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1-
# WAL-Listener
1+
# pgoutbox
22

3-
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4-
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/ihippik/wal-listener)
5-
![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/ihippik/wal-listener)
6-
[![Publish Docker image](https://github.com/ihippik/wal-listener/actions/workflows/github-actions.yml/badge.svg)](https://github.com/ihippik/wal-listener/actions/workflows/github-actions.yml)
7-
8-
![WAL-Listener](wal-listener.png)
3+
![PgOutbox](wal-listener.png)
94

105
A service that helps implement the **Event-Driven architecture**.
116

@@ -77,7 +72,7 @@ You must make the following settings in the db configuration (postgresql.conf)
7772
* max_replication_slots >= 1
7873
7974
The publication & slot created automatically when the service starts (for all tables and all actions).
80-
You can delete the default publication and create your own (name: _wal-listener_) with the necessary filtering conditions, and then the filtering will occur at the database level and not at the application level.
75+
You can delete the default publication and create your own (name: _pgoutbox_) with the necessary filtering conditions, and then the filtering will occur at the database level and not at the application level.
8176
8277
https://www.postgresql.org/docs/current/sql-createpublication.html
8378
@@ -150,7 +145,7 @@ for readiness `/ready` and liveness `/healthz` probes.
150145
You can start the container from the project folder (configuration file is required).
151146

152147
See `./config_example.yml` for an example configuration.
153-
Be sure to copy the file to the docker image in the `Dockerfile` prior to running [after the build setp](https://github.com/ihippik/wal-listener/blob/master/Dockerfile#L31)
148+
Be sure to copy the file to the docker image in the `Dockerfile` prior to running [after the build setp](https://kubeops.dev/pgoutbox/blob/master/Dockerfile#L31)
154149
ex:
155150
```docker
156151
COPY /config.yml .
@@ -161,10 +156,3 @@ Please don't forget to delete them:
161156
```shell
162157
docker image prune --filter label=stage=builder
163158
```
164-
165-
#### Docker Hub
166-
https://hub.docker.com/r/ihippik/wal-listener
167-
#### Example
168-
```shell
169-
docker run -v $(pwd)/config.yml:/app/config.yml ihippik/wal-listener:tag
170-
```

apis/config.go

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package apis
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
"time"
7+
8+
"github.com/asaskevich/govalidator"
9+
"github.com/spf13/viper"
10+
)
11+
12+
type PublisherType string
13+
14+
const (
15+
PublisherTypeNats PublisherType = "nats"
16+
PublisherTypeKafka PublisherType = "kafka"
17+
PublisherTypeRabbitMQ PublisherType = "rabbitmq"
18+
PublisherTypeGooglePubSub PublisherType = "google_pubsub"
19+
)
20+
21+
// Config for pgoutbox.
22+
type Config struct {
23+
Listener *ListenerCfg `valid:"required" json:"listener" mapstructure:"listener"`
24+
Database *DatabaseCfg `valid:"required" json:"database" mapstructure:"database"`
25+
Publisher *PublisherCfg `valid:"required" json:"publisher" mapstructure:"publisher"`
26+
Logger *Logger `valid:"required" json:"logger" mapstructure:"logger"`
27+
}
28+
29+
// ListenerCfg path of the listener config.
30+
type ListenerCfg struct {
31+
SlotName string `valid:"required" json:"slotName" mapstructure:"slotName"`
32+
ServerPort int `json:"serverPort" mapstructure:"serverPort"`
33+
AckTimeout time.Duration `json:"ackTimeout" mapstructure:"ackTimeout"`
34+
RefreshConnection time.Duration `json:"refreshConnection" valid:"required" mapstructure:"refreshConnection"`
35+
HeartbeatInterval time.Duration `json:"heartbeatInterval" valid:"required" mapstructure:"heartbeatInterval"`
36+
Filter FilterStruct `json:"filter" mapstructure:"filter"`
37+
TopicsMap map[string]string `json:"topicsMap" mapstructure:"topicsMap"`
38+
}
39+
40+
// PublisherCfg represent configuration for any publisher types.
41+
type PublisherCfg struct {
42+
Type PublisherType `valid:"required" json:"type" mapstructure:"type"`
43+
Address string `valid:"required" json:"address" mapstructure:"address"`
44+
NatsCredPath string `valid:"required" json:"natsCredPath" mapstructure:"natsCredPath"`
45+
Topic string `valid:"required" json:"topic" mapstructure:"topic"`
46+
TopicPrefix string `json:"topicPrefix" mapstructure:"topicPrefix"`
47+
EnableTLS bool `json:"enableTLS" mapstructure:"enableTlS"`
48+
ClientCert string `json:"clientCert" mapstructure:"clientCert"`
49+
ClientKey string `json:"clientKey" mapstructure:"clientKey"`
50+
CACert string `json:"CACert" mapstructure:"caCert"`
51+
PubSubProjectID string `json:"pubSubProjectID" mapstructure:"pubSubProductId"`
52+
}
53+
54+
// DatabaseCfg path of the PostgreSQL DB config.
55+
type DatabaseCfg struct {
56+
Host string `valid:"required" json:"host" mapstructure:"host"`
57+
Port uint16 `valid:"required" json:"port" mapstructure:"port"`
58+
Name string `valid:"required" json:"name" mapstructure:"name"`
59+
User string `valid:"required" json:"user" mapstructure:"user"`
60+
Password string `valid:"required" json:"password" mapstructure:"password"`
61+
Debug bool `json:"debug" mapstructure:"debug"`
62+
}
63+
64+
// FilterStruct incoming WAL message filter.
65+
type FilterStruct struct {
66+
Tables map[string][]string `json:"tables" yaml:"tables" mapstructure:"tables"`
67+
}
68+
69+
// Validate config data.
70+
func (c Config) Validate() error {
71+
_, err := govalidator.ValidateStruct(c)
72+
return err
73+
}
74+
75+
// InitConfig load config from file.
76+
func InitConfig(path string) (*Config, error) {
77+
const envPrefix = "WAL"
78+
79+
var conf Config
80+
81+
vp := viper.New()
82+
83+
vp.SetEnvPrefix(envPrefix)
84+
vp.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
85+
vp.AutomaticEnv()
86+
vp.SetConfigFile(path)
87+
88+
if err := vp.ReadInConfig(); err != nil {
89+
return nil, fmt.Errorf("error reading config: %w", err)
90+
}
91+
92+
if err := vp.Unmarshal(&conf); err != nil {
93+
return nil, fmt.Errorf("unable to decode into config struct: %w", err)
94+
}
95+
96+
return &conf, nil
97+
}

internal/config/config_test.go renamed to apis/config_test.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
package config
1+
package apis
22

33
import (
44
"errors"
55
"testing"
66

7-
scfg "github.com/ihippik/config"
8-
97
"github.com/stretchr/testify/assert"
108
)
119

1210
func TestConfig_Validate(t *testing.T) {
1311
type fields struct {
14-
Logger *scfg.Logger
12+
Logger *Logger
1513
Listener *ListenerCfg
1614
Database *DatabaseCfg
1715
Publisher *PublisherCfg
@@ -24,7 +22,7 @@ func TestConfig_Validate(t *testing.T) {
2422
{
2523
name: "success",
2624
fields: fields{
27-
Logger: &scfg.Logger{
25+
Logger: &Logger{
2826
Level: "info",
2927
},
3028
Listener: &ListenerCfg{
@@ -52,7 +50,7 @@ func TestConfig_Validate(t *testing.T) {
5250
{
5351
name: "bad listener cfg",
5452
fields: fields{
55-
Logger: &scfg.Logger{
53+
Logger: &Logger{
5654
Level: "info",
5755
},
5856
Listener: &ListenerCfg{
@@ -78,7 +76,7 @@ func TestConfig_Validate(t *testing.T) {
7876
{
7977
name: "bad db cfg",
8078
fields: fields{
81-
Logger: &scfg.Logger{
79+
Logger: &Logger{
8280
Level: "info",
8381
},
8482
Listener: &ListenerCfg{
@@ -104,7 +102,7 @@ func TestConfig_Validate(t *testing.T) {
104102
{
105103
name: "empty publisher kind",
106104
fields: fields{
107-
Logger: &scfg.Logger{
105+
Logger: &Logger{
108106
Level: "info",
109107
},
110108
Listener: &ListenerCfg{

internal/publisher/event.go renamed to apis/event.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
package publisher
1+
package apis
22

33
import (
44
"fmt"
5-
"time"
6-
7-
"github.com/ihippik/wal-listener/v2/internal/config"
8-
95
"github.com/google/uuid"
6+
"time"
107
)
118

129
// Event structure for publishing to the NATS server.
@@ -21,8 +18,8 @@ type Event struct {
2118
}
2219

2320
// SubjectName creates subject name from the prefix, schema and table name. Also using topic map from cfg.
24-
func (e *Event) SubjectName(cfg *config.Config) string {
25-
topic := fmt.Sprintf("%s_%s", e.Schema, e.Table)
21+
func (e *Event) SubjectName(cfg *Config) string {
22+
topic := fmt.Sprintf("schemas.%s.tables.%s", e.Schema, e.Table)
2623

2724
if cfg.Listener.TopicsMap != nil {
2825
if t, ok := cfg.Listener.TopicsMap[topic]; ok {

0 commit comments

Comments
 (0)