-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #211 from EURODEO/logging
Add Monitoring to test local performance improvements
- Loading branch information
Showing
19 changed files
with
4,972 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# postgres-exporter | ||
shared_preload_libraries = 'pg_cron,pg_stat_statements' | ||
track_activity_query_size = 2048 | ||
pg_stat_statements.track = 'all' | ||
pg_stat_statements.max = 10000 | ||
pg_stat_statements.save = 'on' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ | |
!common | ||
!dsimpl | ||
!storagebackend | ||
!metrics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package promservermetrics | ||
|
||
import ( | ||
"context" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"google.golang.org/grpc" | ||
"sync" | ||
"time" | ||
) | ||
|
||
var ( | ||
UptimeCounter = prometheus.NewCounter(prometheus.CounterOpts{ | ||
Name: "grpc_server_uptime_seconds", | ||
Help: "Total uptime of the gRPC server in seconds", | ||
}) | ||
|
||
InFlightRequests = prometheus.NewGauge(prometheus.GaugeOpts{ | ||
Name: "grpc_in_flight_requests", | ||
Help: "Current number of in-flight gRPC requests", | ||
}) | ||
|
||
ResponseSizeSummary = prometheus.NewSummaryVec( | ||
prometheus.SummaryOpts{ | ||
Name: "grpc_response_size_summary_bytes", | ||
Help: "Summary of response sizes in bytes for each gRPC method, with mean, min, and max", | ||
Objectives: map[float64]float64{0.0: 0.001, 1.0: 0.001}, // Track min (0.0 quantile) and max (1.0 quantile) | ||
}, | ||
[]string{"method"}, | ||
) | ||
|
||
responseSizeMu sync.Mutex | ||
responseSizeSum = make(map[string]float64) | ||
responseSizeCount = make(map[string]float64) | ||
) | ||
|
||
func TrackUptime() { | ||
// Increment the uptime every second | ||
for { | ||
UptimeCounter.Inc() | ||
time.Sleep(1 * time.Second) | ||
} | ||
} | ||
|
||
func InFlightRequestInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { | ||
InFlightRequests.Inc() // Increment at the start of the request | ||
defer InFlightRequests.Dec() // Decrement at the end of the request | ||
return handler(ctx, req) | ||
} | ||
|
||
func ResponseSizeUnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) { | ||
resp, err = handler(ctx, req) | ||
|
||
if resp != nil { | ||
responseSize := float64(len(resp.(interface{ String() string }).String())) | ||
|
||
ResponseSizeSummary.WithLabelValues(info.FullMethod).Observe(responseSize) | ||
|
||
// Used a mutex to synchronise the access for the responseSizeSum and responseSizeCount. | ||
// To prevent race conditions and multiple goroutines accessing the variables at the same time. | ||
responseSizeMu.Lock() | ||
responseSizeSum[info.FullMethod] += responseSize | ||
responseSizeCount[info.FullMethod]++ | ||
responseSizeMu.Unlock() | ||
} | ||
|
||
return resp, err | ||
} |
1 change: 1 addition & 0 deletions
1
datastore/migrate/data/migrations/1723033622_setup_prometheus_extension.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP EXTENSION pg_stat_statements; |
1 change: 1 addition & 0 deletions
1
datastore/migrate/data/migrations/1723033622_setup_prometheus_extension.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE EXTENSION IF NOT EXISTS pg_stat_statements; |
1 change: 1 addition & 0 deletions
1
datastore/migrate/data/migrations/1730887695_create_pg_stat_statements.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP EXTENSION IF EXISTS pg_stat_statements; |
1 change: 1 addition & 0 deletions
1
datastore/migrate/data/migrations/1730887695_create_pg_stat_statements.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CREATE EXTENSION IF NOT EXISTS pg_stat_statements; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
63e2a3e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API Unit Test Coverage Report
API Unit Test Coverage Summary