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

added screen that shows transaction graph per hour, day and month #92

Merged
merged 5 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 34 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"nuts-foundation/nuts-monitor/client"
"nuts-foundation/nuts-monitor/client/diagnostics"
"nuts-foundation/nuts-monitor/config"
"nuts-foundation/nuts-monitor/data"
"time"
)

var _ StrictServerInterface = (*Wrapper)(nil)
Expand All @@ -33,8 +35,9 @@ const (
)

type Wrapper struct {
Config config.Config
Client client.HTTPClient
Config config.Config
Client client.HTTPClient
DataStore *data.Store
}

func (w Wrapper) Diagnostics(ctx context.Context, _ DiagnosticsRequestObject) (DiagnosticsResponseObject, error) {
Expand Down Expand Up @@ -97,3 +100,32 @@ func (w Wrapper) NetworkTopology(ctx context.Context, _ NetworkTopologyRequestOb

return NetworkTopology200JSONResponse(networkTopology), nil
}

func (w Wrapper) GetWebTransactionsAggregated(ctx context.Context, _ GetWebTransactionsAggregatedRequestObject) (GetWebTransactionsAggregatedResponseObject, error) {
// get data from the store
dataPoints := w.DataStore.GetTransactions()

// convert the data points to the response object
response := AggregatedTransactions{}
// loop over the 3 categories of data points
// for each category, loop over the data points and add them to the correct category in the response object
for _, dp := range dataPoints[0] {
response.Hourly = append(response.Hourly, toDataPoint(dp))
}
for _, dp := range dataPoints[1] {
response.Daily = append(response.Daily, toDataPoint(dp))
}
for _, dp := range dataPoints[2] {
response.Monthly = append(response.Monthly, toDataPoint(dp))
}

return GetWebTransactionsAggregated200JSONResponse(response), nil
}

func toDataPoint(dp data.DataPoint) DataPoint {
return DataPoint{
Timestamp: int(dp.Timestamp.Unix()),
Label: dp.Timestamp.Format(time.RFC3339),
Value: int(dp.Count),
}
}
58 changes: 57 additions & 1 deletion api/api.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
openapi: 3.0.0
info:
title: Nuts Registry Admin API
title: Nuts Monitor API
version: 1.0.0

paths:
Expand Down Expand Up @@ -44,8 +44,47 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/NetworkTopology"
/web/transactions/aggregated:
get:
summary: "Returns the transactions aggregated by time"
description: >
Returns the transactions aggregated by time. It contains three sets of data points:
- an interval of 1 hour with a resolution of 1 minute
- an interval of 1 day with a resolution of 1 hour
- an interval of 1 month with a resolution of 1 day
operationId: aggregatedTransactions
responses:
200:
description: "Aggregated transactions data"
content:
application/json:
schema:
$ref: "#/components/schemas/AggregatedTransactions"
components:
schemas:
AggregatedTransactions:
type: object
description: "Aggregated transactions data"
required:
- hourly
- daily
- monthly
properties:
hourly:
type: array
description: "Aggregated transactions data for the last hour"
items:
$ref: "#/components/schemas/DataPoint"
daily:
type: array
description: "Aggregated transactions data for the last day"
items:
$ref: "#/components/schemas/DataPoint"
monthly:
type: array
description: "Aggregated transactions data for the last month"
items:
$ref: "#/components/schemas/DataPoint"
CheckHealthResponse:
required:
- status
Expand All @@ -59,6 +98,23 @@ components:
description: Map of the performed health checks and their results.
additionalProperties:
$ref: "#/components/schemas/HealthCheckResult"
DataPoint:
type: object
description: "Data point"
required:
- timestamp
- label
- value
properties:
timestamp:
type: integer
description: "time of the data point formatted as unix timestamp"
label:
type: string
description: "time of the data point formatted as RFC3339"
value:
type: integer
description: "number of transactions between the given timestamp and the next timestamp"
Diagnostics:
required:
- network
Expand Down
87 changes: 74 additions & 13 deletions api/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,27 @@ func (hb HTTPClient) DIDDocument(ctx context.Context, did string) (*vdr.DIDResol
}
return nil, fmt.Errorf("received incorrect response from node: %s", string(result.Body))
}

// ListTransactions returns transactions in a certain range according to LC value
func (hb HTTPClient) ListTransactions(ctx context.Context, start int, end int) ([]string, error) {
var transactions []string

response, err := hb.networkClient().ListTransactions(ctx, &network.ListTransactionsParams{
Start: &start,
End: &end,
})
if err != nil {
return transactions, err
}
if err := TestResponseCode(http.StatusOK, response); err != nil {
return transactions, err
}
parsedResponse, err := network.ParseListTransactionsResponse(response)
if err != nil {
return transactions, err
}
if parsedResponse.JSON200 != nil {
return *parsedResponse.JSON200, nil
}
return transactions, nil
}
Loading