Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(telemetry): instrument rafiki #2299

Merged
merged 67 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
4e8101d
feat(telemetry): add opentelemetry and instrument rafiki.
beniaminmunteanu Nov 23, 2023
4ee5dda
feat(telemetry): move transaction_amount metric into ilp connector.
beniaminmunteanu Nov 24, 2023
ec31fad
chore(telemetry): format
beniaminmunteanu Nov 24, 2023
f0e9e33
feat(telemetry): go back to usual DI implementation
beniaminmunteanu Nov 24, 2023
31402d6
feat(telemetry): remove collector methods from telemetry service & re…
beniaminmunteanu Nov 24, 2023
8cc1f98
feat(telemetry): use already existing env variable (instance_name)
beniaminmunteanu Nov 27, 2023
cfcc091
feat(telemetry): move transactions_total metric to outgoing payment i…
beniaminmunteanu Nov 27, 2023
fdd41d7
feat(telemetry): telemetry now has it's own middleware instead of inj…
beniaminmunteanu Nov 27, 2023
26d9526
feat(telemetry): add unit tests for ILP Connector telemetry middleware
beniaminmunteanu Nov 29, 2023
783d548
feat(telemetry):remove clog
beniaminmunteanu Nov 29, 2023
5a99206
feat(telemetry): add telemetry middleware and service tests
beniaminmunteanu Dec 4, 2023
29bcd07
feat(telemetry): mock TelemetryService in createTestApp
beniaminmunteanu Dec 4, 2023
770573f
feat(telemetry): fix DI of middleware. Add condition for early return…
beniaminmunteanu Dec 4, 2023
126f0da
feat(telemetry): move telemetry middleware after createStreamControll…
beniaminmunteanu Dec 4, 2023
603fbe1
feat(telemetry): telemetry service now supports sending metrics to mu…
beniaminmunteanu Dec 11, 2023
67f279b
feat:(telemetry): remove asset_code information from transactions_amo…
beniaminmunteanu Dec 11, 2023
44645cb
feat(telemetry): add rates service that uses external rates
beniaminmunteanu Dec 21, 2023
a7c895e
feat(telemetry): add privacy
beniaminmunteanu Dec 21, 2023
0356ada
feat(telemetry): rephrase md
beniaminmunteanu Dec 21, 2023
503b6d2
feat(telemetry): extract privacy as a separate module
beniaminmunteanu Dec 23, 2023
c29f62f
feat(telemetry): add tests
beniaminmunteanu Dec 23, 2023
8ae1660
feat(telemetry): remove hostPort
beniaminmunteanu Dec 23, 2023
4a910f9
feat(telemetry): cleanup & add tesets
beniaminmunteanu Dec 23, 2023
87161b8
feat(telemetry): change privacy doc wording
beniaminmunteanu Jan 2, 2024
01ba59a
feat(telemetry): Remove local otel collector setup from cloud-nine an…
beniaminmunteanu Jan 6, 2024
7770f8f
feat(telemetry): prioritize ase provided exchange rates before extern…
beniaminmunteanu Jan 8, 2024
de49bf3
feat(telemetry): openTelemetryCollectors env var now has a default
beniaminmunteanu Jan 8, 2024
2357e01
feat(telemetry): remove source from amount metrics for privacy concerns
beniaminmunteanu Jan 8, 2024
b1b1489
feat(telemetry): add exchange rates retrieval lambda to codebase
beniaminmunteanu Jan 9, 2024
b50cfcf
feat(telemetry): docs
beniaminmunteanu Jan 9, 2024
79aff6c
Resolve documentation issues
huijing Jan 9, 2024
ed2aff8
feat(telemetry): move back from ILP connector to accounting service
beniaminmunteanu Jan 13, 2024
ff63f80
feat(telemetry): base asset code no longer externally configurable
beniaminmunteanu Jan 13, 2024
19183c5
feat(telemetry): leftover of last commit
beniaminmunteanu Jan 13, 2024
86a569a
feat(telemetry): some docs changes
beniaminmunteanu Jan 29, 2024
c528ab8
feat(telemetry):docs changes
beniaminmunteanu Jan 29, 2024
f171026
feat(telemetry):docs
beniaminmunteanu Jan 29, 2024
223e89f
feat(telemetry):more docs changes
beniaminmunteanu Jan 29, 2024
ff70532
feat(telemetry): remove leftover mock
beniaminmunteanu Jan 29, 2024
48631ff
feat(telemetry): Move conversion in telemetry & update DI accordingly.
beniaminmunteanu Jan 29, 2024
73f3f83
feat(telemetry): docs - create new integration section
beniaminmunteanu Jan 29, 2024
eb7e189
feat(telemetry): logger DI - add BaseAccountingServiceDependencies in…
beniaminmunteanu Feb 1, 2024
8f9ec36
feat(telemetry): telemetry optional in the AppServices interface
beniaminmunteanu Feb 1, 2024
0896717
docs(telemetry): remove collection implementation details
beniaminmunteanu Feb 1, 2024
7232209
feat(telemetry): cleanup
beniaminmunteanu Feb 2, 2024
bf092bb
feat(telemetry):testing- telemetry service tests now properly mock ot…
beniaminmunteanu Feb 2, 2024
8d38726
feat(telemetry): opt out of otel sdk periodic logging on periodic exp…
beniaminmunteanu Feb 2, 2024
b4dec15
feat(telemetry): meter provider shutdown exposed in telemetryService …
beniaminmunteanu Feb 2, 2024
1e3e678
feat(telemetry): tests now provide empty list of collector url's, so …
beniaminmunteanu Feb 2, 2024
8b90d53
feat(telemetry): tests now no longer need to mock exporters, as they …
beniaminmunteanu Feb 2, 2024
ed1f86b
feat(telemetry): code review cleanup
beniaminmunteanu Feb 4, 2024
ac83b25
feat(telemetry): docs updates
beniaminmunteanu Feb 6, 2024
7e09fb3
feat(telemetry): docs improvements
beniaminmunteanu Feb 8, 2024
05e308b
fix(telemetry):docs link
beniaminmunteanu Feb 8, 2024
a2d007b
feat(telemetry): docs change
beniaminmunteanu Feb 8, 2024
e6b06e5
feat(telemetry): fix docs link
beniaminmunteanu Feb 12, 2024
08d8efa
feat(telemetry): fix seed not having peeringAsset
beniaminmunteanu Feb 13, 2024
482aa67
feat(telemetry): remove unused aseRatesService
beniaminmunteanu Feb 14, 2024
a91c5d4
feat(telemetry): rename fallbackRates to internalRates
beniaminmunteanu Feb 14, 2024
409f2e1
feat(telemetry): added comments for privacy implementation + added a …
beniaminmunteanu Feb 14, 2024
a7f0a3f
feat(telemetry): remove testing clog
beniaminmunteanu Feb 15, 2024
b59814a
feaet(telemetry): remove telemetry from localenv
beniaminmunteanu Feb 19, 2024
3a9b8ff
feat(telemetry): enableTelemetry defaults to false
beniaminmunteanu Feb 19, 2024
efe4c52
feat(telemetry): turn default telemetry back on, but off on localenv
beniaminmunteanu Feb 19, 2024
395c86a
feat(telemetry): add distinction between livenet and testnet
beniaminmunteanu Feb 21, 2024
1c759e3
feat(telemetry): update docs to new LIVENET env variable
beniaminmunteanu Feb 21, 2024
8135aac
feat(telemetry): plural on OPEN_TELEMETRY_COLLECTOR_URLS
beniaminmunteanu Feb 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions aws/lambdas/exchange-rates/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module exchange-rates-lambda

