Skip to content

Commit

Permalink
[ContainerLog]: add show_events (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
duc-cnzj committed Aug 15, 2023
1 parent 2f9d667 commit 58b3e3b
Show file tree
Hide file tree
Showing 29 changed files with 1,028 additions and 412 deletions.
12 changes: 12 additions & 0 deletions doc/container/container.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
"in": "path",
"required": true,
"type": "string"
},
{
"name": "show_events",
"in": "query",
"required": false,
"type": "boolean"
}
],
"tags": [
Expand Down Expand Up @@ -137,6 +143,12 @@
"in": "path",
"required": true,
"type": "string"
},
{
"name": "show_events",
"in": "query",
"required": false,
"type": "boolean"
}
],
"tags": [
Expand Down
3 changes: 3 additions & 0 deletions doc/project/project.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@
},
"pending": {
"type": "boolean"
},
"ready": {
"type": "boolean"
}
}
},
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/api/compiled.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,9 @@ export namespace container {

/** LogRequest container */
container?: (string|null);

/** LogRequest show_events */
show_events?: (boolean|null);
}

/** Represents a LogRequest. */
Expand All @@ -1566,6 +1569,9 @@ export namespace container {
/** LogRequest container. */
public container: string;

/** LogRequest show_events. */
public show_events: boolean;

/**
* Encodes the specified LogRequest message. Does not implicitly {@link container.LogRequest.verify|verify} messages.
* @param message LogRequest message or plain object to encode
Expand Down Expand Up @@ -7907,6 +7913,9 @@ export namespace types {

/** StateContainer pending */
pending?: (boolean|null);

/** StateContainer ready */
ready?: (boolean|null);
}

/** Represents a StateContainer. */
Expand Down Expand Up @@ -7936,6 +7945,9 @@ export namespace types {
/** StateContainer pending. */
public pending: boolean;

/** StateContainer ready. */
public ready: boolean;

/**
* Encodes the specified StateContainer message. Does not implicitly {@link types.StateContainer.verify|verify} messages.
* @param message StateContainer message or plain object to encode
Expand Down
30 changes: 30 additions & 0 deletions frontend/src/api/compiled.js
Original file line number Diff line number Diff line change
Expand Up @@ -3329,6 +3329,7 @@ export const container = $root.container = (() => {
* @property {string|null} [namespace] LogRequest namespace
* @property {string|null} [pod] LogRequest pod
* @property {string|null} [container] LogRequest container
* @property {boolean|null} [show_events] LogRequest show_events
*/

/**
Expand Down Expand Up @@ -3370,6 +3371,14 @@ export const container = $root.container = (() => {
*/
LogRequest.prototype.container = "";

/**
* LogRequest show_events.
* @member {boolean} show_events
* @memberof container.LogRequest
* @instance
*/
LogRequest.prototype.show_events = false;

/**
* Encodes the specified LogRequest message. Does not implicitly {@link container.LogRequest.verify|verify} messages.
* @function encode
Expand All @@ -3388,6 +3397,8 @@ export const container = $root.container = (() => {
writer.uint32(/* id 2, wireType 2 =*/18).string(message.pod);
if (message.container != null && Object.hasOwnProperty.call(message, "container"))
writer.uint32(/* id 3, wireType 2 =*/26).string(message.container);
if (message.show_events != null && Object.hasOwnProperty.call(message, "show_events"))
writer.uint32(/* id 4, wireType 0 =*/32).bool(message.show_events);
return writer;
};

