Skip to content

Commit 5c90f66

Browse files
committed
adds inspect extraInfo to ig-desktop
Signed-off-by: KapilSareen <kapilsareen584@gmail.com>
1 parent d770c87 commit 5c90f66

File tree

10 files changed

+966
-17
lines changed

10 files changed

+966
-17
lines changed

frontend/package-lock.json

Lines changed: 838 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"@tailwindcss/vite": "^4.1.7",
4343
"d3": "^7.9.0",
4444
"js-yaml": "^4.1.0",
45-
"marked": "^15.0.12",
45+
"marked": "^15.0.11",
46+
"mermaid": "^11.6.0",
4647
"monaco-editor": "^0.52.2"
4748
}
4849
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<script>
2+
import Monaco from '../monaco.svelte';
3+
import { getContext } from 'svelte';
4+
import { page } from '$app/state';
5+
import { environments } from '$lib/shared/environments.svelte.js';
6+
import mermaid from 'mermaid';
7+
8+
let { data, gadgetInfo } = $props();
9+
const api = getContext('api');
10+
11+
let env = $derived(environments[page.params.env]);
12+
13+
let graphs = $state({});
14+
let info = $state({});
15+
16+
$effect(() => {
17+
if (!env.id || !gadgetInfo?.imageName) {
18+
return;
19+
}
20+
21+
mermaid.initialize({ startOnLoad: true, theme: 'dark' });
22+
23+
api
24+
.request({ cmd: 'getGadgetInfo', data: { url: gadgetInfo.imageName, environmentID: env.id } })
25+
.then((res) => {
26+
let extraInfo = res.extraInfo.data;
27+
if (!extraInfo) {
28+
return;
29+
}
30+
for (const key in extraInfo) {
31+
if (extraInfo[key].contentType == 'text/mermaid') {
32+
let graph = atob(extraInfo[key].content);
33+
let id = `mermaid-${Math.random().toString(2).substring(2, 15)}`;
34+
mermaid
35+
.render(id, graph)
36+
.then(({ svg }) => {
37+
console.log(svg);
38+
graphs[key] = svg;
39+
})
40+
.catch((err) => {
41+
console.error(`Error rendering mermaid graph for key ${key}:`, err);
42+
graphs[key] = `<div>Error rendering graph: ${err.message}</div>`;
43+
});
44+
}
45+
46+
if (
47+
extraInfo[key].contentType == 'text/plain' ||
48+
extraInfo[key].contentType == 'application/json'
49+
) {
50+
try {
51+
info[key] = atob(extraInfo[key].content);
52+
} catch (e) {
53+
console.error(`Error decoding content for key ${key}:`, e);
54+
info[key] = 'Error decoding content.';
55+
}
56+
}
57+
}
58+
})
59+
.catch((err) => {
60+
console.error('Error fetching gadget info:', err);
61+
});
62+
});
63+
</script>
64+
65+
<div class="flex flex-1 flex-col space-y-4 overflow-scroll">
66+
<!-- Mermaid graphs -->
67+
{#if graphs && Object.keys(graphs).length > 0}
68+
{#each Object.entries(graphs) as [key, svg]}
69+
<div class="mb-4">
70+
<h3 class="text-md mb-2 font-semibold">{key}</h3>
71+
<button
72+
class="text-sm text-blue-500 hover:underline"
73+
onclick={() => {
74+
const pre = document.getElementById(`extra-info-${key}`);
75+
if (pre) {
76+
pre.classList.toggle('hidden');
77+
}
78+
}}>Toggle Content</button
79+
>
80+
<div id={`extra-info-${key}`} class="hidden overflow-x-auto rounded border p-2">
81+
{@html svg}
82+
</div>
83+
</div>
84+
{/each}
85+
{/if}
86+
87+
<!-- JSON extra info -->
88+
{#if info && Object.keys(info).length > 0}
89+
{#each Object.entries(info) as [key, content]}
90+
<div class="mb-4">
91+
<h3 class="text-md mb-2 font-semibold">{key}</h3>
92+
<button
93+
class="cursor-pointer text-sm text-blue-500"
94+
onclick={() => {
95+
const pre = document.getElementById(`extra-info-${key}`);
96+
if (pre) {
97+
pre.classList.toggle('hidden');
98+
}
99+
}}>Toggle Content</button
100+
>
101+
</div>
102+
<div id={`extra-info-${key}`} class="hidden">{content}</div>
103+
{/each}
104+
{/if}
105+
</div>

frontend/src/lib/components/gadget-settings.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import Metadata from './gadget-attribs/metadata.svelte';
1313
import GadgetInfo from './gadget-attribs/gadgetinfo.svelte';
1414
import Inspect from './gadget-attribs/inspect.svelte';
15+
import ExtraInfo from './gadget-attribs/extrainfo.svelte';
1516
1617
let {
1718
gadgetInfo, onclose = () => {
@@ -24,7 +25,7 @@
2425
{ class: Metadata, name: 'Metadata', icon: Book },
2526
{ class: GadgetInfo, name: 'Gadget Information', icon: Bug },
2627
{ class: Inspect, name: 'Inspect', icon: Layers },
27-
// { class: Inspect, name: 'Inspect', icon: Adjustments }
28+
{ class: ExtraInfo, name: 'Extra Info', icon: Adjustments }
2829
];
2930
3031
let tabIndex = $state(0); // gadget.attribsPage;

frontend/wailsjs/go/main/App.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@ export function GetEnvironments():Promise<Array<main.Environment>>;
1111

1212
export function GetRuntime(arg1:string):Promise<grpcruntime.Runtime>;
1313

14-
export function Greet(arg1:string):Promise<string>;
15-
1614
export function Run():Promise<void>;

frontend/wailsjs/go/main/App.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ export function GetRuntime(arg1) {
1818
return window['go']['main']['App']['GetRuntime'](arg1);
1919
}
2020

21-
export function Greet(arg1) {
22-
return window['go']['main']['App']['Greet'](arg1);
23-
}
24-
2521
export function Run() {
2622
return window['go']['main']['App']['Run']();
2723
}

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

pkg/grpc-runtime/oci.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ func (r *Runtime) GetGadgetInfo(gadgetCtx runtime.GadgetContext, runtimeParams *
4444
client := api.NewGadgetManagerClient(conn)
4545

4646
in := &api.GetGadgetInfoRequest{
47-
ParamValues: paramValues,
48-
ImageName: gadgetCtx.ImageName(),
49-
Version: api.VersionGadgetInfo,
47+
ParamValues: paramValues,
48+
ImageName: gadgetCtx.ImageName(),
49+
Version: api.VersionGadgetInfo,
50+
RequestExtraInfo: gadgetCtx.ExtraInfo(),
5051
}
5152

5253
// specify that ImageName will contain a gadget instance ID
@@ -58,13 +59,18 @@ func (r *Runtime) GetGadgetInfo(gadgetCtx runtime.GadgetContext, runtimeParams *
5859
if err != nil {
5960
return nil, fmt.Errorf("getting gadget info: %w", err)
6061
}
62+
extraInfo := &api.ExtraInfo{}
6163

62-
err = gadgetCtx.LoadGadgetInfo(out.GadgetInfo, paramValues, false, nil)
64+
if gadgetCtx.ExtraInfo() {
65+
extraInfo = out.GadgetInfo.ExtraInfo
66+
}
67+
68+
err = gadgetCtx.LoadGadgetInfo(out.GadgetInfo, paramValues, false, extraInfo)
6369
if err != nil {
6470
return nil, fmt.Errorf("initializing local operators: %w", err)
6571
}
6672

67-
return gadgetCtx.SerializeGadgetInfo(false)
73+
return gadgetCtx.SerializeGadgetInfo(gadgetCtx.ExtraInfo())
6874
}
6975

7076
func (r *Runtime) RunGadget(gadgetCtx runtime.GadgetContext, runtimeParams *params.Params, paramValues api.ParamValues) error {

web.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ func (w *App) Run() error {
564564
gadgetCtx := gadgetcontext.New(
565565
ctx,
566566
gadgetInfoRequest.URL,
567+
gadgetcontext.IncludeExtraInfo(true),
567568
)
568569

569570
// use default params; TODO!

0 commit comments

Comments
 (0)