Skip to content
This repository has been archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Do not run rules-manager in -db.read-only mode.
Browse files Browse the repository at this point in the history
Signed-off-by: Harkishen-Singh <harkishensingh@hotmail.com>
  • Loading branch information
Harkishen-Singh committed Jul 13, 2022
1 parent d833a01 commit cc0e5ad
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 39 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -17,12 +17,14 @@ We use the following categories for changes:

### Added
- Network latency metric [#1431]
- Ability to configure reader-pool and writer-pool sizes [#1451]

### Changed
- `db.num-writer-connections` now sets the absolute number of write connections for writing metrics. [#1430]

### Fixed
- Refine check for existence of `prom_schema_migrations` table [#1452]
- Do not run rules-manager in `-db.read-only` mode [#1451]

## [0.12.1] - 2022-06-29

Expand Down
32 changes: 17 additions & 15 deletions docs/configuration.md
Expand Up @@ -59,21 +59,23 @@ The following subsections cover all CLI flags which promscale supports. You can

### Database flags

| Flag | Type | Default | Description |
|---------------------------|:--------:|:------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| db.app | string | promscale@{version} | 'app' sets application_name in database connection string. This is helpful during debugging when looking at pg_stat_activity. |
| db.connection-timeout | duration | 60 seconds | Timeout for establishing the connection between Promscale and TimescaleDB. |
| db.connections-max | integer | 80% of possible connections db | Maximum number of connections to the database that should be opened at once. It defaults to 80% of the maximum connections that the database can handle. |
| db.host | string | localhost | Host for TimescaleDB/Vanilla Postgres. |
| db.name | string | timescale | Database name. |
| db.num-writer-connections | integer | 0 | Number of database connections for writing metrics to database. By default, this will be set based on the number of CPUs available to the DB Promscale is connected to. |
| db.password | string | | Password for connecting to TimescaleDB/Vanilla Postgres. |
| db.port | int | 5432 | TimescaleDB/Vanilla Postgres connection password. |
| db.read-only | boolean | false | Read-only mode for the connector. Operations related to writing or updating the database are disallowed. It is used when pointing the connector to a TimescaleDB read replica. |
| db.ssl-mode | string | require | TimescaleDB/Vanilla Postgres connection ssl mode. If you do not want to use ssl, pass `allow` as value. |
| db.statements-cache | boolean | true | Whether database connection pool should use cached prepared statements. Disable if using PgBouncer. |
| db.uri | string | | TimescaleDB/Vanilla PostgresSQL URI. Example:`postgres://postgres:password@localhost:5432/timescale?sslmode=require` |
| db.user | string | postgres | TimescaleDB/Vanilla Postgres user. |
| Flag | Type | Default | Description |
|---------------------------------|:--------:|:------------------------------:|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| db.app | string | promscale@{version} | 'app' sets application_name in database connection string. This is helpful during debugging when looking at pg_stat_activity. |
| db.connection-timeout | duration | 60 seconds | Timeout for establishing the connection between Promscale and TimescaleDB. |
| db.connections-max | integer | 80% of possible connections db | Maximum number of connections to the database that should be opened at once. It defaults to 80% of the maximum connections that the database can handle. |
| db.connections.num-writers | integer | 0 | Number of database connections for writing metrics to database. By default, this will be set based on the number of CPUs available to the DB Promscale is connected to. |
| db.connections.reader-pool.size | integer | 30% of possible connections db | Maximum size of the reader pool of database connections. This defaults to 30% of max_connections allowed by the database. |
| db.connections.writer-pool.size | integer | 50% of possible connections db | Maximum size of the writer pool of database connections. This defaults to 50% of max_connections allowed by the database. |
| db.host | string | localhost | Host for TimescaleDB/Vanilla Postgres. |
| db.name | string | timescale | Database name. |
| db.password | string | | Password for connecting to TimescaleDB/Vanilla Postgres. |
| db.port | int | 5432 | TimescaleDB/Vanilla Postgres connection password. |
| db.read-only | boolean | false | Read-only mode for the connector. Operations related to writing or updating the database are disallowed. It is used when pointing the connector to a TimescaleDB read replica. |
| db.ssl-mode | string | require | TimescaleDB/Vanilla Postgres connection ssl mode. If you do not want to use ssl, pass `allow` as value. |
| db.statements-cache | boolean | true | Whether database connection pool should use cached prepared statements. Disable if using PgBouncer. |
| db.uri | string | | TimescaleDB/Vanilla PostgresSQL URI. Example:`postgres://postgres:password@localhost:5432/timescale?sslmode=require` |
| db.user | string | postgres | TimescaleDB/Vanilla Postgres user. |

### Telemetry flags (for telemetry generated by the Promscale connector itself)

Expand Down
55 changes: 31 additions & 24 deletions pkg/runner/runner.go
Expand Up @@ -137,33 +137,40 @@ func Run(cfg *Config) error {
}
}

rulesCtx, stopRuler := context.WithCancel(context.Background())
defer stopRuler()
manager, reloadRules, err := rules.NewManager(rulesCtx, prometheus.DefaultRegisterer, client, &cfg.RulesCfg)
if err != nil {
return fmt.Errorf("error creating rules manager: %w", err)
}
cfg.APICfg.Rules = manager

var group run.Group
group.Add(
func() error {
// Reload the rules before starting the rules-manager to ensure all rules are healthy.
// Otherwise, we block the startup.
if err = reloadRules(); err != nil {
return fmt.Errorf("error reloading rules: %w", err)
}
log.Info("msg", "Started Rule-Manager")
return manager.Run()
}, func(error) {
log.Info("msg", "Stopping Rule-Manager")
stopRuler()
},
var (
group run.Group
rulesReloader func() error
)
if !cfg.APICfg.ReadOnly {
rulesCtx, stopRuler := context.WithCancel(context.Background())
defer stopRuler()
manager, reloadRules, err := rules.NewManager(rulesCtx, prometheus.DefaultRegisterer, client, &cfg.RulesCfg)
if err != nil {
log.Error("msg", "error creating rules manager", "err", err.Error())
return fmt.Errorf("error creating rules manager: %w", err)
}
cfg.APICfg.Rules = manager
rulesReloader = reloadRules

group.Add(
func() error {
// Reload the rules before starting the rules-manager to ensure all rules are healthy.
// Otherwise, we block the startup.
if err = reloadRules(); err != nil {
return fmt.Errorf("error reloading rules: %w", err)
}
log.Info("msg", "Started Rule-Manager")
return manager.Run()
}, func(error) {
log.Info("msg", "Stopping Rule-Manager")
stopRuler()
},
)
}

jaegerQuery := query.New(client.ReadOnlyConnection(), &cfg.TracingCfg)

router, err := api.GenerateRouter(&cfg.APICfg, &cfg.PromQLCfg, client, jaegerQuery, reloadRules)
router, err := api.GenerateRouter(&cfg.APICfg, &cfg.PromQLCfg, client, jaegerQuery, rulesReloader)
if err != nil {
log.Error("msg", "aborting startup due to error", "err", fmt.Sprintf("generate router: %s", err.Error()))
return fmt.Errorf("generate router: %w", err)
Expand Down Expand Up @@ -287,7 +294,7 @@ func Run(cfg *Config) error {
case syscall.SIGINT:
return nil
case syscall.SIGHUP:
if err := reloadRules(); err != nil {
if err := rulesReloader(); err != nil {
log.Error("msg", "error reloading rules", "err", err.Error())
continue
}
Expand Down

0 comments on commit cc0e5ad

Please sign in to comment.