Skip to content

Commit

Permalink
fix lint errors in internal/observability/
Browse files Browse the repository at this point in the history
  • Loading branch information
JyotinderSingh committed Oct 11, 2024
1 parent 290d8a6 commit f1e4572
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion internal/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ func evalJSONDEL(args []string, store *dstore.Store) []byte {

hasBrackets := strings.Contains(path, "[") && strings.Contains(path, "]")

//If the command has square brackets then we have to delete an element inside an array
// If the command has square brackets then we have to delete an element inside an array
if hasBrackets {
_, err = expr.Remove(jsonData)
} else {
Expand Down
5 changes: 5 additions & 0 deletions internal/observability/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package observability

const linux = "linux"
const darwin = "darwin"
const windows = "windows"
12 changes: 6 additions & 6 deletions internal/observability/hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ func getTotalMemoryMB() (int64, error) {
var res string
var err error
switch runtime.GOOS {
case "linux":
case linux:
res, err = executeCommand("free -b | grep Mem | awk '{print $2}'")
if err != nil {
return 0, fmt.Errorf("error:stats.total_memory_mb failed to capture memory err=%w", err)
}
case "darwin":
case darwin:
res, err = executeCommand("sysctl -n hw.memsize")
if err != nil {
return 0, fmt.Errorf("error:stats.total_memory_mb failed to capture memory err=%w", err)
}
case "windows":
case windows:
res, err = executeCommand("wmic OS get TotalVisibleMemorySize /Value")
if err != nil {
return 0, fmt.Errorf("error:stats.total_memory_mb failed to capture memory err=%w", err)
Expand Down Expand Up @@ -87,17 +87,17 @@ func getTotalDiskMB() (int64, error) {
var res string
var err error
switch runtime.GOOS {
case "linux":
case linux:
res, err = executeCommand("df --block-size=1 / | tail -1 | awk '{print $2}'")
if err != nil {
return 0, fmt.Errorf("error:stats.total_disk_mb failed to capture disk usage err=%w", err)
}
case "darwin":
case darwin:
res, err = executeCommand("df -k / | tail -1 | awk '{print $2}'")
if err != nil {
return 0, fmt.Errorf("error:stats.total_disk_mb failed to capture disk usage err=%w", err)
}
case "windows":
case windows:
res, err = executeCommand("wmic logicaldisk get size /Value")
if err != nil {
return 0, fmt.Errorf("error:stats.total_disk_mb failed to capture disk usage err=%w", err)
Expand Down
1 change: 1 addition & 0 deletions internal/observability/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func GetOrCreateInstanceID() string {

if _, err := os.Stat(filePath); os.IsNotExist(err) {
id := uuid.New().String()
// #nosec G306
if err := os.WriteFile(filePath, []byte(id), 0644); err != nil {

Check failure on line 20 in internal/observability/instance.go

View workflow job for this annotation

GitHub Actions / lint

G306: Expect WriteFile permissions to be 0600 or less (gosec)
slog.Error("unable to create dicedb.iid hence running anon", slog.Any("error", err))
return ""
Expand Down
6 changes: 4 additions & 2 deletions internal/observability/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package observability

import (
"bytes"
"context"
"encoding/json"
"net/http"
"time"
Expand Down Expand Up @@ -39,7 +40,8 @@ func Ping() {
url := "https://api.us-east.aws.tinybird.co/v0/events?name=ping"
b, _ := json.Marshal(payload)

req, _ := http.NewRequest("POST", url, bytes.NewBuffer(b))
req, _ := http.NewRequestWithContext(context.Background(), "POST", url, bytes.NewBuffer(b))
//nolint:lll
req.Header.Set("Authorization", "Bearer p.eyJ1IjogIjhjNWQxMjdlLTczZmYtNGRjZS04Mzk5LTQyMDU0MThhYjc2OSIsICJpZCI6ICJhZjcxNGExNC0xZWQyLTQ3ZDktOTM0MS0xMzgwNWNiOWFhNDYiLCAiaG9zdCI6ICJ1cy1lYXN0LWF3cyJ9.o9LqZqTZ9YkhbcusZOltsm95RzVQUzJLQOHV2YA7L0E")
req.Header.Set("Content-Type", "application/json")

Expand All @@ -48,5 +50,5 @@ func Ping() {
if err != nil {
panic(err)
}
defer resp.Body.Close()
resp.Body.Close()
}

0 comments on commit f1e4572

Please sign in to comment.