Skip to content

Commit 9114bde

Browse files
feat: Use multiple time formats for system resource metrics (#493)
* feat: Use multiple time formats for system resource metrics * feat: integration tests on ubuntu 24.04 * fix: dockerfile ci issue * fix: CI issues
1 parent 21f2709 commit 9114bde

File tree

5 files changed

+80
-3
lines changed

5 files changed

+80
-3
lines changed

.semaphore/semaphore.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,57 @@ blocks:
792792
commands:
793793
- 'test-results publish report.xml --name="Bats: Linux" --suite-prefix=$TEST'
794794

795+
- name: "Bats: Ubuntu 24.04"
796+
dependencies:
797+
- "Build local CLIs"
798+
task:
799+
agent:
800+
machine:
801+
type: e2-standard-2
802+
os_image: ubuntu2404
803+
prologue:
804+
commands:
805+
- checkout
806+
- artifact pull workflow bin/linux/amd64/cache -d cache-cli/bin/linux/amd64/cache
807+
- artifact pull workflow bin/linux/arm64/cache -d cache-cli/bin/linux/arm64/cache
808+
- artifact pull workflow bin/darwin/amd64/cache -d cache-cli/bin/darwin/amd64/cache
809+
- artifact pull workflow bin/darwin/arm64/cache -d cache-cli/bin/darwin/arm64/cache
810+
- artifact pull workflow bin/linux/amd64/sem-context -d sem-context/bin/linux/amd64/sem-context
811+
- artifact pull workflow bin/linux/arm64/sem-context -d sem-context/bin/linux/arm64/sem-context
812+
- artifact pull workflow bin/darwin/amd64/sem-context -d sem-context/bin/darwin/amd64/sem-context
813+
- artifact pull workflow bin/darwin/arm64/sem-context -d sem-context/bin/darwin/arm64/sem-context
814+
- artifact pull workflow bin/linux/amd64/test-results -d test-results/bin/linux/amd64/test-results
815+
- artifact pull workflow bin/linux/arm64/test-results -d test-results/bin/linux/arm64/test-results
816+
- artifact pull workflow bin/darwin/amd64/test-results -d test-results/bin/darwin/amd64/test-results
817+
- artifact pull workflow bin/darwin/arm64/test-results -d test-results/bin/darwin/arm64/test-results
818+
- bash release/create.sh
819+
- source tests/sftp_server/start_on_linux.sh
820+
- sudo apt-get install -y python3.8-dev
821+
- sem-version python 3.11
822+
- sem-version go 1.22
823+
- sem-version php 8.2.20
824+
jobs:
825+
- name: "Non-cache tests"
826+
matrix:
827+
- env_var: TEST
828+
values:
829+
- tests/install_package.bats
830+
- tests/artifacts.bats
831+
- tests/compiler.bats
832+
- tests/test-results.bats
833+
- tests/enetwork.bats
834+
- tests/sem-semantic-release.bats
835+
commands:
836+
- source release/install_in_tests.sh
837+
- git submodule init && git submodule update
838+
- sudo ./tests/support/bats-core/install.sh /usr/local
839+
- bats --report-formatter junit --tap --timing $TEST
840+
841+
epilogue:
842+
always:
843+
commands:
844+
- 'test-results publish report.xml --name="Bats: Linux" --suite-prefix=$TEST'
845+
795846
- name: "Cache CLI: Tests"
796847
dependencies: []
797848
task:

Dockerfile.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM ubuntu:20.04
33
ARG DEBIAN_FRONTEND=noninteractive
44

55
RUN apt-get update -qy
6-
RUN apt-get install -y wget apt-transport-https software-properties-common git
6+
RUN apt-get install -y --fix-missing wget apt-transport-https software-properties-common git
77

88
RUN wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb && \
99
dpkg -i packages-microsoft-prod.deb && \

cache-cli/pkg/utils/check.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//revive:disable-next-line:var-naming
12
package utils
23

34
import (

test-results/cmd/resource-metrics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"time"
1111

12+
"github.com/semaphoreci/toolbox/test-results/pkg/parser"
1213
"github.com/spf13/cobra"
1314
)
1415

@@ -89,8 +90,7 @@ var resourceMetricsCmd = &cobra.Command{
8990
dockerDiskSeries []string
9091
)
9192

92-
layout := "Mon 02 Jan 2006 03:04:05 PM MST"
93-
startTime, err := time.Parse(layout, metrics[0].Timestamp)
93+
startTime, layout, err := parser.ParseTimeAuto(metrics[0].Timestamp)
9494
if err != nil {
9595
return fmt.Errorf("failed to parse start time: %w", err)
9696
}

test-results/pkg/parser/time.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package parser
2+
3+
import (
4+
"fmt"
5+
"time"
6+
)
7+
8+
var layouts = []string{
9+
time.RFC1123,
10+
time.RFC1123Z,
11+
"Mon 02 Jan 2006 03:04:05 PM MST",
12+
"Mon Jan 2 15:04:05 MST 2006",
13+
"Mon Jan 2 03:04:05 PM MST 2006",
14+
"Mon Jan 2 15:04:05 UTC 2006",
15+
}
16+
17+
func ParseTimeAuto(input string) (time.Time, string, error) {
18+
for _, layout := range layouts {
19+
t, err := time.Parse(layout, input)
20+
if err == nil {
21+
return t, layout, nil
22+
}
23+
}
24+
return time.Time{}, "", fmt.Errorf("no matching layout found for: %s", input)
25+
}

0 commit comments

Comments
 (0)