Skip to content
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
8 changes: 4 additions & 4 deletions CLAUDE.md

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions internal/api/notifications_ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,8 @@ func TestSetConnectionActive(t *testing.T) {
// with their issues, retrying messages, and the health of each connection.
func TestUIDeliveries(t *testing.T) {
server := newNotificationsServer(t)
brokenID := server.create(map[string]any{"type": "slack", "name": "Broken chat", "webhook_url": newWebhook(t).url})
brokenHook := newWebhook(t)
brokenID := server.create(map[string]any{"type": "slack", "name": "Broken chat", "webhook_url": brokenHook.url})
workingID := server.create(map[string]any{"type": "slack", "name": "Working chat", "webhook_url": newWebhook(t).url})

ctx := context.Background()
Expand Down Expand Up @@ -861,11 +862,9 @@ func TestUIDeliveries(t *testing.T) {
t.Errorf("past the end: %+v", page.Items)
}

// The message waiting an hour goes out at once; the woken worker may send it before any check of its due time.
server.must("retry_connection", map[string]any{"connection_id": brokenID}, nil)

if due, _ := server.database.DueOutbox(ctx, brokenID, time.Now().Add(time.Second), 10); len(due) != 1 {
t.Error("the waiting message must be due now")
}
waitFor(t, "the waiting message sent", func() bool { return brokenHook.count() == 1 })
}

// newest is the id of the newest outbox message of a connection.
Expand Down
3 changes: 1 addition & 2 deletions internal/api/projects_ui_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ func TestUIStorageByProject(t *testing.T) {
var storage struct {
UsedBytes int64 `json:"used_bytes"`
OtherBytes int64 `json:"other_bytes"`
Counting bool `json:"counting"`
Projects []struct {
ID int `json:"id"`
Bytes int64 `json:"bytes"`
Expand All @@ -325,7 +324,7 @@ func TestUIStorageByProject(t *testing.T) {

server.webUser(store.RoleUser, false).request(http.MethodGet, "get_storage", "", &storage)

if storage.Counting || len(storage.Projects) != len(fixtures.Projects()) {
if len(storage.Projects) != len(fixtures.Projects()) {
t.Fatalf("%+v", storage)
}

Expand Down
6 changes: 2 additions & 4 deletions internal/api/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,10 @@ type storageOutput struct {
// The cleanup starts at CleanupStartPercent of the limit and deletes down to CleanupStopPercent.
CleanupStartPercent int `json:"cleanup_start_percent"`
CleanupStopPercent int `json:"cleanup_stop_percent"`
// Projects are each project's part of Used, in list order; Other is the
// rest. No parts while Counting (data stored before is counted once).
// Projects are each project's part of Used, in list order; Other is the rest.
Projects []projectStorage `json:"projects"`
OtherBytes int64 `json:"other_bytes"`
Other string `json:"other"`
Counting bool `json:"counting,omitempty"`
}

type projectStorage struct {
Expand Down Expand Up @@ -117,7 +115,7 @@ func (handler *handlers) getStorage(ctx context.Context, call Call, input storag
UsedBytes: storage.UsedBytes, Used: storage.Used, LimitBytes: storage.LimitBytes, Limit: storage.Limit,
Percent: storage.Percent, FilesBytes: storage.FilesBytes, Files: storage.Files,
CleanupStartPercent: storage.CleanupStartPercent, CleanupStopPercent: storage.CleanupStopPercent,
Projects: []projectStorage{}, OtherBytes: storage.OtherBytes, Other: storage.Other, Counting: storage.Counting,
Projects: []projectStorage{}, OtherBytes: storage.OtherBytes, Other: storage.Other,
}

for _, project := range storage.Projects {
Expand Down
13 changes: 4 additions & 9 deletions internal/services/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,9 @@ type Storage struct {
// Projects are the parts of UsedBytes of the current projects the
// viewer sees, in list order; Other is the rest (the projects not seen,
// users, sessions, settings, history, data of deleted projects).
// Without parts while Counting.
Projects []ProjectStorage
OtherBytes int64
Other string
// Counting: data stored before the project sizes is still being counted.
Counting bool
}

// ProjectStorage is a project's part of the database on disk, as the
Expand Down Expand Up @@ -305,7 +302,7 @@ func (service *Projects) Storage(ctx context.Context, access store.Access, only
used := usage.Live
storage := Storage{
UsedBytes: used, Used: config.FormatSize(used), FilesBytes: usage.Files, Files: config.FormatSize(usage.Files),
CleanupStartPercent: config.CleanupStartPercent, CleanupStopPercent: config.CleanupStopPercent, Counting: usage.Counting,
CleanupStartPercent: config.CleanupStartPercent, CleanupStopPercent: config.CleanupStopPercent,
}

if limit := service.retention.MaxDatabaseBytes; limit > 0 {
Expand All @@ -332,11 +329,9 @@ func (service *Projects) Storage(ctx context.Context, access store.Access, only
part.LastReceived = &last
}

if !usage.Counting {
part.Bytes = min(storage.OtherBytes, usage.OnDisk[project.ID])
part.Size = config.FormatSize(part.Bytes)
storage.OtherBytes -= part.Bytes
}
part.Bytes = min(storage.OtherBytes, usage.OnDisk[project.ID])
part.Size = config.FormatSize(part.Bytes)
storage.OtherBytes -= part.Bytes

storage.Projects = append(storage.Projects, part)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/storage/database/project_usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestProjectUsage(t *testing.T) {
}
}

if got := usage(t, database); len(got.Bytes) != 0 || len(got.LastReceived) != 0 || got.Counting {
if got := usage(t, database); len(got.Bytes) != 0 || len(got.LastReceived) != 0 {
t.Fatalf("empty database: %+v", got)
}

Expand Down
3 changes: 0 additions & 3 deletions internal/storage/store/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,4 @@ type ProjectUsage struct {
FirstContact map[int]time.Time
// Oldest is what each project still keeps, by the kinds the cleanup deletes.
Oldest map[int]OldestKept
// Counting: data stored before the per-project counters is still being
// counted (once, in the background), so Bytes fall short until it is done.
Counting bool
}
1 change: 0 additions & 1 deletion web/src/lib/api/catalog.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ export interface Endpoints {
})[] | null;
other_bytes: number;
other: string;
counting?: boolean;
};
};
get_user: {
Expand Down
4 changes: 0 additions & 4 deletions web/src/lib/projects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ describe('usageSegments', () => {
{ label: 'Other: 100 B', percent: 10 }
]);
});

it('shows nothing while counting', () => {
expect(usageSegments({ ...storage, counting: true }, () => undefined)).toEqual([]);
});
});

describe('errorsKept', () => {
Expand Down
4 changes: 2 additions & 2 deletions web/src/lib/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ export function bySize<Project extends { id: number }>(

/**
* The storage bar's segments: each project's part of the database in its color, then the rest,
* in percent of the limit. None while the sizes are counted.
* in percent of the limit.
*/
export function usageSegments(
storage: Out<'get_storage'>,
colorOf: (name: string) => string | undefined
): UsageSegment[] {
if (storage.counting || !storage.limit_bytes) return [];
if (!storage.limit_bytes) return [];

const percent = (bytes: number) => (bytes * 100) / storage.limit_bytes;
const segments: UsageSegment[] = partsBySize(storage)
Expand Down
43 changes: 21 additions & 22 deletions web/src/routes/(app)/projects/ProjectsPage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import Dialog from '#lib/components/Dialog.svelte';
import FormDialog from '#lib/components/FormDialog.svelte';
import Hint from '#lib/components/Hint.svelte';
import Icon from '#lib/components/Icon.svelte';
import LevelSummary from '#lib/components/LevelSummary.svelte';
import type { MenuItem } from '#lib/components/menu.ts';
import PageHeading from '#lib/components/PageHeading.svelte';
Expand Down Expand Up @@ -230,39 +231,39 @@
waiting to be stored.
</p>
<p class="text-xs text-muted">
{#if storage.counting}
Counting what each project holds…
{/if}
At {storage.cleanup_start_percent}% of the limit the least useful data is deleted until the
database holds {storage.cleanup_stop_percent}%: old logs first, errors last.
<code>MAX_DATABASE_SIZE</code>
<Hint text={help.settings.MAX_DATABASE_SIZE} />
</p>
</div>
{#if droppedAllLine}
<p class="text-xs">
<Notice tone="warning" compact>
{@render droppedLink(`${droppedAllLine} in all projects`, 'all projects', droppedAll)}
</p>
</Notice>
{/if}
{/if}
</Card>

<!-- What was dropped: a link to its reasons when the last 24 hours have some. -->
<!-- What was dropped, after a warning mark: a link to its reasons when the last 24 hours have some. -->
{#snippet droppedLink(text: string, name: string, rows: DroppedRow[])}
{#if rows.length}
<Button
variant="link"
popup="dialog"
onclick={() => {
droppedOf = { name, rows };
droppedOpen = true;
}}
>
{text}
</Button>
{:else}
<span class="text-muted">{text}</span>
{/if}
<span class="inline-flex items-center gap-1.5">
<span class="text-warning"><Icon name="warning" size={14} /></span>
{#if rows.length}
<Button
variant="link"
popup="dialog"
onclick={() => {
droppedOf = { name, rows };
droppedOpen = true;
}}
>
{text}
</Button>
{:else}
<span>{text}</span>
{/if}
</span>
{/snippet}

<Table
Expand Down Expand Up @@ -297,8 +298,6 @@
{:else if column.key === 'size'}
{#if !storage}
<span class="text-muted">…</span>
{:else if storage.counting}
<span class="text-xs text-muted">counting…</span>
{:else}
{part?.size ?? '—'}
{/if}
Expand Down
Loading