Skip to content

Commit 7e73a36

Browse files
committed
Add observability to OE and PDP
# Conflicts: # exchange/docker-compose.yml
1 parent 3bd7c64 commit 7e73a36

5 files changed

Lines changed: 28 additions & 28 deletions

File tree

.github/workflows/integration-tests.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ jobs:
115115
PORT=8082 \
116116
LOG_LEVEL=debug \
117117
DB_SSLMODE=disable \
118-
CHOREO_OPENDIF_DATABASE_HOSTNAME=localhost \
119-
CHOREO_OPENDIF_DATABASE_PORT=5433 \
120-
CHOREO_OPENDIF_DATABASE_USERNAME=postgres \
121-
CHOREO_OPENDIF_DATABASE_PASSWORD=password \
122-
CHOREO_OPENDIF_DATABASE_DATABASENAME=policy_db \
118+
CHOREO_OPENDIF_DATABASE_HOSTNAME=${CHOREO_OPENDIF_DATABASE_HOSTNAME:-localhost} \
119+
CHOREO_OPENDIF_DATABASE_PORT=${CHOREO_OPENDIF_DATABASE_PORT:-5433} \
120+
CHOREO_OPENDIF_DATABASE_USERNAME=${CHOREO_OPENDIF_DATABASE_USERNAME:-postgres} \
121+
CHOREO_OPENDIF_DATABASE_PASSWORD=${CHOREO_OPENDIF_DATABASE_PASSWORD:-password} \
122+
CHOREO_OPENDIF_DATABASE_DATABASENAME=${CHOREO_OPENDIF_DATABASE_DATABASENAME:-policy_db} \
123123
RUN_MIGRATION=true \
124124
./bin/policy-decision-point > logs/pdp.log 2>&1 &
125125
PDP_PID=$!
@@ -128,16 +128,16 @@ jobs:
128128
echo "🚀 Starting Consent Engine..."
129129
PORT=8081 \
130130
LOG_LEVEL=debug \
131-
CHOREO_DB_CE_HOSTNAME=localhost \
132-
CHOREO_DB_CE_PORT=5434 \
133-
CHOREO_DB_CE_USERNAME=postgres \
134-
CHOREO_DB_CE_PASSWORD=password \
135-
CHOREO_DB_CE_DATABASENAME=consent_db \
136-
CHOREO_OPENDIF_DATABASE_HOSTNAME=localhost \
137-
CHOREO_OPENDIF_DATABASE_PORT=5434 \
138-
CHOREO_OPENDIF_DATABASE_USERNAME=postgres \
139-
CHOREO_OPENDIF_DATABASE_PASSWORD=password \
140-
CHOREO_OPENDIF_DATABASE_DATABASENAME=consent_db \
131+
CHOREO_DB_CE_HOSTNAME=${CHOREO_DB_CE_HOSTNAME:-localhost} \
132+
CHOREO_DB_CE_PORT=${CHOREO_DB_CE_PORT:-5434} \
133+
CHOREO_DB_CE_USERNAME=${CHOREO_DB_CE_USERNAME:-postgres} \
134+
CHOREO_DB_CE_PASSWORD=${CHOREO_DB_CE_PASSWORD:-password} \
135+
CHOREO_DB_CE_DATABASENAME=${CHOREO_DB_CE_DATABASENAME:-consent_db} \
136+
CHOREO_OPENDIF_DATABASE_HOSTNAME=${CHOREO_OPENDIF_DATABASE_HOSTNAME:-localhost} \
137+
CHOREO_OPENDIF_DATABASE_PORT=${CHOREO_OPENDIF_DATABASE_PORT:-5434} \
138+
CHOREO_OPENDIF_DATABASE_USERNAME=${CHOREO_OPENDIF_DATABASE_USERNAME:-postgres} \
139+
CHOREO_OPENDIF_DATABASE_PASSWORD=${CHOREO_OPENDIF_DATABASE_PASSWORD:-password} \
140+
CHOREO_OPENDIF_DATABASE_DATABASENAME=${CHOREO_OPENDIF_DATABASE_DATABASENAME:-consent_db} \
141141
DB_SSLMODE=disable \
142142
RUN_MIGRATION=true \
143143
ASGARDEO_JWKS_URL="https://www.googleapis.com/oauth2/v3/certs" \

exchange/orchestration-engine/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414

1515
require github.com/go-chi/chi/v5 v5.2.3
1616

