-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add visualization tool to debug image sources
- Loading branch information
1 parent
d69c1fb
commit 8cb0c12
Showing
12 changed files
with
533 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,20 +13,23 @@ Read the [benchmark documentation](./BENCHMARK.md) for information of expected g | |
|
||
## How do I know that Spegel is working? | ||
|
||
Spegel is meant to be a painless experience to install, meaning that it may be difficult initially to know if things are working or not. Simply put a good indicator that things are working is if all Spegel pods have started and are in a ready state. | ||
Spegel does a couple of checks on startup to verify that any required configuration is correct, if it is not it will exit with an error. While it runs it will log all received requests, both those it mirrors and it serves. | ||
Spegel is meant to be a painless experience to install. Image pulls will fallback to the original registry if Spegel does not work, meaning that it can be difficult to determine if things are working or not. Spegel has a UI that visualizes incoming and outgoing requests, this will allow you understand if images are pulled from other Spegel instances or not. | ||
|
||
An incoming request to Spegel that is mirrored will receive the following log. | ||
The UI is disabled by default as it adds additional overhead. To access the UI enable the feature in the Helm values. | ||
|
||
``` | ||
{"level":"info","ts":1692304805.9038486,"caller":"[email protected]/logger.go:53","msg":"","path":"/v2/library/nginx/blobs/sha256:1cb127bd932119089b5ffb612ffa84537ddd1318e6784f2fce80916bbb8bd166","status":200,"method":"GET","latency":0.005075836,"ip":"172.18.0.5","handler":"mirror"} | ||
```yaml | ||
spegel: | ||
visualize: | ||
enabled: true | ||
``` | ||
While the Spegel instance on the other end will log. | ||
After all Spegel instances have restarted you can port forward to one of the Spegel pods. | ||
```shell | ||
kubectl -n spegel port-forward ${POD_NAME} 9090 | ||
``` | ||
{"level":"info","ts":1692304805.9035861,"caller":"[email protected]/logger.go:53","msg":"","path":"/v2/library/nginx/blobs/sha256:1cb127bd932119089b5ffb612ffa84537ddd1318e6784f2fce80916bbb8bd166","status":200,"method":"GET","latency":0.003644997,"ip":"172.18.0.5","handler":"blob"} | ||
``` | ||
|
||
Open the UI at `http://localhost:9090/visualize` in a browser. If all is configured propery you should be presented with and interface showing registry requests. | ||
|
||
## Will image pulls break or be delayed if a spegel instance fails or is removed? | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
package visualize | ||
|
||
import ( | ||
"net/http" | ||
"net/netip" | ||
"sync" | ||
"time" | ||
) | ||
|
||
type GraphData struct { | ||
Nodes []Node `json:"nodes"` | ||
Links []Link `json:"links"` | ||
} | ||
|
||
type Node struct { | ||
ID string `json:"id"` | ||
} | ||
|
||
type Link struct { | ||
ID string `json:"id"` | ||
Source string `json:"source"` | ||
Target string `json:"target"` | ||
Status int `json:"status"` | ||
} | ||
|
||
type EventStore interface { | ||
RecordNoMirrors(id string) | ||
RecordRequest(id string, peer netip.Addr, method string, status int, mirror bool) | ||
FilterByDirection(rootIsSource bool) EventStore | ||
Graph() GraphData | ||
LastModified() time.Time | ||
} | ||
|
||
type edge struct { | ||
node string | ||
id string | ||
status int | ||
rootIsSource bool | ||
} | ||
|
||
var _ EventStore = &MemoryStore{} | ||
|
||
type MemoryStore struct { | ||
lastModified time.Time | ||
edgeIndex map[string]int | ||
edges []edge | ||
mx sync.RWMutex | ||
} | ||
|
||
func NewMemoryStore() *MemoryStore { | ||
return &MemoryStore{ | ||
edges: []edge{}, | ||
edgeIndex: map[string]int{}, | ||
} | ||
} | ||
|
||
func (m *MemoryStore) set(e edge) { | ||
m.mx.Lock() | ||
defer m.mx.Unlock() | ||
|
||
m.lastModified = time.Now() | ||
if idx, ok := m.edgeIndex[e.id]; ok { | ||
m.edges[idx] = e | ||
return | ||
} | ||
m.edges = append(m.edges, e) | ||
m.edgeIndex[e.id] = len(m.edges) - 1 | ||
} | ||
|
||
func (m *MemoryStore) RecordNoMirrors(id string) { | ||
e := edge{ | ||
node: "Not Found", | ||
id: id, | ||
rootIsSource: true, | ||
} | ||
m.set(e) | ||
} | ||
|
||
func (m *MemoryStore) RecordRequest(id string, peer netip.Addr, method string, status int, mirror bool) { | ||
if method != http.MethodGet { | ||
return | ||
} | ||
e := edge{ | ||
node: peer.String(), | ||
id: id, | ||
status: status, | ||
rootIsSource: mirror, | ||
} | ||
m.set(e) | ||
} | ||
|
||
func (m *MemoryStore) FilterByDirection(rootIsSource bool) EventStore { //nolint: ireturn // Have to return interface to implement interface. | ||
m.mx.RLock() | ||
defer m.mx.RUnlock() | ||
|
||
f := NewMemoryStore() | ||
f.lastModified = m.lastModified | ||
for _, edge := range m.edges { | ||
if edge.rootIsSource != rootIsSource { | ||
continue | ||
} | ||
f.edges = append(f.edges, edge) | ||
f.edgeIndex[edge.id] = len(f.edges) - 1 | ||
} | ||
return f | ||
} | ||
|
||
func (m *MemoryStore) Graph() GraphData { | ||
m.mx.RLock() | ||
defer m.mx.RUnlock() | ||
|
||
gd := GraphData{ | ||
Nodes: []Node{ | ||
{ | ||
ID: "self", | ||
}, | ||
}, | ||
Links: []Link{}, | ||
} | ||
nodeIndex := map[string]interface{}{} | ||
for _, edge := range m.edges { | ||
src := gd.Nodes[0].ID | ||
dest := edge.node | ||
if !edge.rootIsSource { | ||
src = edge.node | ||
dest = gd.Nodes[0].ID | ||
} | ||
link := Link{ | ||
ID: edge.id, | ||
Source: src, | ||
Target: dest, | ||
Status: edge.status, | ||
} | ||
gd.Links = append(gd.Links, link) | ||
|
||
if _, ok := nodeIndex[edge.node]; ok { | ||
continue | ||
} | ||
gd.Nodes = append(gd.Nodes, Node{ID: edge.node}) | ||
nodeIndex[edge.node] = nil | ||
} | ||
return gd | ||
} | ||
|
||
func (m *MemoryStore) LastModified() time.Time { | ||
m.mx.RLock() | ||
defer m.mx.RUnlock() | ||
|
||
return m.lastModified | ||
} |
Oops, something went wrong.