Skip to content

Commit

Permalink
Merge pull request #15 from raj-prince/audit_ci
Browse files Browse the repository at this point in the history
Adding CI/CD Lint/Vet And StaticCheck
  • Loading branch information
raj-prince authored Sep 12, 2024
2 parents 4e1cdf1 + 6ea9b16 commit e546050
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 154 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Audit

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:

audit:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.23

- name: Verify dependencies
run: go mod verify

- name: Build
run: go build -v ./...

- name: Run go vet
run: go vet ./...

- name: Install staticcheck
run: go install honnef.co/go/tools/cmd/staticcheck@latest

- name: Run staticcheck
run: staticcheck ./...

- name: Install golint
run: go install golang.org/x/lint/golint@latest

- name: Run golint
run: golint ./...

- name: Run tests
run: go test -race -vet=off ./...
4 changes: 2 additions & 2 deletions auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"os"

"github.com/jacobsa/gcloud/gcs"
"golang.org/x/oauth2"
Expand All @@ -31,7 +31,7 @@ func newTokenSourceFromPath(
scope string,
) (ts oauth2.TokenSource, err error) {
// Read the file.
contents, err := ioutil.ReadFile(path)
contents, err := os.ReadFile(path)
if err != nil {
err = fmt.Errorf("ReadFile(%q): %w", path, err)
return
Expand Down
28 changes: 15 additions & 13 deletions benchmark-script/2x_performance_test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,24 @@ import (
)

var (

fDir = flag.String("dir", "", "Directory file to be opened.")
fSSD = flag.Bool("ssd", false, "Given directory is ssd or not.")
fDir = flag.String("dir", "", "Directory file to be opened.")
fSSD = flag.Bool("ssd", false, "Given directory is ssd or not.")
fileCount = flag.Int("file-count", 10, "Number of files to read")

FileSize = 512 * OneKB
OneKB = 1024
openLatency []int64
readLatency []int64
closeLatency []int64
fileSize = 512 * oneKB
oneKB = 1024
openLatency []int64
readLatency []int64
closeLatency []int64
totalReadLatency []int64
)

// ReadFilesSequentially sequentially reads n (fileCount) number of
// files from a directory one by one.
func ReadFilesSequentially(fileCount int) (err error) {
startTime := time.Now()

b := make([]byte, FileSize*1024)
b := make([]byte, fileSize*1024)

for i := 0; i < fileCount; i++ {

Expand Down Expand Up @@ -76,6 +77,7 @@ func ReadFilesSequentially(fileCount int) (err error) {
return
}

// Report prints the statistical measurement of the given latencies.
func Report(latency []int64, prefix string) {
sort.Slice(latency, func(i, j int) bool {
return latency[i] < latency[j]
Expand All @@ -90,8 +92,8 @@ func Report(latency []int64, prefix string) {
avg := sum / int64(sz)
fmt.Printf("Avg %s latency: %d us\n", prefix, avg)
fmt.Printf("Min %s latency: %d us\n", prefix, latency[0])
fmt.Printf("Max %s latency: %d us\n", prefix, latency[sz - 1])
fmt.Printf("Med %s latency: %d us\n", prefix, latency[sz / 2])
fmt.Printf("Max %s latency: %d us\n", prefix, latency[sz-1])
fmt.Printf("Med %s latency: %d us\n", prefix, latency[sz/2])
tt := (9 * sz) / 10
fmt.Printf("90th %s latency: %d us\n", prefix, latency[tt])

Expand All @@ -103,7 +105,7 @@ func main() {

err := ReadFilesSequentially(*fileCount)
if err != nil {
fmt.Println(os.Stderr, err)
fmt.Println(err)
os.Exit(1)
} else {
// Print the stats
Expand All @@ -112,4 +114,4 @@ func main() {
Report(readLatency, "read-file")
Report(closeLatency, "close-file")
}
}
}
1 change: 1 addition & 0 deletions benchmark-script/analyse_scale_result/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var (
forceDownload = flag.Bool("force-download", false, "Force download or not")
)

// DataRow represents one metrics.
type DataRow struct {
Timestamp int64
ReadLatency float64
Expand Down
35 changes: 4 additions & 31 deletions benchmark-script/dynamic_delay_plotter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"image/color"
"math"
"math/rand"
"os"
"path/filepath"
"strconv"
Expand All @@ -30,21 +29,6 @@ var (
outputFile = flag.String("output-file", "plot", "Plot file name")
)

func applySamples(p *plot.Plot, numSamples int, expectedValue float64, rnd *rand.Rand, d *util.Delay) {
var samplesOverThreshold int
for i := 0; i < numSamples; i++ {
randomDelay := time.Duration(-math.Log(rnd.Float64()) * expectedValue * float64(time.Second))
if randomDelay > d.Value() {
samplesOverThreshold++
d.Increase()
} else {
d.Decrease()
}
AddPoints(p, randomDelay.Seconds(), d.Value().Seconds())
}
fmt.Println("Over threshold: ", samplesOverThreshold)
}

// ConvertToXYs takes separate x and y slices and converts them into the correct plotter.XYs format
func ConvertToXYs(xValues, yValues []float64) plotter.XYs {
if len(xValues) != len(yValues) {
Expand Down Expand Up @@ -80,8 +64,6 @@ func actualSample(p *plot.Plot, dataRows []DataRow, d *util.Delay) {
xValues[i] = float64(i)
yValues1[i] = d.Value().Seconds()
yValues2[i] = actualDelay.Seconds()

//AddPoints(p, actualDelay.Seconds(), d.Value().Seconds())
}

// Add line series for the first curve (sine)
Expand All @@ -105,24 +87,15 @@ func actualSample(p *plot.Plot, dataRows []DataRow, d *util.Delay) {
fmt.Println("Over threshold: ", samplesOverThreshold)
}

func AddPoints(p *plot.Plot, x float64, y float64) {
// Create a slice of points (we'll have just one point)
pts := plotter.XYs{{X: x, Y: y}} // Adjust these coordinates as needed

// Add the points to the plot
scatter, err := plotter.NewScatter(pts)
if err != nil {
panic(err)
}
p.Add(scatter)
}

// DataRow represents one metrics.
type DataRow struct {
Timestamp int64
ReadLatency float64
Throughput float64
}

// GetDataRows parses all the CSV file present in a directory and return the
// list of DataRow.
func GetDataRows(folder string) ([]DataRow, error) {
// Store all data rows from all files
var allDataRows []DataRow
Expand Down Expand Up @@ -159,7 +132,7 @@ func GetDataRows(folder string) ([]DataRow, error) {
})

if err != nil {
return nil, fmt.Errorf("Error reading CSV files: %v\n", err)
return nil, fmt.Errorf("while reading CSV files: %v", err)
}

return allDataRows, nil
Expand Down
11 changes: 8 additions & 3 deletions benchmark-script/list_operation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

var fDir = flag.String("dir", "", "Directory within which listing performed.")
var fGoList = flag.Bool("go-list", false, "Directory within which listing performed using go-list.")

// This doesn't match with
func runListingGoScript() (err error) {
Expand Down Expand Up @@ -66,12 +67,16 @@ func runListingCommandLine() (err error) {
}

func main() {

flag.Parse()

err := runListingCommandLine()
var err error
if *fGoList {
err = runListingGoScript()
} else {
err = runListingCommandLine()
}
if err != nil {
fmt.Println(os.Stderr, err)
fmt.Println(err)
os.Exit(1)
}

Expand Down
2 changes: 1 addition & 1 deletion benchmark-script/open_file/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func main() {

err := runOpenFileOperations()
if err != nil {
fmt.Println(os.Stderr, err)
fmt.Println(err)
os.Exit(1)
}

Expand Down
33 changes: 22 additions & 11 deletions benchmark-script/pprof_test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,22 @@ package main
import (
"crypto/md5"
"fmt"
"google.golang.org/api/googleapi"
"os"
"runtime"
"runtime/pprof"
"strings"
"time"
"unsafe"

"google.golang.org/api/googleapi"
)

const (

// KiB means 1024 bytes.
KiB = 1024

// MiB means 1024 KiB.
MiB = 1024 * KiB
)

Expand All @@ -28,7 +33,7 @@ func profileOnce(path string) (err error) {
var f *os.File
f, err = os.Create(path)
if err != nil {
err = fmt.Errorf("Create: %w", err)
err = fmt.Errorf("create: %w", err)
return
}

Expand Down Expand Up @@ -75,6 +80,7 @@ func profileOnce(path string) (err error) {
//
// }

// ObjectAccessControlProjectTeam represents a team.
type ObjectAccessControlProjectTeam struct {
// ProjectNumber: The project number.
ProjectNumber string `json:"projectNumber,omitempty"`
Expand All @@ -99,7 +105,7 @@ type ObjectAccessControlProjectTeam struct {
NullFields []string `json:"-"`
}

// ObjectAccessControl: An access-control entry.
// ObjectAccessControl is an access-control entry.
type ObjectAccessControl struct {
// Bucket: The name of the bucket.
Bucket string `json:"bucket,omitempty"`
Expand All @@ -114,7 +120,7 @@ type ObjectAccessControl struct {
// forms:
// - user-userId
// - user-email
// - group-groupId
// - group-groupID
// - group-email
// - domain-domain
// - project-team-projectId
Expand All @@ -127,8 +133,8 @@ type ObjectAccessControl struct {
// example.com, the entity would be domain-example.com.
Entity string `json:"entity,omitempty"`

// EntityId: The ID for the entity, if any.
EntityId string `json:"entityId,omitempty"`
// EntityID: The ID for the entity, if any.
EntityID string `json:"entityId,omitempty"`

// Etag: HTTP 1.1 Entity tag for the access-control entry.
Etag string `json:"etag,omitempty"`
Expand All @@ -137,8 +143,8 @@ type ObjectAccessControl struct {
// object.
Generation int64 `json:"generation,omitempty,string"`

// Id: The ID of the access-control entry.
Id string `json:"id,omitempty"`
// ID: The ID of the access-control entry.
ID string `json:"id,omitempty"`

// Kind: The kind of item this is. For object access control entries,
// this is always storage#objectAccessControl.
Expand Down Expand Up @@ -176,6 +182,8 @@ type ObjectAccessControl struct {
// This may be used to include null fields in Patch requests.
NullFields []string `json:"-"`
}

// Test is just a test struct for memory experiment.
type Test struct {
Name string
ContentType string
Expand Down Expand Up @@ -218,9 +226,10 @@ type Test struct {
ContentDisposition string
CustomTime string
EventBasedHold bool
Acl []ObjectAccessControl
ACL []ObjectAccessControl
}

// CloneMap just do deep copy of a map.
func CloneMap(m map[string]string) map[string]string {

//return &map[string]string{strings.Clone("key1"): strings.Clone("testddddddd"),
Expand All @@ -233,13 +242,15 @@ func CloneMap(m map[string]string) map[string]string {

return newMap
}

// GetObject returns a customized Test object.
func GetObject() *Test {
return &Test{
Name: strings.Clone("aa"),
ContentType: "text/plane",
Metadata: map[string]string{strings.Clone("key1"): strings.Clone("testddddddd"),
strings.Clone("key2"): strings.Clone("testddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddhffffffffffffff")},
Acl: []ObjectAccessControl{{}, {}, {}, {}, {}},
ACL: []ObjectAccessControl{{}, {}, {}, {}, {}},
}
}

Expand Down Expand Up @@ -273,7 +284,7 @@ func temp() []*Test {
fmt.Println(len(clone3))
test = append(test, test1)
}
fmt.Println("Object ACL: %v", unsafe.Sizeof(ObjectAccessControl{}))
fmt.Printf("Object ACL: %v\n", unsafe.Sizeof(ObjectAccessControl{}))
return test
}
func main() {
Expand Down
3 changes: 2 additions & 1 deletion benchmark-script/read_operation/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var (

eG errgroup.Group

// OneKB means 1024 bytes.
OneKB = 1024

fNumberOfRead = flag.Int("read-count", 1, "number of read iteration")
Expand Down Expand Up @@ -112,7 +113,7 @@ func main() {

err := runReadFileOperations()
if err != nil {
fmt.Println(os.Stderr, err)
fmt.Println(err)
os.Exit(1)
}

Expand Down
Loading

0 comments on commit e546050

Please sign in to comment.