Skip to content

Commit

Permalink
update trigger file.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Assassin718 committed Aug 11, 2024
1 parent 439fbe1 commit 6edfc68
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ on:

jobs:
CI:
if: github.event.pull_request.merged == true
# if: github.event.pull_request.merged == true
runs-on: ${{ matrix.runner }}
timeout-minutes: 60
strategy:
Expand Down Expand Up @@ -88,20 +88,11 @@ jobs:
path: ./cache
key: ${{ runner.os }}-benchmark

<<<<<<< HEAD
- name: Store benchmark result
=======
- name: Store benchmark result iLogtail
>>>>>>> a9705b46 (update github benchmark CI to store avg/max ans time records)
uses: benchmark-action/github-action-benchmark@v1
with:
name: benchmark
tool: "customSmallerIsBetter"
<<<<<<< HEAD
output-file-path: "test/benchmark/report/combined_benchmark.json"
external-data-json-path: ./cache/benchmark-data.json
summary-always: true
=======
output-file-path: "test/benchmark/report/ilogtail_statistic_all.json"
external-data-json-path: ./cache/ilogtail_statistic.json
auto-push: false
Expand All @@ -120,13 +111,11 @@ jobs:
# - name: Push benchmark result
# run: git push 'https://alibaba:${{ secrets.GITHUB_TOKEN }}@github.com/alibaba/ilogtail.git' gh-pages:gh-pages

>>>>>>> a9705b46 (update github benchmark CI to store avg/max ans time records)

result:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
timeout-minutes: 60
needs: [ CI ]
steps:
- name: Build Result
run: echo "Just to make the GitHub merge button green"
run: echo "Just to make the GitHub merge button green"
20 changes: 6 additions & 14 deletions test/engine/trigger/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package trigger

import (
"context"
"fmt"
"os"
"os/exec"
"path/filepath"
"time"

Expand All @@ -18,13 +16,9 @@ func GenerateLogToFile(ctx context.Context, speed, totalTime int, path string, t
path = filepath.Join(config.CaseHome, path)
path = filepath.Clean(path)
_ = os.WriteFile(path, []byte{}, 0600)
file, _ := os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0600) // #nosec G304

command := fmt.Sprintf("echo '%s' >> %s", templateStr, path)

// interval = templateLen / speed
interval := time.Microsecond * time.Duration(len(templateStr)/speed)

limiter := rate.NewLimiter(rate.Every(interval), 1)
limiter := rate.NewLimiter(rate.Limit(speed*1024*1024), len(templateStr))

timeout := time.After(time.Minute * time.Duration(totalTime))

Expand All @@ -33,19 +27,17 @@ func GenerateLogToFile(ctx context.Context, speed, totalTime int, path string, t
// context is done
case <-ctx.Done():
// clear file
_ = os.WriteFile(path, []byte{}, 0600)
_ = file.Close()
return ctx, ctx.Err()
// all time is done
case <-timeout:
// clear file
_ = os.WriteFile(path, []byte{}, 0600)
_ = file.Close()
return ctx, nil
default:
if err := limiter.Wait(ctx); err != nil {
return ctx, err
if limiter.AllowN(time.Now(), len(templateStr)) {
_, _ = file.WriteString(templateStr + "\n")
}
cmd := exec.Command("sh", "-c", command)
_ = cmd.Run()
}
}
}

0 comments on commit 6edfc68

Please sign in to comment.