go 1.21.0

require (
github.com/aws/aws-lambda-go v1.42.0 // indirect
github.com/aws/aws-sdk-go v1.49.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
)
12 changes: 12 additions & 0 deletions aws/lambdas/exchange-rates/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
github.com/aws/aws-lambda-go v1.42.0 h1:U4QKkxLp/il15RJGAANxiT9VumQzimsUER7gokqA0+c=
github.com/aws/aws-lambda-go v1.42.0/go.mod h1:dpMpZgvWx5vuQJfBt0zqBha60q7Dd7RfgJv23DymV8A=
github.com/aws/aws-sdk-go v1.49.1 h1:Dsamcd8d/nNb3A+bZ0ucfGl0vGZsW5wlRW0vhoYGoeQ=
github.com/aws/aws-sdk-go v1.49.1/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
119 changes: 119 additions & 0 deletions aws/lambdas/exchange-rates/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package main

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net/http"
"os"
"strconv"
"time"

"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
)

type RatesResponse struct {
Base string `json:"base"`
Rates map[string]float64 `json:"rates"`
}

type MerchantRates struct {
Merchant map[string]map[string]string `json:"merchant"`
}

func getExchangeRates(apiURL string) (map[string]map[string]string, error) {
client := &http.Client{Timeout: 15 * time.Second}
response, err := client.Get(apiURL)
if err != nil {
return nil, fmt.Errorf("failed to get exchange rates from %s: %w", apiURL, err)
}
defer response.Body.Close()

if response.StatusCode != http.StatusOK {
return nil, fmt.Errorf("received non-200 response code: %d", response.StatusCode)
}

var ratesResponse MerchantRates
err = json.NewDecoder(response.Body).Decode(&ratesResponse)
if err != nil {
return nil, fmt.Errorf("failed to decode response body: %w", err)
}

return ratesResponse.Merchant, nil
}

