Skip to content

Commit

Permalink
Merge branch 'develop' into fix/list-anchors
Browse files Browse the repository at this point in the history
  • Loading branch information
m8vago committed Mar 12, 2024
2 parents 7dc3bec + 52d6472 commit 22f163b
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 11 deletions.
27 changes: 26 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
# CHANGELOG


<a name="0.11.3"></a>
## [0.11.3](https://github.com/dyrector-io/dyrectorio/compare/ls...0.11.3) (2024-03-11)

### Feat

* container log api ([#931](https://github.com/dyrector-io/dyrectorio/issues/931))

### Fix

* container log new line ([#932](https://github.com/dyrector-io/dyrectorio/issues/932))
* add ENCRYPTION_SECRET_KEY to compose files ([#927](https://github.com/dyrector-io/dyrectorio/issues/927))


<a name="ls"></a>
## [ls](https://github.com/dyrector-io/dyrectorio/compare/0.11.2...ls) (2024-02-26)

### Doc

* **(crux):** add extra info encrpytion gey generation ([#926](https://github.com/dyrector-io/dyrectorio/issues/926))

### Feat

* **(web):** update kratos to 1.1.0 ([#925](https://github.com/dyrector-io/dyrectorio/issues/925))


<a name="0.11.2"></a>
## [0.11.2](https://github.com/dyrector-io/dyrectorio/compare/0.11.1...0.11.2) (2024-02-22)
## [0.11.2](https://github.com/dyrector-io/dyrectorio/compare/0.11.1...0.11.2) (2024-02-23)

### Feat

Expand Down
6 changes: 6 additions & 0 deletions golang/internal/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,12 @@ func streamContainerLog(reader ContainerLogReader,
if event.Error != nil {
if event.Error == io.EOF && !streaming {
log.Trace().Str("prefix", prefix).Str("name", name).Msg("Container log finished non streaming (EOF)")

err := client.CloseSend()
if err != nil {
log.Error().Err(err).Stack().Str("prefix", prefix).Str("name", name).Msg("Failed to close client")
}

break
}

Expand Down
2 changes: 1 addition & 1 deletion golang/internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

var (
// Version represents the version of the application
Version = "0.11.2"
Version = "0.11.3"
// CommitHash is the hash of the commit used for the build
CommitHash = "n/a"
// BuildTimestamp represents the timestamp when the build was created
Expand Down
4 changes: 2 additions & 2 deletions web/crux-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/crux-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crux-ui",
"version": "0.11.2",
"version": "0.11.3",
"description": "Open-source delivery platform that helps developers to deliver applications efficiently by simplifying software releases and operations in any environment.",
"author": "dyrector.io",
"private": true,
Expand Down
4 changes: 2 additions & 2 deletions web/crux/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/crux/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crux",
"version": "0.11.2",
"version": "0.11.3",
"description": "Open-source delivery platform that helps developers to deliver applications efficiently by simplifying software releases and operations in any environment.",
"author": "dyrector.io",
"private": true,
Expand Down
14 changes: 14 additions & 0 deletions web/crux/src/app/node/node.global-container.http.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,18 @@ export default class NodeGlobalContainerHttpController {
async inspectContainer(@NodeId() nodeId: string, @Name() name: string): Promise<ContainerInspectionDto> {
return await this.service.inspectContainer(nodeId, GLOBAL_PREFIX, name)
}

@Get(`${ROUTE_NAME}/log`)
@HttpCode(HttpStatus.OK)
@ApiOperation({
description: 'Request must include `nodeId`, and the `name` of the container.',
summary: 'Get the logs of a container.',
})
@ApiOkResponse({ description: 'Container log.', type: String })
@ApiBadRequestResponse({ description: 'Bad request for container log.' })
@ApiForbiddenResponse({ description: 'Unauthorized request for container log.' })
@UuidParams(PARAM_NODE_ID)
async getContainerLog(@TeamSlug() _: string, @NodeId() nodeId: string, @Name() name: string): Promise<string> {
return this.service.getContainerLog(nodeId, GLOBAL_PREFIX, name)
}
}
19 changes: 19 additions & 0 deletions web/crux/src/app/node/node.prefix-container.http.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,23 @@ export default class NodePrefixContainerHttpController {
): Promise<ContainerInspectionDto> {
return await this.service.inspectContainer(nodeId, prefix, name)
}

@Get(`${ROUTE_NAME}/log`)
@HttpCode(HttpStatus.OK)
@ApiOperation({
description: 'Request must include `nodeId`, `prefix`, and the `name` of the container.',
summary: 'Get the logs of a container.',
})
@ApiOkResponse({ description: 'Container log.', type: String })
@ApiBadRequestResponse({ description: 'Bad request for container log.' })
@ApiForbiddenResponse({ description: 'Unauthorized request for container log.' })
@UuidParams(PARAM_NODE_ID)
async getContainerLog(
@TeamSlug() _: string,
@NodeId() nodeId: string,
@Prefix() prefix: string,
@Name() name: string,
): Promise<string> {
return this.service.getContainerLog(nodeId, prefix, name)
}
}
36 changes: 36 additions & 0 deletions web/crux/src/app/node/node.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import {
mergeAll,
mergeWith,
of,
reduce,
throwError,
timeout,
} from 'rxjs'
import { Agent, AgentConnectionMessage } from 'src/domain/agent'
import { BaseMessage } from 'src/domain/notification-templates'
import { CruxInternalServerErrorException } from 'src/exception/crux-exception'
import {
ContainerCommandRequest,
ContainerIdentifier,
Expand All @@ -26,6 +29,7 @@ import {
} from 'src/grpc/protobuf/proto/common'
import DomainNotificationService from 'src/services/domain.notification.service'
import PrismaService from 'src/services/prisma.service'
import { GET_CONTAINER_LOG_TIMEOUT_MILLIS } from 'src/shared/const'
import AgentService from '../agent/agent.service'
import TeamRepository from '../team/team.repository'
import {
Expand Down Expand Up @@ -433,6 +437,38 @@ export default class NodeService {
return this.mapper.containerInspectionMessageToDto(inspectionMessage)
}

async getContainerLog(nodeId: string, prefix: string, name: string): Promise<string> {
const agent = this.agentService.getByIdOrThrow(nodeId)

const container = {
prefix,
name,
}

const stream = agent.upsertContainerLogStream(
container,
this.configService.get<number>('DEFAULT_CONTAINER_LOG_TAIL', 1000),
false,
)

const watcher = stream.watch().pipe(
map(it => it.log),
reduce((acc, it) => `${acc.trimEnd()}\n${it}`, ''),
timeout({
each: GET_CONTAINER_LOG_TIMEOUT_MILLIS,
with: () =>
throwError(
() =>
new CruxInternalServerErrorException({
message: 'Agent container log timed out.',
}),
),
}),
)

return lastValueFrom(watcher)
}

async kickNode(id: string, identity: Identity): Promise<void> {
await this.agentService.kick(id, 'user-kick', identity.id)
}
Expand Down
8 changes: 6 additions & 2 deletions web/crux/src/domain/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,17 @@ export class Agent {
return watcher
}

upsertContainerLogStream(container: ContainerIdentifier, tail: number): ContainerLogStream {
upsertContainerLogStream(
container: ContainerIdentifier,
tail: number,
streaming: boolean = true,
): ContainerLogStream {
this.throwIfCommandsAreDisabled()

const key = Agent.containerPrefixNameOf(container)
let stream = this.logStreams.get(key)
if (!stream) {
stream = new ContainerLogStream(container, tail)
stream = new ContainerLogStream(container, tail, streaming)
this.logStreams.set(key, stream)
stream.start(this.commandChannel)
}
Expand Down
3 changes: 2 additions & 1 deletion web/crux/src/domain/container-log-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default class ContainerLogStream {
constructor(
private readonly container: ContainerIdentifier,
private readonly tail: number,
private readonly streaming: boolean = true,
) {}

start(commandChannel: Subject<AgentCommand>) {
Expand All @@ -26,7 +27,7 @@ export default class ContainerLogStream {
commandChannel.next({
containerLog: {
container: this.container,
streaming: true,
streaming: this.streaming,
tail: this.tail,
},
} as AgentCommand)
Expand Down
1 change: 1 addition & 0 deletions web/crux/src/shared/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const JWT_EXPIRATION_MILLIS = 10 * 60 * 1000 // 10 minutes
export const CONTAINER_DELETE_TIMEOUT_MILLIS = 1000
export const GET_CONTAINER_SECRETS_TIMEOUT_MILLIS = 5000
export const GET_CONTAINER_INSPECTION_TIMEOUT_MILLIS = 5000
export const GET_CONTAINER_LOG_TIMEOUT_MILLIS = 15000

// NOTE(@m8vago): This should be incremented, when a new release includes a proto file change
const AGENT_PROTO_COMPATIBILITY_MINIMUM_VERSION = '0.11.0'
Expand Down

0 comments on commit 22f163b

Please sign in to comment.