Skip to content

Commit

Permalink
feat(web): add DEFAULT_CONTAINER_LOG_TAIL to .env (#915)
Browse files Browse the repository at this point in the history
  • Loading branch information
Levente Orban authored Feb 22, 2024
1 parent c1c9726 commit c0d5326
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 16 deletions.
1 change: 1 addition & 0 deletions web/crux-ui/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"copy": "Copy",
"copied": "Copied.",
"delete": "Delete",
"log": "Log",

"home": "Home",
"settings": "Settings",
Expand Down
11 changes: 7 additions & 4 deletions web/crux/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
NODE_ENV=development

## Development configurations
# # Development configurations

# Kratos public API
KRATOS_URL=http://localhost:8000/kratos
Expand All @@ -10,7 +10,7 @@ KRATOS_ADMIN_URL=http://localhost:4434
DATABASE_URL="postgresql://username:password@localhost:5432/crux?schema=public"
CRUX_UI_URL=http://localhost:8000

## Port settings
# # Port settings

# Agent gRPC API port
GRPC_AGENT_PORT=5000
Expand Down Expand Up @@ -45,19 +45,22 @@ ENCRYPTION_SECRET_KEY=
# Example: error contains fatal
LOG_LEVEL=debug

## Email service config
# # Email service config
# SMTP URL for the mailslurper
SMTP_URI=smtps://test:test@localhost:1025/?skip_ssl_verify=true&legacy_ssl=true
# E-mail address for dyrector.io invitation links, password resets and others
FROM_EMAIL=from@example.com
# E-mail sender name for dyrector.io invitation links, password resets and others
FROM_NAME=dyrector.io

## Google ReCAPTCHA config
# Google ReCAPTCHA config
DISABLE_RECAPTCHA=true
# Required only when ReCAPTCHA is enabled
RECAPTCHA_SECRET_KEY=<recaptcha_secret_key>

# Determines the quantity of lines being returned by a Docker container, while streaming its logs
DEFAULT_CONTAINER_LOG_TAIL=100

# For overriding the node DNS result order
# regardless of the NODE_ENV value
# It may be necessary for running the e2e tests,
Expand Down
5 changes: 5 additions & 0 deletions web/crux/src/app/node/node.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ConfigService } from '@nestjs/config'
import { Test, TestingModule } from '@nestjs/testing'
import { of } from 'rxjs'
import DomainNotificationService from 'src/services/domain.notification.service'
Expand Down Expand Up @@ -43,6 +44,10 @@ describe('NodeService', () => {
provide: PrismaService,
useValue: jest.mocked(PrismaService),
},
{
provide: ConfigService,
useValue: jest.mocked(ConfigService),
},
NodeService,
],
}).compile()
Expand Down
7 changes: 6 additions & 1 deletion web/crux/src/app/node/node.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Injectable, Logger } from '@nestjs/common'
import { ConfigService } from '@nestjs/config'
import { Identity } from '@ory/kratos-client'
import { Prisma } from '@prisma/client'
import {
Expand Down Expand Up @@ -57,6 +58,7 @@ export default class NodeService {
private readonly agentService: AgentService,
private readonly mapper: NodeMapper,
private readonly notificationService: DomainNotificationService,
private readonly configService: ConfigService,
) {}

async checkNodeIsInTheTeam(teamSlug: string, nodeId: string, identity: Identity): Promise<boolean> {
Expand Down Expand Up @@ -247,7 +249,10 @@ export default class NodeService {

const agent = this.agentService.getByIdOrThrow(nodeId)

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

return stream.watch()
}
Expand Down
2 changes: 2 additions & 0 deletions web/crux/src/config/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const configSchema = yup.object({

QA_OPT_OUT: yup.bool().default(false).required(),
QA_GROUP_NAME: yup.string().optional(),

DEFAULT_CONTAINER_LOG_TAIL: yup.number().optional(),
})

class InvalidEnvironmentError extends Error {
Expand Down
7 changes: 4 additions & 3 deletions web/crux/src/domain/agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
DeploymentStatusMessage,
Empty,
} from 'src/grpc/protobuf/proto/common'
import { DEFAULT_CONTAINER_LOG_TAIL, GET_CONTAINER_SECRETS_TIMEOUT_MILLIS } from 'src/shared/const'
import { GET_CONTAINER_SECRETS_TIMEOUT_MILLIS } from 'src/shared/const'
import GrpcNodeConnection from 'src/shared/grpc-node-connection'
import { Agent, AgentConnectionMessage } from './agent'
import { generateAgentToken } from './agent-token'
Expand Down Expand Up @@ -341,7 +341,8 @@ describe('agent', () => {
name: 'name',
}

const logStream = agent.upsertContainerLogStream(container)
const tail = 1000
const logStream = agent.upsertContainerLogStream(container, tail)

const logEvent = firstValueFrom(logStream.watch().pipe(skip(1)))

Expand All @@ -353,7 +354,7 @@ describe('agent', () => {
name: 'name',
},
streaming: true,
tail: DEFAULT_CONTAINER_LOG_TAIL,
tail,
},
})

Expand Down
7 changes: 3 additions & 4 deletions web/crux/src/domain/agent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger } from '@nestjs/common'
import { DeploymentStatusEnum } from '@prisma/client'
import { catchError, finalize, Observable, of, Subject, Subscription, throwError, timeout, TimeoutError } from 'rxjs'
import { Observable, Subject, Subscription, TimeoutError, catchError, finalize, of, throwError, timeout } from 'rxjs'
import { NodeConnectionStatus } from 'src/app/node/node.dto'
import {
CruxConflictException,
Expand All @@ -19,7 +19,6 @@ import {
} from 'src/grpc/protobuf/proto/common'
import {
CONTAINER_DELETE_TIMEOUT_MILLIS,
DEFAULT_CONTAINER_LOG_TAIL,
GET_CONTAINER_INSPECTION_TIMEOUT_MILLIS,
GET_CONTAINER_SECRETS_TIMEOUT_MILLIS,
} from 'src/shared/const'
Expand Down Expand Up @@ -165,13 +164,13 @@ export class Agent {
return watcher
}

upsertContainerLogStream(container: ContainerIdentifier): ContainerLogStream {
upsertContainerLogStream(container: ContainerIdentifier, tail: number): ContainerLogStream {
this.throwIfCommandsAreDisabled()

const key = Agent.containerPrefixNameOf(container)
let stream = this.logStreams.get(key)
if (!stream) {
stream = new ContainerLogStream(container, DEFAULT_CONTAINER_LOG_TAIL)
stream = new ContainerLogStream(container, tail)
this.logStreams.set(key, stream)
stream.start(this.commandChannel)
}
Expand Down
4 changes: 2 additions & 2 deletions web/crux/src/domain/container-log-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export default class ContainerLogStream {
private completer: ContainerLogStreamCompleter = null

constructor(
private container: ContainerIdentifier,
private tail: number,
private readonly container: ContainerIdentifier,
private readonly tail: number,
) {}

start(commandChannel: Subject<AgentCommand>) {
Expand Down
2 changes: 0 additions & 2 deletions web/crux/src/shared/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ 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 DEFAULT_CONTAINER_LOG_TAIL = 40

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

0 comments on commit c0d5326

Please sign in to comment.