func transformToBaseCurrency(baseCurrency string, merchantRates map[string]map[string]string) (*RatesResponse, error) {

usdRates := make(map[string]float64)

for currency, rateMap := range merchantRates {
rateStr, ok := rateMap[baseCurrency]
if !ok {
return nil, fmt.Errorf("failed to find %s rate for currency %s in merchant rates", baseCurrency, currency)
}

rate, err := strconv.ParseFloat(rateStr, 64)
if err != nil {
return nil, fmt.Errorf("failed to convert rate to float64 for currency %s: %v", currency, err)
}

usdRates[currency] = rate
}

return &RatesResponse{
Base: baseCurrency,
Rates: usdRates,
}, nil
}

func Handler() (string, error) {
apiUrl := os.Getenv("API_URL")
bucketName := os.Getenv("BUCKET_NAME")
keyName := os.Getenv("KEY_NAME")
region := os.Getenv("REGION")
baseCurrency := os.Getenv("BASE_CURRENCY")

if apiUrl == "" || bucketName == "" || keyName == "" || region == "" {
return "", errors.New("API_URL, BUCKET_NAME, or KEY_NAME environment variable is not set")
}

merchantRates, err := getExchangeRates(apiUrl)
if err != nil {
return "", err
}

data, err := transformToBaseCurrency(baseCurrency, merchantRates)
if err != nil {
return "", err
}

dataBytes, err := json.Marshal(data)
if err != nil {
return "", err
}

sess := session.Must(session.NewSession(&aws.Config{
Region: aws.String(region)},
))

uploader := s3manager.NewUploader(sess)

_, err = uploader.Upload(&s3manager.UploadInput{
Bucket: aws.String(bucketName),
Key: aws.String(keyName),
Body: bytes.NewReader(dataBytes),
})
if err != nil {
return "", err
}

return "Successfully uploaded data to " + bucketName + "/" + keyName, nil
}

