Skip to content

Commit 9c4071e

Browse files
committed
work on resources monitoring
1 parent 5762d8a commit 9c4071e

File tree

7 files changed

+774
-498
lines changed

7 files changed

+774
-498
lines changed

provisioner/terraform/provision.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func (s *server) Plan(
7878

7979
e := s.executor(sess.WorkDirectory, database.ProvisionerJobTimingStagePlan)
8080
if err := e.checkMinVersion(ctx); err != nil {
81-
return provisionersdk.PlanErrorf(err.Error())
81+
return provisionersdk.PlanErrorf("%s", err.Error())
8282
}
8383
logTerraformEnvVars(sess)
8484

@@ -168,7 +168,7 @@ func (s *server) Plan(
168168
request.Metadata.GetWorkspaceTransition() == proto.WorkspaceTransition_DESTROY,
169169
)
170170
if err != nil {
171-
return provisionersdk.PlanErrorf(err.Error())
171+
return provisionersdk.PlanErrorf("%s", err.Error())
172172
}
173173

174174
// Prepend init timings since they occur prior to plan timings.
@@ -189,7 +189,7 @@ func (s *server) Apply(
189189

190190
e := s.executor(sess.WorkDirectory, database.ProvisionerJobTimingStageApply)
191191
if err := e.checkMinVersion(ctx); err != nil {
192-
return provisionersdk.ApplyErrorf(err.Error())
192+
return provisionersdk.ApplyErrorf("%s", err.Error())
193193
}
194194
logTerraformEnvVars(sess)
195195

provisioner/terraform/resources.go

+32
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ type agentAttributes struct {
5656
Metadata []agentMetadata `mapstructure:"metadata"`
5757
DisplayApps []agentDisplayAppsAttributes `mapstructure:"display_apps"`
5858
Order int64 `mapstructure:"order"`
59+
ResourcesMonitoring agentResourcesMonitoring `mapstructure:"resources_monitoring"`
60+
}
61+
62+
type agentResourcesMonitoring struct {
63+
Memory agentResourceMonitor `mapstructure:"memory"`
64+
Volumes map[string]agentResourceMonitor `mapstructure:"volumes"`
65+
}
66+
67+
type agentResourceMonitor struct {
68+
Enabled bool `mapstructure:"enabled"`
69+
Threshold int32 `mapstructure:"threshold"`
5970
}
6071

6172
type agentDisplayAppsAttributes struct {
@@ -239,6 +250,26 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
239250
}
240251
}
241252

253+
resourcesMonitoring := &proto.ResourcesMonitoring{
254+
Memory: func() *proto.Resourcemonitor {
255+
return &proto.Resourcemonitor{
256+
Enabled: attrs.ResourcesMonitoring.Memory.Enabled,
257+
Threshold: attrs.ResourcesMonitoring.Memory.Threshold,
258+
}
259+
}(),
260+
Volumes: func() map[string]*proto.Resourcemonitor {
261+
volumes := make(map[string]*proto.Resourcemonitor)
262+
for key, value := range attrs.ResourcesMonitoring.Volumes {
263+
volumes[key] = &proto.Resourcemonitor{
264+
Enabled: value.Enabled,
265+
Threshold: value.Threshold,
266+
}
267+
}
268+
269+
return volumes
270+
}(),
271+
}
272+
242273
agent := &proto.Agent{
243274
Name: tfResource.Name,
244275
Id: attrs.ID,
@@ -249,6 +280,7 @@ func ConvertState(ctx context.Context, modules []*tfjson.StateModule, rawGraph s
249280
ConnectionTimeoutSeconds: attrs.ConnectionTimeoutSeconds,
250281
TroubleshootingUrl: attrs.TroubleshootingURL,
251282
MotdFile: attrs.MOTDFile,
283+
ResourcesMonitoring: resourcesMonitoring,
252284
Metadata: metadata,
253285
DisplayApps: displayApps,
254286
Order: attrs.Order,

provisioner/terraform/timings_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func TestTimingsFromProvision(t *testing.T) {
2828
// Given: a fake terraform bin that behaves as we expect it to.
2929
fakeBin := filepath.Join(cwd, "testdata", "timings-aggregation/fake-terraform.sh")
3030

31-
t.Logf(fakeBin)
31+
t.Log("%s", fakeBin)
3232

3333
ctx, api := setupProvisioner(t, &provisionerServeOptions{
3434
binaryPath: fakeBin,

provisionerd/proto/version.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import "github.com/coder/coder/v2/apiversion"
66
//
77
// API v1.2:
88
// - Add support for `open_in` parameters in the workspace apps.
9+
//
10+
// API v1.3:
11+
// - Add new field named `resources_monitoring` in the Agent with resources monitoring..
912
const (
1013
CurrentMajor = 1
11-
CurrentMinor = 2
14+
CurrentMinor = 3
1215
)
1316

1417
// CurrentVersion is the current provisionerd API version.

0 commit comments

Comments
 (0)