Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Commit 13a8f10

Browse files
Fix comments
1 parent 6dabca5 commit 13a8f10

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func main() {
113113
http.Handle(cfg.telemetryPath, prometheus.Handler())
114114

115115
writer, reader := buildClients(cfg)
116-
election = initElection(cfg, writer.(*pgprometheus.Client).Db)
116+
election = initElection(cfg, writer.(*pgprometheus.Client).DB)
117117

118118
http.Handle("/write", timeHandler("write", write(writer)))
119119
http.Handle("/read", timeHandler("read", read(reader)))

postgresql/client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func ParseFlags(cfg *Config) *Config {
6464

6565
// Client sends Prometheus samples to PostgreSQL
6666
type Client struct {
67-
Db *sql.DB
67+
DB *sql.DB
6868
cfg *Config
6969
}
7070

@@ -101,7 +101,7 @@ func NewClient(cfg *Config) *Client {
101101
db.SetMaxIdleConns(cfg.maxIdleConns)
102102

103103
client := &Client{
104-
Db: db,
104+
DB: db,
105105
cfg: cfg,
106106
}
107107

@@ -121,7 +121,7 @@ func NewClient(cfg *Config) *Client {
121121
}
122122

123123
func (c *Client) setupPgPrometheus() error {
124-
tx, err := c.Db.Begin()
124+
tx, err := c.DB.Begin()
125125

126126
if err != nil {
127127
return err
@@ -193,7 +193,7 @@ func metricString(m model.Metric) string {
193193
// Write implements the Writer interface and writes metric samples to the database
194194
func (c *Client) Write(samples model.Samples) error {
195195
begin := time.Now()
196-
tx, err := c.Db.Begin()
196+
tx, err := c.DB.Begin()
197197

198198
if err != nil {
199199
log.Error("msg", "Error on Begin when writing samples", "err", err)
@@ -360,7 +360,7 @@ func (c *Client) Read(req *prompb.ReadRequest) (*prompb.ReadResponse, error) {
360360

361361
log.Debug("msg", "Executed query", "query", command)
362362

363-
rows, err := c.Db.Query(command)
363+
rows, err := c.DB.Query(command)
364364

365365
if err != nil {
366366
return nil, err
@@ -439,7 +439,7 @@ func (c *Client) Read(req *prompb.ReadRequest) (*prompb.ReadResponse, error) {
439439

440440
// HealthCheck implements the healtcheck interface
441441
func (c *Client) HealthCheck() error {
442-
rows, err := c.Db.Query("SELECT 1")
442+
rows, err := c.DB.Query("SELECT 1")
443443

444444
if err != nil {
445445
log.Debug("msg", "Health check error", "err", err)

util/election.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package util
22

3+
// Election defines an interface for adapter leader election.
34
// If you are running Prometheus in HA mode where each Prometheus instance sends data to corresponding adapter you probably
45
// want to allow writes into the database from only one adapter at the time. We need to elect a leader who can write to
56
// the database. If leader goes down, another leader is elected. Look at `lock.go` for an implementation based on PostgreSQL

util/lock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const (
1414
connCheckInterval = time.Millisecond * 250
1515
)
1616

17-
// One implementation of leader election protocol based on PostgreSQL advisory locks. All adapters withing a HA group are trying
17+
// PgAdvisoryLock is implementation of leader election protocol based on PostgreSQL advisory locks. All adapters withing a HA group are trying
1818
// to obtain an advisory lock for particular group. The one who holds the lock can write to the database. Due to the fact
1919
// that Prometheus HA setup provides no consistency guarantees this implementation is best effort in regards
2020
// to metrics that is written (some duplicates or data loss are possible during failover)

0 commit comments

Comments
 (0)