Expand Down Expand Up @@ -3421,6 +3432,10 @@ export const container = $root.container = (() => {
message.container = reader.string();
break;
}
case 4: {
message.show_events = reader.bool();
break;
}
default:
reader.skipType(tag & 7);
break;
Expand Down Expand Up @@ -16636,6 +16651,7 @@ export const types = $root.types = (() => {
* @property {boolean|null} [is_old] StateContainer is_old
* @property {boolean|null} [terminating] StateContainer terminating
* @property {boolean|null} [pending] StateContainer pending
* @property {boolean|null} [ready] StateContainer ready
*/

/**
Expand Down Expand Up @@ -16701,6 +16717,14 @@ export const types = $root.types = (() => {
*/
StateContainer.prototype.pending = false;

/**
* StateContainer ready.
* @member {boolean} ready
* @memberof types.StateContainer
* @instance
*/
StateContainer.prototype.ready = false;

/**
* Encodes the specified StateContainer message. Does not implicitly {@link types.StateContainer.verify|verify} messages.
* @function encode
Expand All @@ -16725,6 +16749,8 @@ export const types = $root.types = (() => {
writer.uint32(/* id 5, wireType 0 =*/40).bool(message.terminating);
if (message.pending != null && Object.hasOwnProperty.call(message, "pending"))
writer.uint32(/* id 6, wireType 0 =*/48).bool(message.pending);
if (message.ready != null && Object.hasOwnProperty.call(message, "ready"))
writer.uint32(/* id 7, wireType 0 =*/56).bool(message.ready);
return writer;
};

Expand Down Expand Up @@ -16770,6 +16796,10 @@ export const types = $root.types = (() => {
message.pending = reader.bool();
break;
}
case 7: {
message.ready = reader.bool();
break;
}
default:
reader.skipType(tag & 7);
break;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export function containerLog({
container,
}: pb.container.LogRequest) {
return ajax.get<pb.container.LogResponse>(
`/api/containers/namespaces/${namespace}/pods/${pod}/containers/${container}/logs`
`/api/containers/namespaces/${namespace}/pods/${pod}/containers/${container}/logs?show_events=1`
);
}
22 changes: 17 additions & 5 deletions frontend/src/components/PodStateTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ import { SyncOutlined, LoadingOutlined } from "@ant-design/icons";
import { css } from "@emotion/css";
import theme from "../styles/theme";
const PodStateTag: React.FC<{ pod: pb.types.StateContainer }> = ({ pod }) => {
if (pod.is_old) {
return (
<Tag
icon={<SyncOutlined spin />}
color="#fde047"
style={{ marginLeft: 5 }}
>
{pod.pod} 即将停止
</Tag>
);
}

if (pod.terminating) {
return (
<Tag
Expand All @@ -21,22 +33,22 @@ const PodStateTag: React.FC<{ pod: pb.types.StateContainer }> = ({ pod }) => {
return (
<Tag
icon={<LoadingOutlined spin />}
color="#93c5fd"
color="#67e8f9"
style={{ marginLeft: 5 }}
>
{pod.pod} 未就绪
{pod.pod} 启动中
</Tag>
);
}

if (pod.is_old) {
if (!pod.is_old && !pod.ready) {
return (
<Tag
icon={<SyncOutlined spin />}
color="#fde047"
color="#93c5fd"
style={{ marginLeft: 5 }}
>
{pod.pod} 即将停止
{pod.pod} 未就绪
</Tag>
);
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/TabLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const MyLogUtil: React.FC<{
};
}> = ({ namespace, pod, container, onError, freshTime }) => {
const getUrl = useCallback(() => {
return `${process.env.REACT_APP_BASE_URL}/api/containers/namespaces/${namespace}/pods/${pod}/containers/${container}/stream_logs?timestamp=${freshTime}`;
return `${process.env.REACT_APP_BASE_URL}/api/containers/namespaces/${namespace}/pods/${pod}/containers/${container}/stream_logs?timestamp=${freshTime}&show_events=1`;
}, [namespace, pod, container, freshTime]);

return (
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/TabShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ const TabShell: React.FC<{
) {
groups.push(
<Allotment
key={groups.length + 1}
vertical={lastType === "vertical"}
onDragEnd={resizeShellWindow}
>
Expand All @@ -339,6 +340,7 @@ const TabShell: React.FC<{
} else {
groups.push(
<Allotment
key={groups.length + 1}
vertical={lastType === "vertical"}
onDragEnd={resizeShellWindow}
>
Expand Down
36 changes: 19 additions & 17 deletions frontend/src/pkg/lazylog/components/LazyLog/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -376,30 +376,32 @@ export default class LazyLog extends Component {
handleUpdate = ({ lines: moreLines, encodedLog }) => {
this.encodedLog = encodedLog;
const { scrollToLine, follow, stream, websocket } = this.props;
const { lineLimit, count: previousCount, isBottom } = this.state;
let offset = 0;
let lines = (this.state.lines || List()).concat(moreLines);
let count = lines.count();

if (count > lineLimit) {
offset = count - lineLimit;
lines = lines.slice(-lineLimit);
count = lines.count();
}

this.setState((prevState) => {
const { lineLimit, count: previousCount, isBottom } = prevState;
let offset = 0;
let lines = (prevState.lines || List()).concat(moreLines);
let count = lines.count();

if (count > lineLimit) {
offset = count - lineLimit;
lines = lines.slice(-lineLimit);
count = lines.count();
}

let scrollToIndex = getScrollIndex({
follow: follow && isBottom,
follow: follow && isBottom,
scrollToLine,
previousCount,
count,
offset,
});

this.setState({
lines,
offset,
count,
scrollToIndex: scrollToIndex,
return {
lines,
offset,
count,
scrollToIndex: scrollToIndex,
};
});

if (stream || websocket) {
Expand Down
6 changes: 5 additions & 1 deletion internal/app/bootstrappers/apigateway_bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,11 @@ func exportMarsConfig(w http.ResponseWriter, r *http.Request, pathParams map[str
e.AuditLog(user.Name,
types.EventActionType_Download,
fmt.Sprintf("下载配置文件: %v", strings.Join(pname, ",")), nil, &e.StringYamlPrettier{Str: jsonString})
download(w, "mars-config.json", strings.NewReader(jsonString))
fileName := "mars-config.json"
if pid != "" && len(pname) == 1 {
fileName = pname[0] + ".json"
}
download(w, fileName, strings.NewReader(jsonString))
}

type gitProjectList []models.GitProject
Expand Down
2 changes: 2 additions & 0 deletions internal/app/bootstrappers/apigateway_bootstrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,14 @@ func Test_exportMarsConfig(t *testing.T) {
}
]
`), fmt.Sprintf("\n%s\n", r3.Body.String()))
assert.Equal(t, `attachment; filename="mars-config.json"`, r3.Result().Header.Get("Content-Disposition"))

r4 := httptest.NewRecorder()
auth.EXPECT().VerifyToken(gomock.Any()).Return(admin, true).Times(1)
testutil.AssertAuditLogFiredWithMsg(m, app, "下载配置文件: app")
exportMarsConfig(r4, req, map[string]string{"git_project_id": "1"})
assert.Equal(t, 200, r4.Code)
assert.Equal(t, `attachment; filename="app.json"`, r4.Result().Header.Get("Content-Disposition"))
}

func Test_exportMarsConfigWithPid(t *testing.T) {
Expand Down
Loading

0 comments on commit 58b3e3b

Please sign in to comment.