17-
require github.com/gov-dx-sandbox/exchange/pkg/monitoring v0.0.0
17+
require github.com/gov-dx-sandbox/exchange/shared/monitoring v0.0.0
1818

1919
require (
2020
github.com/beorn7/perks v1.0.1 // indirect
@@ -54,6 +54,6 @@ require (
5454
gopkg.in/yaml.v3 v3.0.1 // indirect
5555
)
5656

57-
replace github.com/gov-dx-sandbox/exchange/pkg/monitoring => ../shared/monitoring
57+
replace github.com/gov-dx-sandbox/exchange/shared/monitoring => ../shared/monitoring
5858

5959
replace github.com/gov-dx-sandbox/audit-service => ../../audit-service

exchange/orchestration-engine/provider/provider.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
"github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/logger"
1212
"github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/pkg/auth"
13-
"github.com/gov-dx-sandbox/exchange/pkg/monitoring"
13+
"github.com/gov-dx-sandbox/exchange/shared/monitoring"
1414
"golang.org/x/oauth2/clientcredentials"
1515
)
1616

@@ -49,7 +49,7 @@ func NewProvider(serviceKey, serviceUrl, schemaID string, authConfig *auth.AuthC
4949
}
5050

5151
// PerformRequest performs the HTTP request to the provider with necessary authentication.
52-
func (p *Provider) PerformRequest(ctx context.Context, reqBody []byte) (*http.Response, error) {
52+
func (p *Provider) PerformRequest(ctx context.Context, reqBody []byte) (resp *http.Response, err error) {
5353
// 1. Create Request
5454
req, err := http.NewRequestWithContext(ctx, "POST", p.ServiceUrl, bytes.NewBuffer(reqBody))
5555
if err != nil {
@@ -59,19 +59,21 @@ func (p *Provider) PerformRequest(ctx context.Context, reqBody []byte) (*http.Re
5959
req.Header.Set("Content-Type", "application/json")
6060

6161
start := time.Now()
62+
defer func() {
63+
monitoring.RecordExternalCall(p.ServiceKey, "provider_request", time.Since(start), err)
64+
}()
6265

6366
if p.Auth != nil {
6467
switch p.Auth.Type {
6568
case auth.AuthTypeOAuth2:
6669
if p.OAuth2Config == nil {
67-
logger.Log.Error("OAuth2Config is nil", "providerKey", p.ServiceKey)
68-
return nil, fmt.Errorf("OAuth2Config is nil")
70+
err = fmt.Errorf("OAuth2Config is nil")
71+
logger.Log.Error(err.Error(), "providerKey", p.ServiceKey)
72+
return nil, err
6973
}
7074

7175
client := p.OAuth2Config.Client(ctx)
72-
resp, err := client.Do(req) // Use context with request
73-
monitoring.RecordExternalCall(p.ServiceKey, "provider_request", time.Since(start), err)
74-
return resp, err
76+
return client.Do(req)
7577
case auth.AuthTypeAPIKey:
7678
req.Header.Set(p.Auth.APIKeyName, p.Auth.APIKeyValue)
7779
}

exchange/orchestration-engine/server/server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import (
77
"os"
88
"runtime/debug"
99

10-
"github.com/go-chi/chi/v5"
1110
"github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/auth"
1211
"github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/database"
1312
"github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/federator"
1413
"github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/handlers"
1514
"github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/logger"
1615
"github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/pkg/graphql"
1716
"github.com/ginaxu1/gov-dx-sandbox/exchange/orchestration-engine/services"
18-
"github.com/gov-dx-sandbox/exchange/pkg/monitoring"
17+
"github.com/go-chi/chi/v5"
18+
"github.com/gov-dx-sandbox/exchange/shared/monitoring"
1919
)
2020

2121
type Response struct {

exchange/policy-decision-point/main.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ func main() {
2828
utils.SetupLogging("json", getEnvOrDefault("LOG_LEVEL", "info"))
2929

3030
// Initialize monitoring/observability
31-
// Set SERVICE_NAME for proper metric labeling
32-
os.Setenv("SERVICE_NAME", "policy-decision-point")
3331
monitoringConfig := monitoring.DefaultConfig("policy-decision-point")
3432
if err := monitoring.Initialize(monitoringConfig); err != nil {
3533
slog.Error("Failed to initialize monitoring", "error", err)

0 commit comments

Comments
 (0)