Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2608,6 +2608,7 @@ components:
instances:
- backupSize: 0
lastBackup: 6
buildVersion: buildVersion
role: role
logLevel: logLevel
userCount: 1
Expand All @@ -2619,6 +2620,7 @@ components:
coreAddress: coreAddress
- backupSize: 0
lastBackup: 6
buildVersion: buildVersion
role: role
logLevel: logLevel
userCount: 1
Expand Down Expand Up @@ -3720,6 +3722,7 @@ components:
example:
backupSize: 0
lastBackup: 6
buildVersion: buildVersion
role: role
logLevel: logLevel
userCount: 1
Expand All @@ -3733,6 +3736,11 @@ components:
backupSize:
format: int64
type: integer
buildVersion:
description: |-
BuildVersion is the build version of the running server binary, sourced
from WEBLENS_BUILD_VERSION or the embedded VCS revision.
type: string
coreAddress:
description: |-
Address of the remote server, only if the instance is a core.
Expand Down
26 changes: 26 additions & 0 deletions api/docs/TowerInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**BackupSize** | **int64** | |
**BuildVersion** | Pointer to **string** | BuildVersion is the build version of the running server binary, sourced from WEBLENS_BUILD_VERSION or the embedded VCS revision. | [optional]
**CoreAddress** | **string** | Address of the remote server, only if the instance is a core. Not set for any remotes/backups on core server, as it IS the core |
**Id** | **string** | |
**LastBackup** | **int64** | |
Expand Down Expand Up @@ -55,6 +56,31 @@ and a boolean to check if the value has been set.
SetBackupSize sets BackupSize field to given value.


### GetBuildVersion

`func (o *TowerInfo) GetBuildVersion() string`

GetBuildVersion returns the BuildVersion field if non-nil, zero value otherwise.

### GetBuildVersionOk

`func (o *TowerInfo) GetBuildVersionOk() (*string, bool)`

GetBuildVersionOk returns a tuple with the BuildVersion field if it's non-nil, zero value otherwise
and a boolean to check if the value has been set.

### SetBuildVersion

`func (o *TowerInfo) SetBuildVersion(v string)`

SetBuildVersion sets BuildVersion field to given value.

### HasBuildVersion

`func (o *TowerInfo) HasBuildVersion() bool`

HasBuildVersion returns a boolean if a field has been set.

### GetCoreAddress

`func (o *TowerInfo) GetCoreAddress() string`
Expand Down
37 changes: 37 additions & 0 deletions api/model_tower_info.go

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

