Skip to content

Commit

Permalink
Merge pull request #39 from CapillarySoftware/fix_partition_detection
Browse files Browse the repository at this point in the history
fix regex with tests
  • Loading branch information
vrecan committed Jul 16, 2014
2 parents ad76499 + fdb1c3d commit 939273b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var LastRawStat = make(map[string]diskStat.DiskStat)
var partition = regexp.MustCompile(`\w.*\d`)
var partition = regexp.MustCompile(`\w.*[^-]\d`)

const oneSecondInMilli = 1000

Expand All @@ -35,6 +35,10 @@ type DiskStatDiff struct {
SectorsTotalRaw float64
}

func IsPartition(device *string) (r bool) {
return partition.MatchString(*device)
}

//TransformStat goroutine function to transform the stats and send to the stats output channel.
func TransformStat(channel <-chan *diskStat.DiskStat, statsOutputChannel chan *diskStat.ExtendedIoStats) (err error) {
for {
Expand All @@ -46,7 +50,7 @@ func TransformStat(channel <-chan *diskStat.DiskStat, statsOutputChannel chan *d

if in {
//ignore partitions with no history of activity
if (stat.ReadsCompleted == 0 && stat.WritesCompleted == 0) || partition.MatchString(stat.Device) {
if (stat.ReadsCompleted == 0 && stat.WritesCompleted == 0) || IsPartition(&stat.Device){
continue
}
diffStat, err := getDiffDiskStat(&prevStat, stat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ type error interface {

var _ = Describe("IoStatTransform", func() {

Describe("Unit tests", func() {
It("validate partition regex doesn't get hit when using raid controllers", func() {
device := "md-1"
Expect(IsPartition(&device)).Should(BeFalse())
})
It("validate partition regeg against device", func() {
device := "sda"
Expect(IsPartition(&device)).Should(BeFalse())
})

It("validate partition regeg against partition", func() {
device := "sda1"
Expect(IsPartition(&device)).Should(BeTrue())
})
})

Describe("IntegrationTest", func() {

var (
Expand Down

0 comments on commit 939273b

Please sign in to comment.