mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-09-12 17:40:43 +02:00
* fix(admin): use protocol-relative URLs for component links Hardcoded http:// in admin UI templates breaks browser-initiated clicks to master / volume / filer / EC shard / Iceberg REST URLs whenever the target component runs HTTPS-only via security.toml [https.X] sections. The browser sends plain HTTP to a TLS-only endpoint and gets 400 "client sent an HTTP request to an HTTPS server". Same root pattern as #9227 (admin's own backend /dir/status fetch); this PR is the browser-facing equivalent. Replace fmt.Sprintf("http://%s...") with fmt.Sprintf("//%s...") and the JS-string '<a href="http://' with '<a href="//' so the browser uses the same scheme as the page hosting the link. Backwards compatible: - HTTPS-only deployments: links now work - HTTP-only deployments: identical behavior to before - Mixed: edge case, addressed by future per-component public-URL work Affected templates (9 files), each kept in lockstep with its generated _templ.go sibling so reviewers don't need to run templ generate: - weed/admin/view/app/admin.templ - weed/admin/view/app/cluster_filers.templ - weed/admin/view/app/cluster_masters.templ (Go templ + JS modal) - weed/admin/view/app/cluster_volume_servers.templ (Go templ + JS modal) - weed/admin/view/app/cluster_volumes.templ - weed/admin/view/app/ec_volume_details.templ - weed/admin/view/app/volume_details.templ - weed/admin/view/app/iceberg_catalog.templ - weed/admin/view/app/s3tables_buckets.templ 17 link constructions total, +32/-32 lines. * fix(admin): protocol-relative URLs in iceberg + s3tables JS overrides Per Gemini code review on this PR: the JS scripts in iceberg_catalog and s3tables_buckets templates overwrite the href attribute of the "Open Iceberg REST" links after page load, replacing the protocol-relative URL set by the templ render with a hardcoded http://<host>:<port>/v1/config. Apply the same protocol-relative fix to the JS template literals so they don't undo the templ-side change. Browser uses the page scheme (http or https) to fill in the protocol. Mirrored in iceberg_catalog_templ.go and s3tables_buckets_templ.go. * fix(admin): displayed Iceberg endpoint scheme follows page protocol Per CodeRabbit review on this PR: the on-page guidance text in iceberg and s3tables templates still showed a literal `http://` even after the clickable link was switched to a protocol-relative URL. In HTTPS-only deployments operators see `http://host:8181/v1` as the suggested endpoint, copy it, and get a broken connection. Wrap the scheme in <span id="iceberg-protocol"> (and the s3tables counterpart) and have the existing inline script set its innerText to window.location.protocol minus the trailing colon. Same pattern as the existing dynamic host substitution. Mirrored in *_templ.go so reviewers do not need templ generate. SQL/JSON code-block examples (CREATE EXTERNAL TABLE ... ENDPOINT 'http://...', "uri": "http://..." ) are intentionally left as-is — they are starter snippets users adapt to their environment, not clickable or copy-paste-into-runtime values. Happy to follow up with server-side scheme threading if requested.
336 lines
16 KiB
Templ
336 lines
16 KiB
Templ
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/seaweedfs/seaweedfs/weed/admin/dash"
|
|
"github.com/seaweedfs/seaweedfs/weed/storage/erasure_coding"
|
|
)
|
|
|
|
templ EcVolumeDetails(data dash.EcVolumeDetailsData) {
|
|
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
|
|
<div>
|
|
<h1 class="h2">
|
|
<i class="fas fa-th-large me-2"></i>EC Volume Details
|
|
</h1>
|
|
<nav aria-label="breadcrumb">
|
|
<ol class="breadcrumb">
|
|
<li class="breadcrumb-item"><a href={ dash.PUrl(ctx, "/admin") } class="text-decoration-none">Dashboard</a></li>
|
|
<li class="breadcrumb-item"><a href={ dash.PUrl(ctx, "/storage/ec-shards") } class="text-decoration-none">EC Volumes</a></li>
|
|
<li class="breadcrumb-item active" aria-current="page">Volume {fmt.Sprintf("%d", data.VolumeID)}</li>
|
|
</ol>
|
|
</nav>
|
|
</div>
|
|
<div class="btn-toolbar mb-2 mb-md-0">
|
|
<div class="btn-group me-2">
|
|
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="history.back()">
|
|
<i class="fas fa-arrow-left me-1"></i>Back
|
|
</button>
|
|
<button type="button" class="btn btn-sm btn-outline-primary" onclick="window.location.reload()">
|
|
<i class="fas fa-refresh me-1"></i>Refresh
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- EC Volume Summary -->
|
|
<div class="row mb-4">
|
|
<div class="col-md-6">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="card-title mb-0">
|
|
<i class="fas fa-info-circle me-2"></i>Volume Information
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<table class="table table-borderless">
|
|
<tr>
|
|
<td><strong>Volume ID:</strong></td>
|
|
<td>{fmt.Sprintf("%d", data.VolumeID)}</td>
|
|
</tr>
|
|
<tr>
|
|
<td><strong>Collection:</strong></td>
|
|
<td>
|
|
if data.Collection != "" {
|
|
<span class="badge bg-info">{data.Collection}</span>
|
|
} else {
|
|
<span class="text-muted">default</span>
|
|
}
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td><strong>Status:</strong></td>
|
|
<td>
|
|
if data.IsComplete {
|
|
<span class="badge bg-success">
|
|
<i class="fas fa-check me-1"></i>Complete ({data.TotalShards}/{fmt.Sprintf("%d", erasure_coding.TotalShardsCount)} shards)
|
|
</span>
|
|
} else {
|
|
<span class="badge bg-warning">
|
|
<i class="fas fa-exclamation-triangle me-1"></i>Incomplete ({data.TotalShards}/{fmt.Sprintf("%d", erasure_coding.TotalShardsCount)} shards)
|
|
</span>
|
|
}
|
|
</td>
|
|
</tr>
|
|
if !data.IsComplete {
|
|
<tr>
|
|
<td><strong>Missing Shards:</strong></td>
|
|
<td>
|
|
for i, shardID := range data.MissingShards {
|
|
if i > 0 {
|
|
<span>, </span>
|
|
}
|
|
@renderEcShardBadge(uint32(shardID), true)
|
|
}
|
|
</td>
|
|
</tr>
|
|
}
|
|
<tr>
|
|
<td><strong>Data Centers:</strong></td>
|
|
<td>
|
|
for i, dc := range data.DataCenters {
|
|
if i > 0 {
|
|
<span>, </span>
|
|
}
|
|
<span class="badge bg-primary">{dc}</span>
|
|
}
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td><strong>Servers:</strong></td>
|
|
<td>
|
|
<span class="text-muted">{fmt.Sprintf("%d servers", len(data.Servers))}</span>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td><strong>Last Updated:</strong></td>
|
|
<td>
|
|
<span class="text-muted">{data.LastUpdated.Format("2006-01-02 15:04:05")}</span>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="col-md-6">
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="card-title mb-0">
|
|
<i class="fas fa-chart-pie me-2"></i>Shard Distribution
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="row text-center">
|
|
<div class="col-4">
|
|
<div class="border rounded p-3">
|
|
<h3 class="text-primary mb-1">{fmt.Sprintf("%d", data.TotalShards)}</h3>
|
|
<small class="text-muted">Total Shards</small>
|
|
</div>
|
|
</div>
|
|
<div class="col-4">
|
|
<div class="border rounded p-3">
|
|
<h3 class="text-success mb-1">{fmt.Sprintf("%d", len(data.DataCenters))}</h3>
|
|
<small class="text-muted">Data Centers</small>
|
|
</div>
|
|
</div>
|
|
<div class="col-4">
|
|
<div class="border rounded p-3">
|
|
<h3 class="text-info mb-1">{fmt.Sprintf("%d", len(data.Servers))}</h3>
|
|
<small class="text-muted">Servers</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Shard Distribution Visualization -->
|
|
<div class="mt-3">
|
|
<h6>Present Shards:</h6>
|
|
<div class="d-flex flex-wrap gap-1">
|
|
for _, shard := range data.Shards {
|
|
@renderEcShardBadge(shard.ShardID, false)
|
|
}
|
|
</div>
|
|
<div class="small text-muted mt-2">
|
|
<span class="badge bg-primary me-1">Data</span>
|
|
<span class="badge bg-warning text-dark me-2">Parity</span>
|
|
Data shards are blue, parity shards are yellow.
|
|
</div>
|
|
if len(data.MissingShards) > 0 {
|
|
<h6 class="mt-2">Missing Shards:</h6>
|
|
<div class="d-flex flex-wrap gap-1">
|
|
for _, shardID := range data.MissingShards {
|
|
@renderEcShardBadge(uint32(shardID), true)
|
|
}
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Shard Details Table -->
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h5 class="card-title mb-0">
|
|
<i class="fas fa-list me-2"></i>Shard Details
|
|
</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
if len(data.Shards) > 0 {
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>
|
|
<a href="#" onclick="sortBy('shard_id')" class="text-dark text-decoration-none">
|
|
Shard ID
|
|
if data.SortBy == "shard_id" {
|
|
if data.SortOrder == "asc" {
|
|
<i class="fas fa-sort-up ms-1"></i>
|
|
} else {
|
|
<i class="fas fa-sort-down ms-1"></i>
|
|
}
|
|
} else {
|
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
|
}
|
|
</a>
|
|
</th>
|
|
<th>
|
|
<a href="#" onclick="sortBy('server')" class="text-dark text-decoration-none">
|
|
Server
|
|
if data.SortBy == "server" {
|
|
if data.SortOrder == "asc" {
|
|
<i class="fas fa-sort-up ms-1"></i>
|
|
} else {
|
|
<i class="fas fa-sort-down ms-1"></i>
|
|
}
|
|
} else {
|
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
|
}
|
|
</a>
|
|
</th>
|
|
<th>
|
|
<a href="#" onclick="sortBy('data_center')" class="text-dark text-decoration-none">
|
|
Data Center
|
|
if data.SortBy == "data_center" {
|
|
if data.SortOrder == "asc" {
|
|
<i class="fas fa-sort-up ms-1"></i>
|
|
} else {
|
|
<i class="fas fa-sort-down ms-1"></i>
|
|
}
|
|
} else {
|
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
|
}
|
|
</a>
|
|
</th>
|
|
<th>
|
|
<a href="#" onclick="sortBy('rack')" class="text-dark text-decoration-none">
|
|
Rack
|
|
if data.SortBy == "rack" {
|
|
if data.SortOrder == "asc" {
|
|
<i class="fas fa-sort-up ms-1"></i>
|
|
} else {
|
|
<i class="fas fa-sort-down ms-1"></i>
|
|
}
|
|
} else {
|
|
<i class="fas fa-sort ms-1 text-muted"></i>
|
|
}
|
|
</a>
|
|
</th>
|
|
<th class="text-dark">Disk Type</th>
|
|
<th class="text-dark">Shard Size</th>
|
|
<th class="text-dark">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
for _, shard := range data.Shards {
|
|
<tr>
|
|
<td>
|
|
@renderEcShardBadge(shard.ShardID, false)
|
|
</td>
|
|
<td>
|
|
<a href={ dash.PUrl(ctx, "/cluster/volume-servers/" + shard.Server) } class="text-primary text-decoration-none">
|
|
<code class="small">{shard.Server}</code>
|
|
</a>
|
|
</td>
|
|
<td>
|
|
<span class="badge bg-primary text-white">{shard.DataCenter}</span>
|
|
</td>
|
|
<td>
|
|
<span class="badge bg-secondary text-white">{shard.Rack}</span>
|
|
</td>
|
|
<td>
|
|
<span class="text-dark">{shard.DiskType}</span>
|
|
</td>
|
|
<td>
|
|
<span class="text-success">{bytesToHumanReadableUint64(shard.Size)}</span>
|
|
</td>
|
|
<td>
|
|
<a href={ templ.SafeURL(fmt.Sprintf("//%s/ui/index.html", shard.Server)) } target="_blank" rel="noopener noreferrer" class="btn btn-sm btn-primary">
|
|
<i class="fas fa-external-link-alt me-1"></i>Volume Server
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
} else {
|
|
<div class="text-center py-4">
|
|
<i class="fas fa-exclamation-triangle fa-3x text-warning mb-3"></i>
|
|
<h5>No EC shards found</h5>
|
|
<p class="text-muted">This volume may not be EC encoded yet.</p>
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Sorting functionality
|
|
function sortBy(field) {
|
|
const currentSort = new URLSearchParams(window.location.search).get('sort_by');
|
|
const currentOrder = new URLSearchParams(window.location.search).get('sort_order') || 'asc';
|
|
|
|
let newOrder = 'asc';
|
|
if (currentSort === field && currentOrder === 'asc') {
|
|
newOrder = 'desc';
|
|
}
|
|
|
|
const url = new URL(window.location);
|
|
url.searchParams.set('sort_by', field);
|
|
url.searchParams.set('sort_order', newOrder);
|
|
window.location.href = url.toString();
|
|
}
|
|
</script>
|
|
}
|
|
|
|
templ renderEcShardBadge(shardID uint32, missing bool) {
|
|
if shardID < erasure_coding.DataShardsCount {
|
|
if missing {
|
|
<span class="badge bg-primary opacity-50 me-1 mb-1" title={ fmt.Sprintf("Missing data shard %d", shardID) }>{ fmt.Sprintf("D%02d", shardID) }</span>
|
|
} else {
|
|
<span class="badge bg-primary me-1 mb-1" title={ fmt.Sprintf("Data shard %d", shardID) }>{ fmt.Sprintf("D%02d", shardID) }</span>
|
|
}
|
|
} else {
|
|
if missing {
|
|
<span class="badge bg-warning text-dark opacity-50 me-1 mb-1" title={ fmt.Sprintf("Missing parity shard %d", shardID) }>{ fmt.Sprintf("P%02d", shardID) }</span>
|
|
} else {
|
|
<span class="badge bg-warning text-dark me-1 mb-1" title={ fmt.Sprintf("Parity shard %d", shardID) }>{ fmt.Sprintf("P%02d", shardID) }</span>
|
|
}
|
|
}
|
|
}
|
|
|
|
// Helper function to convert bytes to human readable format (uint64 version)
|
|
func bytesToHumanReadableUint64(bytes uint64) string {
|
|
const unit = 1024
|
|
if bytes < unit {
|
|
return fmt.Sprintf("%dB", bytes)
|
|
}
|
|
div, exp := uint64(unit), 0
|
|
for n := bytes / unit; n >= unit; n /= unit {
|
|
div *= unit
|
|
exp++
|
|
}
|
|
return fmt.Sprintf("%.1f%cB", float64(bytes)/float64(div), "KMGTPE"[exp])
|
|
}
|