Skip to content
This repository was archived by the owner on Mar 16, 2024. It is now read-only.

Commit fb40c49

Browse files
authored
Add support for metrics in containers and jobs (#830) (#1758)
Signed-off-by: Grant Linville <[email protected]>
1 parent fb452e6 commit fb40c49

File tree

127 files changed

+610
-100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+610
-100
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ replace (
1212
require (
1313
cuelang.org/go v0.5.0
1414
github.com/AlecAivazis/survey/v2 v2.3.6
15-
github.com/acorn-io/aml v0.0.0-20230612000521-a812941e7fab
15+
github.com/acorn-io/aml v0.0.0-20230619192500-1f56a8955db2
1616
github.com/acorn-io/baaah v0.0.0-20230617011755-3291c17915f5
1717
github.com/acorn-io/mink v0.0.0-20230523184405-ceaaa366d500
1818
github.com/acorn-io/namegenerator v0.0.0-20220915160418-9e3d5a0ffe78

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ github.com/ThalesIgnite/crypto11 v1.2.5 h1:1IiIIEqYmBvUYFeMnHqRft4bwf/O36jryEUpY
9393
github.com/ThalesIgnite/crypto11 v1.2.5/go.mod h1:ILDKtnCKiQ7zRoNxcp36Y1ZR8LBPmR2E23+wTQe/MlE=
9494
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
9595
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
96-
github.com/acorn-io/aml v0.0.0-20230612000521-a812941e7fab h1:ZJQSAT306ILs8ZDGBMuPJeQN8OCP4bPLhTBw/vHLY+s=
97-
github.com/acorn-io/aml v0.0.0-20230612000521-a812941e7fab/go.mod h1:UEx5RRLFjryCEHN2pM59+d8A0mPJ3VAxggJOTzPymwg=
96+
github.com/acorn-io/aml v0.0.0-20230619192500-1f56a8955db2 h1:tWz51cHGC6GURkKqA4PdG3ObHz2YBrVzCfxXacNUqVY=
97+
github.com/acorn-io/aml v0.0.0-20230619192500-1f56a8955db2/go.mod h1:UEx5RRLFjryCEHN2pM59+d8A0mPJ3VAxggJOTzPymwg=
9898
github.com/acorn-io/baaah v0.0.0-20230617011755-3291c17915f5 h1:NdDW2tFRDHElXpcFeqTDKg6wB0uRLzJ5Kq0YDgYl/Dg=
9999
github.com/acorn-io/baaah v0.0.0-20230617011755-3291c17915f5/go.mod h1:LtwaWrYK/VuGptWxeD5Sgl0sgJV1ksicpTzyLilow1U=
100100
github.com/acorn-io/mink v0.0.0-20230523184405-ceaaa366d500 h1:tiM36bM+iMWuW9HM+YlM1GfNDXC7f565z8Be5epO0qM=

pkg/apis/api.acorn.io/v1/zz_generated.deepcopy.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/internal.acorn.io/v1/appspec.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ type Container struct {
365365
ComputeClass *string `json:"class,omitempty"`
366366
Memory *int64 `json:"memory,omitempty"`
367367

368+
// Metrics is available on containers and jobs, but not sidecars
369+
Metrics MetricsDef `json:"metrics,omitempty"`
370+
368371
// Scale is only available on containers, not sidecars or jobs
369372
Scale *int32 `json:"scale,omitempty"`
370373

@@ -461,6 +464,11 @@ type MemoryMap map[string]*int64
461464
// Workload to its class
462465
type ComputeClassMap map[string]string
463466

467+
type MetricsDef struct {
468+
Port int32 `json:"port,omitempty"`
469+
Path string `json:"path,omitempty"`
470+
}
471+
464472
type GeneratedService struct {
465473
Job string `json:"job,omitempty"`
466474
}

pkg/apis/internal.acorn.io/v1/zz_generated.deepcopy.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cli/testdata/all/all_test_json.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ CONTAINERS:
4040
},
4141
"spec": {
4242
"probes": null,
43+
"metrics": {},
4344
"appName": "found"
4445
},
4546
"status": {

pkg/cli/testdata/all/all_test_yaml.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ items:
2727
name: found.container
2828
spec:
2929
appName: found
30+
metrics: {}
3031
probes: null
3132
status:
3233
columns: {}

pkg/cli/testdata/render/render_test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
]
1111
probes: null
1212
permissions: {}
13+
metrics: {}
1314
}
1415
}

pkg/controller/appdefinition/deploy.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"net/url"
99
"path"
10+
"strconv"
1011
"strings"
1112

1213
v1 "github.com/acorn-io/acorn/pkg/apis/internal.acorn.io/v1"
@@ -476,6 +477,8 @@ func podAnnotations(appInstance *v1.AppInstance, container v1.Container) map[str
476477
annotations := map[string]string{
477478
labels.AcornContainerSpec: containerAnnotation(container),
478479
}
480+
addPrometheusAnnotations(annotations, container)
481+
479482
images := map[string]string{}
480483
addImageAnnotations(images, appInstance, container)
481484

@@ -503,6 +506,14 @@ func addImageAnnotations(annotations map[string]string, appInstance *v1.AppInsta
503506
}
504507
}
505508

509+
func addPrometheusAnnotations(annotations map[string]string, container v1.Container) {
510+
if container.Metrics.Path != "" && container.Metrics.Port != 0 {
511+
annotations[labels.PrometheusScrape] = "true"
512+
annotations[labels.PrometheusPath] = container.Metrics.Path
513+
annotations[labels.PrometheusPort] = strconv.Itoa(int(container.Metrics.Port))
514+
}
515+
}
516+
506517
func isStateful(appInstance *v1.AppInstance, container v1.Container) bool {
507518
for _, dir := range container.Dirs {
508519
if dir.Secret.Name != "" {

pkg/controller/appdefinition/deploy_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ func TestDeploySpecStop(t *testing.T) {
6868
tester.DefaultTest(t, scheme.Scheme, "testdata/deployspec/stop", DeploySpec)
6969
}
7070

71+
func TestDeploySpecMetrics(t *testing.T) {
72+
tester.DefaultTest(t, scheme.Scheme, "testdata/deployspec/metrics", DeploySpec)
73+
}
74+
7175
func TestProbe(t *testing.T) {
7276
tester.DefaultTest(t, scheme.Scheme, "testdata/probes", DeploySpec)
7377
}

0 commit comments

Comments
 (0)