Commit 1bfdb005 authored by Michal Nowikowski's avatar Michal Nowikowski

[#344] addressed review issues

parent 11ccecf6
......@@ -15,8 +15,6 @@
type: object
required:
- logTargetOutput
- agentAddress
- agentPort
- appId
- appType
- contents
......@@ -24,12 +22,8 @@
logTargetOutput:
readOnly: true
type: string
agentAddress:
readOnly: true
type: string
agentPort:
readOnly: true
type: integer
machine:
$ref: '#/definitions/AppMachine'
appId:
readOnly: true
type: integer
......@@ -41,6 +35,9 @@
type: array
items:
type: string
error:
readOnly: true
type: string
Machine:
type: object
......
......@@ -149,7 +149,7 @@ func (sa *StorkAgent) ForwardRndcCommand(ctx context.Context, in *agentapi.Forwa
"Key": accessPoints[0].Key,
}).Errorf("Failed to forward commands to rndc: %+v", err)
rndcRsp.Status.Code = agentapi.Status_ERROR
rndcRsp.Status.Message = "Failed to forward commands to rndc"
rndcRsp.Status.Message = fmt.Sprintf("Failed to forward commands to rndc: %s", err.Error())
} else {
rndcRsp.Status.Code = agentapi.Status_OK
rndcRsp.Response = string(output)
......@@ -157,7 +157,7 @@ func (sa *StorkAgent) ForwardRndcCommand(ctx context.Context, in *agentapi.Forwa
response.Status = rndcRsp.Status
response.RndcResponse = rndcRsp
return response, err
return response, nil
}
// ForwardToNamedStats forwards a statistics request to the named daemon.
......@@ -181,7 +181,7 @@ func (sa *StorkAgent) ForwardToNamedStats(ctx context.Context, in *agentapi.Forw
"URL": reqURL,
}).Errorf("Failed to forward commands to named: %+v", err)
rsp.Status.Code = agentapi.Status_ERROR
rsp.Status.Message = "Failed to forward commands to named"
rsp.Status.Message = fmt.Sprintf("Failed to forward commands to named: %s", err.Error())
response.NamedStatsResponse = rsp
return response, nil
}
......@@ -194,7 +194,7 @@ func (sa *StorkAgent) ForwardToNamedStats(ctx context.Context, in *agentapi.Forw
"URL": reqURL,
}).Errorf("Failed to read the body of the named response: %+v", err)
rsp.Status.Code = agentapi.Status_ERROR
rsp.Status.Message = "Failed to read the body of the named response"
rsp.Status.Message = fmt.Sprintf("Failed to read the body of the named response: %s", err.Error())
response.NamedStatsResponse = rsp
return response, nil
}
......@@ -231,7 +231,7 @@ func (sa *StorkAgent) ForwardToKeaOverHTTP(ctx context.Context, in *agentapi.For
"URL": reqURL,
}).Errorf("Failed to forward commands to Kea: %+v", err)
rsp.Status.Code = agentapi.Status_ERROR
rsp.Status.Message = "Failed to forward commands to Kea"
rsp.Status.Message = fmt.Sprintf("Failed to forward commands to Kea: %s", err.Error())
response.KeaResponses = append(response.KeaResponses, rsp)
continue
}
......@@ -244,7 +244,7 @@ func (sa *StorkAgent) ForwardToKeaOverHTTP(ctx context.Context, in *agentapi.For
"URL": reqURL,
}).Errorf("Failed to read the body of the Kea response to forwarded commands: %+v", err)
rsp.Status.Code = agentapi.Status_ERROR
rsp.Status.Message = "Failed to read the body of the Kea response"
rsp.Status.Message = fmt.Sprintf("Failed to read the body of the Kea response: %s", err.Error())
response.KeaResponses = append(response.KeaResponses, rsp)
continue
}
......@@ -269,8 +269,8 @@ func (sa *StorkAgent) TailTextFile(ctx context.Context, in *agentapi.TailTextFil
f, err := os.Open(in.Path)
if err != nil {
response.Status.Code = agentapi.Status_ERROR
response.Status.Message = "Failed to open file for tailing"
return response, err
response.Status.Message = fmt.Sprintf("Failed to open file for tailing: %s", err.Error())
return response, nil
}
defer func() {
_ = f.Close()
......@@ -279,8 +279,8 @@ func (sa *StorkAgent) TailTextFile(ctx context.Context, in *agentapi.TailTextFil
stat, err := f.Stat()
if err != nil {
response.Status.Code = agentapi.Status_ERROR
response.Status.Message = "Failed to stat the file opened for tailing"
return response, err
response.Status.Message = fmt.Sprintf("Failed to stat the file opened for tailing: %s", err.Error())
return response, nil
}
offset := in.Offset
......@@ -292,8 +292,8 @@ func (sa *StorkAgent) TailTextFile(ctx context.Context, in *agentapi.TailTextFil
_, err = f.Seek(-offset, io.SeekEnd)
if err != nil {
response.Status.Code = agentapi.Status_ERROR
response.Status.Message = "Failed to seek in the file opened for tailing"
return response, err
response.Status.Message = fmt.Sprintf("Failed to seek in the file opened for tailing: %s", err.Error())
return response, nil
}
s := bufio.NewScanner(f)
for s.Scan() {
......
......@@ -415,7 +415,7 @@ func TestForwardRndcCommandError(t *testing.T) {
// Expect an error status code and some message.
rsp, err := sa.ForwardRndcCommand(ctx, req)
require.NotNil(t, rsp)
require.Error(t, err)
require.NoError(t, err)
require.Equal(t, agentapi.Status_ERROR, rsp.Status.Code)
require.NotEmpty(t, rsp.Status.Message)
}
......
......@@ -170,7 +170,7 @@ message TailTextFileReq {
// File to be tailed.
string path = 1;
// Seek info.
// Seek info. The offset is counted from the end of file.
int64 offset = 2;
}
......
......@@ -533,10 +533,14 @@ func (agents *connectedAgentsData) TailTextFile(ctx context.Context, agentAddres
"file": path,
}).Warnf("failed to fetch text file contents")
return []string{}, errors.Wrapf(err, "failed to fetch text file contents: %s", path)
return nil, errors.Wrapf(err, "failed to fetch text file contents: %s", path)
}
response := agentResponse.(*agentapi.TailTextFileRsp)
if response.Status.Code != agentapi.Status_OK {
return nil, errors.New(response.Status.Message)
}
return response.Lines, nil
}
......@@ -58,22 +58,24 @@ func (r *RestAPI) GetLogTail(ctx context.Context, params services.GetLogTailPara
// Send the request to the agent to tail the file.
contents, err := r.Agents.TailTextFile(ctx, dbLogTarget.Daemon.App.Machine.Address,
dbLogTarget.Daemon.App.Machine.AgentPort, dbLogTarget.Output, maxLength)
errStr := ""
if err != nil {
msg := fmt.Sprintf("cannot tail the log file with id %d", params.ID)
rsp := services.NewGetLogTailDefault(http.StatusInternalServerError).WithPayload(&models.APIError{
Message: &msg,
})
return rsp
errStr = err.Error()
}
// Everything ok. Return the response.
tail := &models.LogTail{
AgentAddress: dbLogTarget.Daemon.App.Machine.Address,
AgentPort: dbLogTarget.Daemon.App.Machine.AgentPort,
Machine: &models.AppMachine{
ID: dbLogTarget.Daemon.App.MachineID,
Address: dbLogTarget.Daemon.App.Machine.Address,
Hostname: dbLogTarget.Daemon.App.Machine.State.Hostname,
},
AppID: dbLogTarget.Daemon.App.ID,
AppType: dbLogTarget.Daemon.App.Type,
LogTargetOutput: dbLogTarget.Output,
Contents: contents,
Error: errStr,
}
rsp := services.NewGetLogTailOK().WithPayload(tail)
......
......@@ -70,8 +70,8 @@ func TestGetLogTail(t *testing.T) {
okRsp := rsp.(*services.GetLogTailOK).Payload
// Make sure that all values have been set correctly.
require.Equal(t, "localhost", okRsp.AgentAddress)
require.EqualValues(t, 8080, okRsp.AgentPort)
require.Equal(t, "localhost", okRsp.Machine.Address)
require.EqualValues(t, m.ID, okRsp.Machine.ID)
require.EqualValues(t, a.ID, okRsp.AppID)
require.Equal(t, a.Type, okRsp.AppType)
require.Equal(t, "/tmp/filename.log", okRsp.LogTargetOutput)
......
......@@ -9,7 +9,28 @@
<p-header>
<div style="display: flex; justify-content: space-between;">
<span class="ui-panel-title" style="margin-top: 5px; display: inline-block;">
{{ panelTitle }}
<ng-container *ngIf="!loaded">
Loading...
</ng-container>
<ng-container *ngIf="loaded">
Log {{ data.logTargetOutput }}
from
<app-entity-link entity="app" [attrs]="{ id: appId, type: appType, version: '' }"></app-entity-link>
on
<app-entity-link
entity="machine"
[attrs]="{ id: data.machine.id, address: data.machine.address }"
></app-entity-link>
<ng-container *ngIf="loadingError">
- loading failed: {{ loadingError }}
<i
class="pi pi-exclamation-circle"
style="font-size: 1.75em; vertical-align: bottom; color: red;"
></i>
</ng-container>
</ng-container>
</span>
<span>
<p-button
......
......@@ -20,8 +20,6 @@ import { ServicesService } from '../backend/api/api'
styleUrls: ['./log-view-page.component.sass'],
})
export class LogViewPageComponent implements OnInit {
panelTitle = 'Loading....'
maxLengthChunk = 4000
maxLength = this.maxLengthChunk
......@@ -30,6 +28,7 @@ export class LogViewPageComponent implements OnInit {
appTypeCapitalized: string
private _logId: number
contents: string[]
data: any
/**
* Indicates if the new request for data has been sent and the
......@@ -37,6 +36,7 @@ export class LogViewPageComponent implements OnInit {
* activated to indicate that the data are loading.
*/
loaded = false
loadingError = null
/**
* Constructor
......@@ -73,30 +73,8 @@ export class LogViewPageComponent implements OnInit {
this.loaded = false
this.servicesApi.getLogTail(this._logId, this.maxLength).subscribe(
(data) => {
// Set panel title.
this.panelTitle = data.logTargetOutput
let agentAddress = ''
if (data.agentAddress) {
agentAddress = data.agentAddress
}
let agentPort = 0
if (data.agentPort && data.agentPort > 0) {
agentPort = data.agentPort
}
if (agentAddress.length > 0 || agentPort > 0) {
this.panelTitle += ' (' + agentAddress
}
if (agentPort > 0) {
this.panelTitle += ':' + agentPort
}
if (agentAddress.length > 0 || agentPort > 0) {
this.panelTitle += ')'
}
// store received data
this.data = data
// Set other data.
this.appId = data.appId
......@@ -109,6 +87,19 @@ export class LogViewPageComponent implements OnInit {
// Disable the spinner.
this.loaded = true
// handle error case
if (data.error) {
this.msgSrv.add({
severity: 'error',
summary: 'Unable to get log file',
detail: 'Getting log with ID ' + this._logId + ' erred: ' + data.error,
life: 10000,
})
this.loadingError = data.error
} else {
this.loadingError = null
}
},
(err) => {
this.loaded = true
......@@ -123,6 +114,8 @@ export class LogViewPageComponent implements OnInit {
detail: 'Getting log with ID ' + this._logId + ' erred: ' + msg,
life: 10000,
})
this.loadingError = msg
}
)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment