Skip to content

Commit cb4f1bd

Browse files
authored
Merge pull request #246 from sdslabs/application-metrics-fix
Application metrics fix and make issues
2 parents 72b6a4e + 98e6c6c commit cb4f1bd

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

scripts/build/install_fresh.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ printf "🔨 Installing fresh\n"
1111
mkdir -p bin
1212
tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX)
1313
cd $tmp_dir
14-
GOPATH=$tmp_dir go get github.com/pilu/fresh
14+
GOPATH=$tmp_dir go install github.com/pilu/fresh@latest
1515
cp $tmp_dir/bin/fresh $project_dir/bin/fresh
1616
rm -rf $tmp_dir
1717

scripts/build/install_golint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ printf "🔨 Installing golint\n"
1111
mkdir -p bin
1212
tmp_dir=$(mktemp -d -t ci-XXXXXXXXXX)
1313
cd $tmp_dir
14-
GOPATH=$tmp_dir go get golang.org/x/lint/golint
14+
GOPATH=$tmp_dir go install golang.org/x/lint/golint@latest
1515
cp $tmp_dir/bin/golint $project_dir/bin/golint
1616
rm -rf $tmp_dir
1717

services/master/controllers/application.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ func FetchMetrics(c *gin.Context) {
237237
appName := c.Param("app")
238238
filter := utils.QueryToFilter(c.Request.URL.Query())
239239
var timeSpan int64
240+
var sparsity int64
240241
for unit, converter := range timeConversionMap {
241242
if val, ok := filter[unit].(string); ok {
242243
timeVal, err := strconv.ParseInt(val, 10, 64)
@@ -254,12 +255,25 @@ func FetchMetrics(c *gin.Context) {
254255
},
255256
}, -1)
256257

257-
sparsity := timeConversionMap[filter["sparsity"].(string)]
258+
// handle empty metrics
259+
if len(metrics) == 0 {
260+
c.JSON(200, types.M{
261+
"success": true,
262+
"data": []types.M{},
263+
})
264+
return
265+
}
266+
267+
if val, ok := filter["sparsityvalue"].(string); ok {
268+
sparsityVal, err := strconv.ParseInt(val, 10, 64)
269+
if err != nil {
270+
sparsity = sparsityVal * timeConversionMap[filter["sparsityunit"].(string)]
271+
}
272+
}
258273

259274
uptimeRecord := []bool{}
260275
CPURecord := []float64{}
261276
memoryRecord := []float64{}
262-
263277
baseTimestamp := metrics[0]["timestamp"].(int64)
264278
var downtimeIntensity int = 0
265279
var currTimestamp int64
@@ -277,10 +291,9 @@ func FetchMetrics(c *gin.Context) {
277291
uptimeRecord = append(uptimeRecord, true)
278292
}
279293
downtimeIntensity = 0
294+
CPURecord = append(CPURecord, metrics[i]["cpu_usage"].(float64))
295+
memoryRecord = append(memoryRecord, metrics[i]["memory_usage"].(float64))
280296
}
281-
282-
CPURecord = append(CPURecord, metrics[i]["cpu_usage"].(float64))
283-
memoryRecord = append(memoryRecord, metrics[i]["memory_usage"].(float64))
284297
}
285298

286299
metricsRecord := metricsRecord{uptimeRecord, CPURecord, memoryRecord}

services/master/routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func NewService() http.Handler {
7070
app.PATCH("/:app/rebuild", m.IsAppOwner, c.RebuildApp)
7171
app.PATCH("/:app/transfer/:user", m.IsAppOwner, c.TransferApplicationOwnership)
7272
app.GET("/:app/term", m.IsAppOwner, c.DeployWebTerminal)
73-
app.GET("/:app/metrics", c.FetchMetrics)
73+
app.GET("/:app/metrics", m.IsAppOwner, c.FetchMetrics)
7474
}
7575

7676
db := router.Group("/dbs")

0 commit comments

Comments
 (0)