4 changes: 4 additions & 0 deletions api/ts/dist/AllApi.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ declare const TowerHealthStatusEnum: {
type TowerHealthStatusEnum = typeof TowerHealthStatusEnum[keyof typeof TowerHealthStatusEnum];
interface TowerInfo {
'backupSize': number;
/**
* BuildVersion is the build version of the running server binary, sourced from WEBLENS_BUILD_VERSION or the embedded VCS revision.
*/
'buildVersion'?: string;
/**
* Address of the remote server, only if the instance is a core. Not set for any remotes/backups on core server, as it IS the core
*/
Expand Down
4 changes: 4 additions & 0 deletions api/ts/generated/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ export type TowerHealthStatusEnum = typeof TowerHealthStatusEnum[keyof typeof To

export interface TowerInfo {
'backupSize': number;
/**
* BuildVersion is the build version of the running server binary, sourced from WEBLENS_BUILD_VERSION or the embedded VCS revision.
*/
'buildVersion'?: string;
/**
* Address of the remote server, only if the instance is a core. Not set for any remotes/backups on core server, as it IS the core
*/
Expand Down
2 changes: 2 additions & 0 deletions api/ts/generated/docs/TowerInfo.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**backupSize** | **number** | | [default to undefined]
**buildVersion** | **string** | BuildVersion is the build version of the running server binary, sourced from WEBLENS_BUILD_VERSION or the embedded VCS revision. | [optional] [default to undefined]
**coreAddress** | **string** | Address of the remote server, only if the instance is a core. Not set for any remotes/backups on core server, as it IS the core | [default to undefined]
**id** | **string** | | [default to undefined]
**lastBackup** | **number** | | [default to undefined]
Expand All @@ -24,6 +25,7 @@ import { TowerInfo } from './api';

const instance: TowerInfo = {
backupSize,
buildVersion,
coreAddress,
id,
lastBackup,
Expand Down
4 changes: 4 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4387,6 +4387,10 @@ const docTemplate = `{
"type": "integer",
"format": "int64"
},
"buildVersion": {
"description": "BuildVersion is the build version of the running server binary, sourced\nfrom WEBLENS_BUILD_VERSION or the embedded VCS revision.",
"type": "string"
},
"coreAddress": {
"description": "Address of the remote server, only if the instance is a core.\nNot set for any remotes/backups on core server, as it IS the core",
"type": "string"
Expand Down
4 changes: 4 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -4385,6 +4385,10 @@
"type": "integer",
"format": "int64"
},
"buildVersion": {
"description": "BuildVersion is the build version of the running server binary, sourced\nfrom WEBLENS_BUILD_VERSION or the embedded VCS revision.",
"type": "string"
},
"coreAddress": {
"description": "Address of the remote server, only if the instance is a core.\nNot set for any remotes/backups on core server, as it IS the core",
"type": "string"
Expand Down
5 changes: 5 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,11 @@ definitions:
backupSize:
format: int64
type: integer
buildVersion:
description: |-
BuildVersion is the build version of the running server binary, sourced
from WEBLENS_BUILD_VERSION or the embedded VCS revision.
type: string
coreAddress:
description: |-
Address of the remote server, only if the instance is a core.
Expand Down
31 changes: 31 additions & 0 deletions modules/config/buildversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package config

import (
"os"
"runtime/debug"
)

const unknownBuildVersion = "unknown"

// BuildVersion returns the build version of the running binary. It checks the
// WEBLENS_BUILD_VERSION environment variable first, falling back to the
// embedded VCS revision from runtime/debug. Returns "unknown" if neither is
// available.
func BuildVersion() string {
if v := os.Getenv("WEBLENS_BUILD_VERSION"); v != "" {
return v
}

buildInfo, ok := debug.ReadBuildInfo()
if !ok {
return unknownBuildVersion
}

for _, s := range buildInfo.Settings {
if s.Key == "vcs.revision" {
return s.Value
}
}

return unknownBuildVersion
}
28 changes: 6 additions & 22 deletions modules/wlog/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"os"
"runtime"
"runtime/debug"
"strings"
"sync"

Expand Down Expand Up @@ -105,31 +104,16 @@ func NewZeroLogger(opts ...CreateOpts) *zerolog.Logger {
}
}

config := config.GetConfig()
wlVersion := config.BuildVersion()
cfg := config.GetConfig()

var logWriter io.Writer
if config.LogFormat == "dev" {
if cfg.LogFormat == "dev" {
logWriter = newDevLogger(outputLocation)
} else {
logWriter = outputLocation
}

wlVersion := os.Getenv("WEBLENS_BUILD_VERSION")
if wlVersion == "" {
wlVersion = "unknown"

buildInfo, ok := debug.ReadBuildInfo()
if ok {
for _, v := range buildInfo.Settings {
if v.Key == "vcs.revision" {
wlVersion = v.Value

break
}
}
}
}

level := zerolog.InfoLevel
if o.Level != zerolog.Disabled {
level = o.Level
Expand All @@ -140,7 +124,7 @@ func NewZeroLogger(opts ...CreateOpts) *zerolog.Logger {

// If no options are provided, set the global loggers
if o.Global {
zerolog.SetGlobalLevel(config.LogLevel)
zerolog.SetGlobalLevel(cfg.LogLevel)

loggerMu.Lock()

Expand All @@ -152,9 +136,9 @@ func NewZeroLogger(opts ...CreateOpts) *zerolog.Logger {

loggerMu.Unlock()

log.Info().CallerSkipFrame(2).Msgf("Weblens logger initialized [%s][%s]", log.GetLevel(), config.LogFormat)
log.Info().CallerSkipFrame(2).Msgf("Weblens logger initialized [%s][%s]", log.GetLevel(), cfg.LogFormat)
} else {
log.Debug().CallerSkipFrame(1).Msgf("Created new Weblens logger [%s][%s]", log.GetLevel(), config.LogFormat)
log.Debug().CallerSkipFrame(1).Msgf("Created new Weblens logger [%s][%s]", log.GetLevel(), cfg.LogFormat)
}

return &log
Expand Down
4 changes: 4 additions & 0 deletions modules/wlstructs/tower.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ type TowerInfo struct {
Started bool `json:"started" validate:"required"`

LogLevel string `json:"logLevel,omitempty"`

// BuildVersion is the build version of the running server binary, sourced
// from WEBLENS_BUILD_VERSION or the embedded VCS revision.
BuildVersion string `json:"buildVersion,omitempty"`
} // @name TowerInfo

// TowerHealth represents the health status of the server instance.
Expand Down
9 changes: 8 additions & 1 deletion services/reshape/tower.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

openapi "github.com/ethanrous/weblens/api"
tower_model "github.com/ethanrous/weblens/models/tower"
"github.com/ethanrous/weblens/modules/config"
"github.com/ethanrous/weblens/modules/wlstructs"
context_service "github.com/ethanrous/weblens/services/ctxservice"
)
Expand All @@ -31,7 +32,7 @@ func TowerToTowerInfo(ctx context.Context, tower tower_model.Instance) wlstructs
}
}

return wlstructs.TowerInfo{
info := wlstructs.TowerInfo{
ID: tower.TowerID,
Name: tower.Name,
Role: string(tower.Role),
Expand All @@ -45,6 +46,12 @@ func TowerToTowerInfo(ctx context.Context, tower tower_model.Instance) wlstructs
ReportedRole: string(tower.Role),
Online: online,
}

if tower.IsThisTower {
info.BuildVersion = config.BuildVersion()
}

return info
}

// TowerInfoToTower converts a TowerInfo from the API to a tower Instance.
Expand Down
27 changes: 27 additions & 0 deletions services/reshape/tower_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package reshape_test

import (
"testing"

tower_model "github.com/ethanrous/weblens/models/tower"
"github.com/ethanrous/weblens/services/reshape"
)

func TestTowerToTowerInfo_LocalIncludesBuildVersion(t *testing.T) {
t.Setenv("WEBLENS_BUILD_VERSION", "test-version-1.2.3")

ctx := newTestAppContext(t)

tower := tower_model.Instance{
TowerID: "test-tower",
Name: "Test Tower",
Role: tower_model.RoleCore,
IsThisTower: true,
}

info := reshape.TowerToTowerInfo(ctx, tower)

if info.BuildVersion != "test-version-1.2.3" {
t.Fatalf("expected BuildVersion %q, got %q", "test-version-1.2.3", info.BuildVersion)
}
}
14 changes: 10 additions & 4 deletions weblens-vue/weblens-nuxt/pages/files.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,15 @@
<PathCrumbs />
</div>

<WebsocketStatus
:class="{ 'absolute right-4 bottom-4 hidden sm:block': true }"
:ws-status="wsStore.status"
/>
<div class="absolute right-4 bottom-3 hidden items-center gap-2 sm:flex">
<span
v-if="towerStore.towerInfo?.buildVersion"
class="text-text-tertiary font-mono text-xs"
>
{{ towerStore.towerInfo.buildVersion }}
</span>
<WebsocketStatus :ws-status="wsStore.status" />
</div>
</div>
</template>

Expand All @@ -96,6 +101,7 @@ const locationStore = useLocationStore()
const presentationStore = usePresentationStore()
const filesStore = useFilesStore()
const mediaStore = useMediaStore()
const towerStore = useTowerStore()

const presentingFile = computed(() => {
return filesStore.getFileByID(presentationStore.presentationFileID)
Expand Down
Loading