func main() {
lambda.Start(Handler)
}
1 change: 1 addition & 0 deletions localenv/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.env
3 changes: 3 additions & 0 deletions localenv/cloud-nine-wallet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ services:
- rafiki
environment:
NODE_ENV: ${NODE_ENV:-development}
INSTANCE_NAME: CLOUD-NINE
TRUST_PROXY: ${TRUST_PROXY}
LOG_LEVEL: debug
ADMIN_PORT: 3001
Expand All @@ -59,6 +60,7 @@ services:
REDIS_URL: redis://shared-redis:6379/0
WALLET_ADDRESS_URL: ${CLOUD_NINE_WALLET_ADDRESS_URL:-https://cloud-nine-wallet-backend/.well-known/pay}
ILP_CONNECTOR_ADDRESS: ${CLOUD_NINE_CONNECTOR_URL}
ENABLE_TELEMETRY: false
depends_on:
- shared-database
- shared-redis
Expand Down Expand Up @@ -118,6 +120,7 @@ services:
depends_on:
- cloud-nine-backend


volumes:
database-data: # named volumes can be managed easier using docker-compose

Expand Down
26 changes: 13 additions & 13 deletions localenv/cloud-nine-wallet/seed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@ self:
assets:
- code: USD
scale: 2
liquidity: 1000000
liquidityThreshold: 100000
liquidity: 100000000
liquidityThreshold: 10000000
- code: EUR
scale: 2
liquidity: 1000000
liquidityThreshold: 100000
liquidity: 100000000
liquidityThreshold: 10000000
- code: MXN
scale: 2
liquidity: 1000000
liquidityThreshold: 100000
liquidity: 100000000
liquidityThreshold: 10000000
- code: JPY
scale: 0
liquidity: 10000
liquidityThreshold: 1000
liquidity: 1000000
liquidityThreshold: 100000
peeringAsset: 'USD'
peers:
- initialLiquidity: '100000'
- initialLiquidity: '10000000'
peerUrl: http://happy-life-bank-backend:3002
peerIlpAddress: test.happy-life-bank
liquidityThreshold: 10000
liquidityThreshold: 1000000
accounts:
- name: 'Grace Franklin'
path: accounts/gfranklin
id: 742ab7cd-1624-4d2e-af6e-e15a71638669
initialBalance: 50000
initialBalance: 40000000
postmanEnvVar: gfranklinWalletAddress
assetCode: USD
- name: 'Bert Hamchest'
id: a9adbe1a-df31-4766-87c9-d2cb2e636a9b
initialBalance: 50000
initialBalance: 40000000
path: accounts/bhamchest
postmanEnvVar: bhamchestWalletAddress
assetCode: USD
- name: "World's Best Donut Co"
id: 5726eefe-8737-459d-a36b-0acce152cb90
initialBalance: 2000
initialBalance: 20000000
path: accounts/wbdc
postmanEnvVar: wbdcWalletAddress
assetCode: USD
Expand Down
2 changes: 2 additions & 0 deletions localenv/happy-life-bank/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ services:
- rafiki
environment:
NODE_ENV: development
INSTANCE_NAME: HAPPY-LIFE
LOG_LEVEL: debug
ADMIN_PORT: 3001
CONNECTOR_PORT: 3002
Expand All @@ -51,6 +52,7 @@ services:
EXCHANGE_RATES_URL: http://happy-life-bank/rates
REDIS_URL: redis://shared-redis:6379/1
WALLET_ADDRESS_URL: ${HAPPY_LIFE_BANK_WALLET_ADDRESS_URL:-https://happy-life-bank-backend/.well-known/pay}
ENABLE_TELEMETRY: false
depends_on:
- cloud-nine-backend
happy-life-auth:
Expand Down
28 changes: 14 additions & 14 deletions localenv/happy-life-bank/seed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,55 @@ self:
assets:
- code: USD
scale: 2
liquidity: 1000000
liquidityThreshold: 100000
liquidity: 10000000000
liquidityThreshold: 100000000
- code: EUR
scale: 2
liquidity: 1000000
liquidityThreshold: 100000
liquidity: 10000000000
liquidityThreshold: 1000000
- code: MXN
scale: 2
liquidity: 1000000
liquidityThreshold: 100000
liquidity: 10000000000
liquidityThreshold: 10000000
- code: JPY
scale: 0
liquidity: 10000
liquidityThreshold: 1000
liquidity: 1000000000
liquidityThreshold: 1000000
peeringAsset: 'USD'
peers:
- initialLiquidity: '1000000000000'
peerUrl: http://cloud-nine-wallet-backend:3002
peerIlpAddress: test.cloud-nine-wallet
liquidityThreshold: 100000
liquidityThreshold: 1000000
accounts:
- name: 'Philip Fry'
path: accounts/pfry
id: 97a3a431-8ee1-48fc-ac85-70e2f5eba8e5
initialBalance: 50000
initialBalance: 1
postmanEnvVar: pfryWalletAddress
assetCode: USD
- name: 'PlanEx Corp'
id: a455cc54-b583-455b-836a-e5275c5c05b7
initialBalance: 2000
initialBalance: 2000000
beniaminmunteanu marked this conversation as resolved.
Show resolved Hide resolved
path: accounts/planex
postmanEnvVar: planexWalletAddress
assetCode: USD
- name: 'Alice Smith'
path: accounts/asmith
id: f47ac10b-58cc-4372-a567-0e02b2c3d479
initialBalance: 500
initialBalance: 5000000
postmanEnvVar: asmithWalletAddress
skipWalletAddressCreation: true
assetCode: USD
- name: 'Lars'
path: accounts/lars
id: fd4ecbc9-205d-4ecd-a030-507d6ce2bde6
initialBalance: 50000
initialBalance: 50000000
assetCode: EUR
- name: 'David'
path: accounts/david
id: 60257507-3191-4507-9d77-9071fd6b3c30
initialBalance: 150000
initialBalance: 1500000000
assetCode: MXN
rates:
EUR:
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
"@interledger/pay": "0.4.0-alpha.9",
"@interledger/stream-receiver": "^0.3.3-alpha.3",
"@koa/router": "^12.0.0",
"@opentelemetry/api": "^1.6.0",
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.43.0",
"@opentelemetry/resources": "^1.17.0",
"@opentelemetry/sdk-metrics": "^1.17.0",
"ajv": "^8.12.0",
"axios": "1.6.7",
"base64url": "^3.0.1",
Expand Down
9 changes: 5 additions & 4 deletions packages/backend/src/accounting/psql/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ import { TransactionOrKnex } from 'objection'
import { v4 as uuid } from 'uuid'
import { Asset } from '../../asset/model'
import { BaseService } from '../../shared/baseService'
import { TelemetryService } from '../../telemetry/service'
import { isTransferError, TransferError } from '../errors'
import {
AccountingService,
createAccountToAccountTransfer,
Deposit,
LiquidityAccount,
LiquidityAccountType,
Transaction,
TransferOptions,
TransferToCreate,
Withdrawal,
createAccountToAccountTransfer
Withdrawal
} from '../service'
import { getAccountBalances } from './balance'
import {
Expand All @@ -35,6 +36,7 @@ import {
import { LedgerTransfer, LedgerTransferType } from './ledger-transfer/model'

export interface ServiceDependencies extends BaseService {
telemetry?: TelemetryService
knex: TransactionOrKnex
withdrawalThrottleDelay?: number
}
Expand Down Expand Up @@ -200,9 +202,8 @@ export async function createTransfer(
deps: ServiceDependencies,
args: TransferOptions
): Promise<Transaction | TransferError> {
return createAccountToAccountTransfer({
return createAccountToAccountTransfer(deps, {
transferArgs: args,
withdrawalThrottleDelay: deps.withdrawalThrottleDelay,
voidTransfers: async (transferRefs) => voidTransfers(deps, transferRefs),
postTransfers: async (transferRefs) => postTransfers(deps, transferRefs),
getAccountReceived: async (accountRef) =>
Expand Down
Loading
Loading