This adds the `update_sessions_pending_daily_snapshot` SQL function
which updates the `sessions_pending_daily_snapshot` table by inserting
values for any days missing from the table.
This also adds a check constraint to the
`sessions_pending_daily_snapshot` table along with a `comment on table`.
This also removes the hcp daily billing views since they are no longer
needed.
Ref: ace2def49d
The hcp monthly billing views build a range of buckets using the
`generate_series` and the `now()` functions along with relative offsets
like `+ 1 month`. The calculated start and end times for these views can
vary depending on the time zone setting of the PostgreSQL server.
This adds 3 table functions that call their respective views with the
time zone set to UTC. Calling these functions instead of their
underlying views directly prevents the returned values from varying when
the server's time zone is not set to UTC.
This also drops support for PostgreSQL 11. The included tests use the
`date_trunc(field, source [, time_zone ])` function added in PostgreSQL
12.
Fixes: 41b1b5b4b7
The hcp billing `_all` views built a range of buckets using the
`generate_series` function using the minimum value of the
`session_pending_time` column from the `wh_session_accumulating_fact`
table as the start time and `now()` as the end time. It then truncated
values in the series using the `date_trunc` function. This allowed the
generated series of buckets returned to vary and could result in one
additional bucket being included in the series depending on the current
time and the start time.
As an illustrative example, the `hourly_all` query used:
select date_trunc('hour',time)
from generate_series(
(select min(session_pending_time) -- start time
from wh_session_accumulating_fact),
now(),
'1 hour'::interval
) as time;
Substituting the start time with a hard coded value to show the issue:
-- Show current time, where the minutes portion is 55
select now();
now
-------------------------------
2023-05-22 14:55:40.567605+00
(1 row)
-- generate series with start time's minutes portion at 57
select date_trunc('hour',time)
from generate_series(
'2023-05-22 01:57:00'::timestamptz,
now(),
'1 hour'::interval
) as time;
date_trunc
------------------------
2023-05-22 01:00:00+00
2023-05-22 02:00:00+00
2023-05-22 03:00:00+00
2023-05-22 04:00:00+00
2023-05-22 05:00:00+00
2023-05-22 06:00:00+00
2023-05-22 07:00:00+00
2023-05-22 08:00:00+00
2023-05-22 09:00:00+00
2023-05-22 10:00:00+00
2023-05-22 11:00:00+00
2023-05-22 12:00:00+00
2023-05-22 13:00:00+00
(13 rows)
-- Wait a few minutes
select now();
now
------------------------------
2023-05-22 14:58:48.75287+00
(1 row)
-- Now run again and get an extra result, even though still
-- within the same hour
select date_trunc('hour',time)
from generate_series(
'2023-05-22 01:57:00'::timestamptz,
now(),
'1 hour'::interval
) as time;
date_trunc
------------------------
2023-05-22 01:00:00+00
2023-05-22 02:00:00+00
2023-05-22 03:00:00+00
2023-05-22 04:00:00+00
2023-05-22 05:00:00+00
2023-05-22 06:00:00+00
2023-05-22 07:00:00+00
2023-05-22 08:00:00+00
2023-05-22 09:00:00+00
2023-05-22 10:00:00+00
2023-05-22 11:00:00+00
2023-05-22 12:00:00+00
2023-05-22 13:00:00+00
2023-05-22 14:00:00+00
(14 rows)
To fix this, we call the `generate_series` function truncating the start
time argument to the bucket size:
-- Hourly
select bucket
from generate_series(
date_trunc('hour', select min(session_pending_time)
from wh_session_accumulating_fact)),
now(),
'1 hour'::interval
) as bucket;
-- Monthly
select bucket
from generate_series(
date_trunc('month', select min(session_pending_time)
from wh_session_accumulating_fact)),
now(),
'1 month'::interval
) as bucket;
Fixes: 41b1b5b4b7
Certain tests fail when run on the first day of the month because of
edge cases in the setup of test data. This adds conditional logic to
skip those tests when run on the first day of a month.
* proto: correct classification of authz token
The target authorization token had the invalid classification
"private". Fortunately, classification is a fail-closed system,
so this won't have exposed users authorization tokens, but
we should still use the correct classification. Use "secret".
* scripts: add Go script to remove gotags comments
The new version of grpc-gateway includes our gotags
comments in the generate swagger documentation. This
script removes all mentions of these.
* Upgrade grpc-gateway dependency
Mainly we need this to fix generation of our docs side API docs,
but it also includes a nice fix for the new Download RPC, i.e. it
now contains the correct response schema (a binary stream).
For requests to the target authorize session endpoint we support passing
a target name instead of an id. This means that `req.GetId()` might not
be the target's public id. Since the first thing authorize session does
includes retrieving the target as part of the authorization checks, this
subtype check can leverage the public id of the target instead of using
the request.
Fixes: 6178dd516e
When an SSH channel is used for a file transfer, the summary will report
the detected direction of the file transfer as either an upload or
download, relative to the end client.
The session metadata is provided all at once when a new bsr is opened.
While the session recording metadata records metadata about a recording
while the recording is happening, notably it records each time a new
connection occurs.
The nested structure of the session metadata does not lend itself to the
append-only syntax of the recording meta file. In addition we do not
want to mix different kinds of metadata together. Thus the session
metadata is now written to a separate file in the BSR, and is written as
JSON which better handles the nested structure and allows for simpler
encoding/decoding.
Similarly the summary files are intended to be written to as containers
close and have been switched to JSON.