Skip to content

Commit

Permalink
UML-3706 fix stats in Admin portal (#2948)
Browse files Browse the repository at this point in the history
* accounts_created added to auth_onelogin_accounts_created to get correct
totals now we moved to OneLogin

* reduce code coverage requirement for admin for now

* WIP turn off coverage entirely in build for admin to see if this is the
problem

* fix typo

* fix syntax, re-enable coverage

* add stats together

* seeding with auth_onelogin stat

* make linter happy

* add stats for activation key and seed db

* put an add in the test template to ensure coverage of this function

* enhance test, see if coverage recognises this

* fix test

* fixes

* move api-web onto 9010 so it doesn't clash with admin on 9005, update
README to reflect this,  fix go linting
  • Loading branch information
nickdavis2001 authored Nov 27, 2024
1 parent 9db963c commit 90039f2
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ The Viewer service will be available via [http://localhost:9001/home](http://loc

The Actor service will be available via [http://localhost:9002/home](http://localhost:9002/home)

The API service will be available via [http://localhost:9003](http://localhost:9003)
The API service will be available via [http://localhost:9010](http://localhost:9010)

### Tests

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ services:
volumes:
- ./service-api/web/dist:/web
ports:
- 9005:80
- 9010:80
environment:
APP_HOST: api-app
APP_PORT: 9000
Expand Down
5 changes: 5 additions & 0 deletions service-admin/internal/server/export_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package server

// export private template methods as public, when running tests

var Add = add
42 changes: 24 additions & 18 deletions service-admin/internal/server/handlers/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ func Test_GetAllMetrics(t *testing.T) {
if list[0] == "2022-11" {
return map[string]map[string]float64{
"2022-11": {
"lpas_added": 1,
"lpa_removed_event": 1,
"account_created_event": 5,
"lpas_added": 1,
"lpa_removed_event": 1,
"account_created_event": 5,
"auth_onelogin_account_created_event": 5,
},
}, nil
}
Expand All @@ -73,9 +74,10 @@ func Test_GetAllMetrics(t *testing.T) {
},
want: map[string]map[string]float64{
"2022-11": {
"lpas_added": 1,
"lpa_removed_event": 1,
"account_created_event": 5,
"lpas_added": 1,
"lpa_removed_event": 1,
"account_created_event": 5,
"auth_onelogin_account_created_event": 5,
},
},
},
Expand Down Expand Up @@ -110,24 +112,28 @@ func TestTemplateErrorPanic(t *testing.T) {

testMetrics := &map[string]map[string]float64{
"2022-11": {
"lpas_added": 1,
"lpa_removed_event": 1,
"account_created_event": 5,
"lpas_added": 1,
"lpa_removed_event": 1,
"account_created_event": 5,
"auth_onelogin_account_created_event": 5,
},
"2022-10": {
"lpas_added": 4,
"lpa_removed_event": 2,
"account_created_event": 7,
"lpas_added": 4,
"lpa_removed_event": 2,
"account_created_event": 7,
"auth_onelogin_account_created_event": 7,
},
"2022-09": {
"lpas_added": 3,
"lpa_removed_event": 1,
"account_created_event": 4,
"lpas_added": 3,
"lpa_removed_event": 1,
"account_created_event": 4,
"auth_onelogin_account_created_event": 4,
},
"Total": {
"lpas_added": 10,
"lpa_removed_event": 11,
"account_created_event": 12,
"lpas_added": 10,
"lpa_removed_event": 11,
"account_created_event": 12,
"auth_onelogin_account_created_event": 12,
},
}

Expand Down
11 changes: 11 additions & 0 deletions service-admin/internal/server/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func LoadTemplates(folder fs.FS) *Templates {
t := template.New("")
t = t.Funcs(template.FuncMap{
"readableDateTime": readableDateTime,
"add": add,
})

files, err := fs.Glob(folder, "*.page.gohtml")
Expand Down Expand Up @@ -95,3 +96,13 @@ func readableDateTime(date string) string {

return t.In(l).Format("2 January 2006 at 3:04PM")
}

func add(nums ...float64) float64 {
total := 0.0

for _, num := range nums {
total += num
}

return total
}
10 changes: 9 additions & 1 deletion service-admin/internal/server/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func testFS() (fs.FS, error) {
return nil, err
}

err = afero.WriteFile(fs, "test.partial.gohtml", []byte("{{ define \"partial\" }}World{{ end }}"), 0644)
err = afero.WriteFile(fs, "test.partial.gohtml", []byte("{{ define \"partial\" }}World{{ $test_var := add 2 3}}{{ printf \"%.0f\" $test_var }}{{ end }}"), 0644)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -116,3 +116,11 @@ func TestWithTemplates(t *testing.T) {

assert.HTTPSuccess(t, sut.ServeHTTP, "GET", "/", nil, "handler not successfully running")
}

func TestAdd(t *testing.T) {
t.Parallel()

result := Add(1, 2, 3)

assert.Equal(t, result, 6.0)
}
7 changes: 5 additions & 2 deletions service-admin/web/templates/stats.page.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Accounts created</th>
{{range .Result}}
<td class="govuk-table__cell">{{ printf "%.0f" .account_created_event }}</td>
{{ $accounts_created := add .account_created_event .auth_onelogin_account_created_event }}
<td class="govuk-table__cell">{{ printf "%.0f" $accounts_created }}</td>
{{end}}
</tr>

<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Accounts deleted</th>
{{range .Result}}
Expand Down Expand Up @@ -76,7 +78,8 @@
<tr class="govuk-table__row">
<th scope="row" class="govuk-table__header">Activation key requested</th>
{{range .Result}}
<td class="govuk-table__cell">{{ printf "%.0f" .account_activated_event }}</td>
{{ $accounts_activated := add .older_lpa_needs_cleansing_event .older_lpa_force_activation_key_event .older_lpa_success_event .oolpa_key_requested_for_donor_event .oolpa_key_requested_for_attorney_event}}
<td class="govuk-table__cell">{{ printf "%.0f" $accounts_activated }}</td>
{{end}}
</tr>
<tr class="govuk-table__row">
Expand Down
32 changes: 31 additions & 1 deletion service-api/seeding/dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
'lpas_added': 35,
'lpa_removed_event': 40,
'account_created_event': 30,
'auth_onelogin_account_created_event': 40,
'account_deleted_event': 30,
'account_activated_event': 20,
'viewer_codes_created': 10,
Expand All @@ -261,6 +262,10 @@
'added_lpa_type_pfa_event' : 30,
'download_summary_event' : 20,
'older_lpa_needs_cleansing_event' : 34,
'older_lpa_force_activation_key_event' : 35,
'older_lpa_success_event' : 36,
'oolpa_key_requested_for_donor_event' : 12,
'oolpa_key_requested_for_attorney_event' : 13,
'view_lpa_share_code_expired_event' : 35,
'user_abroad_address_request_success_event' : 27,
'full_match_key_request_success_lpa_type_hw_event' : 45,
Expand All @@ -274,6 +279,7 @@
'lpas_added': 5,
'lpa_removed_event': 6,
'account_created_event': 3,
'auth_onelogin_account_created_event': 4,
'account_deleted_event': 2,
'account_activated_event': 2,
'viewer_codes_created': 2,
Expand All @@ -282,6 +288,10 @@
'added_lpa_type_pfa_event' : 7,
'download_summary_event' : 4,
'older_lpa_needs_cleansing_event' : 6,
'older_lpa_force_activation_key_event' : 7,
'older_lpa_success_event' : 8,
'oolpa_key_requested_for_donor_event' : 12,
'oolpa_key_requested_for_attorney_event' : 13,
'view_lpa_share_code_expired_event' : 6,
'user_abroad_address_request_success_event' : 6,
'full_match_key_request_success_lpa_type_hw_event' : 4,
Expand All @@ -293,14 +303,19 @@
'lpas_added': 3,
'lpa_removed_event': 7,
'account_created_event': 5,
'auth_onelogin_account_created_event': 6,
'account_deleted_event': 1,
'account_activated_event': 15,
'viewer_codes_created': 4,
'viewer_codes_viewed' : 3,
'added_lpa_type_hw_event' : 7,
'added_lpa_type_pfa_event' : 6,
'download_summary_event' : 7,
'older_lpa_needs_cleansing_event' : 6,
'older_lpa_needs_cleansing_event' : 12,
'older_lpa_force_activation_key_event' : 14,
'older_lpa_success_event' : 16,
'oolpa_key_requested_for_donor_event' : 22,
'oolpa_key_requested_for_attorney_event' : 23,
'view_lpa_share_code_expired_event' : 6,
'user_abroad_address_request_success_event' : 5,
'full_match_key_request_success_lpa_type_hw_event' : 4,
Expand All @@ -312,6 +327,7 @@
'lpas_added': 7,
'lpa_removed_event': 8,
'account_created_event': 12,
'auth_onelogin_account_created_event': 13,
'account_deleted_event': 3,
'account_activated_event': 12,
'viewer_codes_created': 2,
Expand All @@ -320,6 +336,10 @@
'added_lpa_type_pfa_event' : 6,
'download_summary_event' : 7,
'older_lpa_needs_cleansing_event' : 6,
'older_lpa_force_activation_key_event' : 7,
'older_lpa_success_event' : 8,
'oolpa_key_requested_for_donor_event' : 32,
'oolpa_key_requested_for_attorney_event' : 33,
'view_lpa_share_code_expired_event' : 6,
'user_abroad_address_request_success_event' : 5,
'full_match_key_request_success_lpa_type_hw_event' : 4,
Expand All @@ -332,6 +352,7 @@
'lpas_added': 5,
'lpa_removed_event': 9,
'account_created_event': 15,
'auth_onelogin_account_created_event': 16,
'account_deleted_event': 1,
'account_activated_event': 9,
'viewer_codes_created': 1,
Expand All @@ -340,6 +361,10 @@
'added_lpa_type_pfa_event' : 8,
'download_summary_event' : 7,
'older_lpa_needs_cleansing_event' : 6,
'older_lpa_force_activation_key_event' : 7,
'older_lpa_success_event' : 8,
'oolpa_key_requested_for_donor_event' : 42,
'oolpa_key_requested_for_attorney_event' : 43,
'view_lpa_share_code_expired_event' : 6,
'user_abroad_address_request_success_event' : 6,
'full_match_key_request_success_lpa_type_hw_event' : 4,
Expand All @@ -353,6 +378,7 @@
'lpas_added': 15,
'lpa_removed_event': 10,
'account_created_event': 6,
'auth_onelogin_account_created_event': 7,
'account_deleted_event': 4,
'account_activated_event': 12,
'viewer_codes_created': 1,
Expand All @@ -361,6 +387,10 @@
'added_lpa_type_pfa_event' : 8,
'download_summary_event' : 7,
'older_lpa_needs_cleansing_event' : 6,
'older_lpa_force_activation_key_event' : 7,
'older_lpa_success_event' : 8,
'oolpa_key_requested_for_donor_event' : 12,
'oolpa_key_requested_for_attorney_event' : 13,
'view_lpa_share_code_expired_event' : 6,
'user_abroad_address_request_success_event' : 6,
'full_match_key_request_success_lpa_type_hw_event' : 4,
Expand Down

0 comments on commit 90039f2

Please sign in to comment.