Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from adalberht/master
Add new metrics tracking in manipulator (size and extension)
- Loading branch information
Showing
4 changed files
with
70 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package metrics | ||
|
||
// GetImageSizeCluster takes in byte array and return the size cluster for tracking purpose | ||
func GetImageSizeCluster(imageData []byte) string { | ||
switch sz := len(imageData); { | ||
case sz <= 128*1024: | ||
return "<=128KB" | ||
case sz <= 256*1024: | ||
return "<=256KB" | ||
case sz <= 512*1024: | ||
return "<=512KB" | ||
case sz <= 1024*1024: | ||
return "<=1MB" | ||
case sz <= 2048*1024: | ||
return "<=2MB" | ||
default: | ||
return ">2MB" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package metrics | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestGetImageSizeCluster(t *testing.T) { | ||
assert.Equal(t, "<=128KB", GetImageSizeCluster(make([]byte, 128*1024)), "<=500KB") | ||
assert.Equal(t, "<=256KB", GetImageSizeCluster(make([]byte, 256*1024)), "<=500KB") | ||
assert.Equal(t, "<=512KB", GetImageSizeCluster(make([]byte, 512*1024)), "<=500KB") | ||
assert.Equal(t, "<=1MB", GetImageSizeCluster(make([]byte, 1024*1024)), "<=500KB") | ||
assert.Equal(t, "<=2MB", GetImageSizeCluster(make([]byte, 2048*1024)), "<=500KB") | ||
assert.Equal(t, ">2MB", GetImageSizeCluster(make([]byte, 2049*1024)), "<=500KB") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters