Skip to content

Commit

Permalink
feat: address lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulguptajss committed Aug 22, 2023
1 parent 6cac8fd commit b5749e1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 8 deletions.
7 changes: 1 addition & 6 deletions cmd/poller/plugin/changelog/change_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,7 @@ func (c *ChangeLog) Init() error {
return err
}

// Populate the ChangeLog configuration
if err := c.populateChangeLogConfig(); err != nil {
return err
}

return nil
return c.populateChangeLogConfig()
}

// populateChangeLogConfig populates the ChangeLog configuration from the plugin parameters
Expand Down
63 changes: 63 additions & 0 deletions main/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package main

import (
"fmt"
"math/rand"
"net/http"
"sort"
"strings"
"sync"
"time"
)

var (
metrics string
metricsMutex sync.RWMutex
)

func generateMetrics() {
now := time.Now()
metricsSlice := make([]string, 0, 10)

for i := 0; i < 5; i++ {
timestamp := now.Add(time.Duration(-i)*time.Minute).UnixNano() / int64(time.Millisecond)
value1 := rand.Intn(500) + 100 // Random value between 100 and 599
//value2 := rand.Intn(500) + 100 // Random value between 100 and 599
metricsSlice = append(metricsSlice, fmt.Sprintf("http_requests_total{code=\"200\",service=\"user\",index=\"%d\"} %d %d", i, value1, timestamp))
//newMetrics += fmt.Sprintf("http_requests_total{code=\"500\",service=\"user%d\"} %d %d\n", i+1, value2, timestamp)

}
sort.Strings(metricsSlice)
newMetrics := strings.Join(metricsSlice, "\n") + "\n"

metricsMutex.Lock()
metrics = newMetrics
metricsMutex.Unlock()
}

func metricsHandler(w http.ResponseWriter, r *http.Request) {
metricsMutex.RLock()
defer metricsMutex.RUnlock()
fmt.Fprint(w, metrics)
}

func main() {
rand.Seed(time.Now().UnixNano()) // Seed the random number generator

// Generate initial metrics
generateMetrics()

// Set up a ticker to generate new metrics every 5 minutes
ticker := time.NewTicker(5 * time.Minute)
go func() {
for range ticker.C {
fmt.Printf("generate")
generateMetrics()
}
}()

http.HandleFunc("/metrics", metricsHandler)

fmt.Println("Starting server on :12990")
http.ListenAndServe(":12990", nil)
}
4 changes: 2 additions & 2 deletions pkg/dict/dict.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
package dict

import (
"github.com/netapp/harvest/v2/pkg/util"
"reflect"
"slices"
"strings"
)

Expand Down Expand Up @@ -129,7 +129,7 @@ func (d *Dict) CompareLabels(prev *Dict, labels []string) (*Dict, *Dict) {
old := New()
for key, val1 := range d.dict {
val2, ok := prev.dict[key]
if util.Contains(labels, key) && (!ok || !reflect.DeepEqual(val1, val2)) {
if slices.Contains(labels, key) && (!ok || !reflect.DeepEqual(val1, val2)) {
cur.dict[key] = val1
old.dict[key] = val2
}
Expand Down

0 comments on commit b5749e1

Please sign in to comment.