MCPcopy Index your code
hub / github.com/coder/coder / New

Function New

coderd/agentapi/api.go:108–252  ·  view source on GitHub ↗
(opts Options, workspace database.Workspace, agent database.WorkspaceAgent)

Source from the content-addressed store, hash-verified

106}
107
108func New(opts Options, workspace database.Workspace, agent database.WorkspaceAgent) *API {
109 if opts.Clock == nil {
110 opts.Clock = quartz.NewReal()
111 }
112
113 api := &API{
114 opts: opts,
115 mu: sync.Mutex{},
116 }
117
118 api.ManifestAPI = &ManifestAPI{
119 AccessURL: opts.AccessURL,
120 AppHostname: opts.AppHostname,
121 ExternalAuthConfigs: opts.ExternalAuthConfigs,
122 DisableDirectConnections: opts.DisableDirectConnections,
123 DerpForceWebSockets: opts.DerpForceWebSockets,
124 AgentFn: api.agent,
125 Database: opts.Database,
126 DerpMapFn: opts.DerpMapFn,
127 WorkspaceID: opts.WorkspaceID,
128 }
129
130 // Don't cache details for prebuilds, though the cached fields will eventually be updated
131 // by the refresh routine once the prebuild workspace is claimed.
132 api.cachedWorkspaceFields = &CachedWorkspaceFields{}
133 if !workspace.IsPrebuild() {
134 api.cachedWorkspaceFields.UpdateValues(workspace)
135 }
136
137 api.AnnouncementBannerAPI = &AnnouncementBannerAPI{
138 appearanceFetcher: opts.AppearanceFetcher,
139 }
140
141 api.ResourcesMonitoringAPI = &ResourcesMonitoringAPI{
142 AgentID: opts.AgentID,
143 WorkspaceID: opts.WorkspaceID,
144 Clock: opts.Clock,
145 Database: opts.Database,
146 NotificationsEnqueuer: opts.NotificationsEnqueuer,
147 Debounce: 30 * time.Minute,
148
149 Config: resourcesmonitor.Config{
150 NumDatapoints: 20,
151 CollectionInterval: 10 * time.Second,
152
153 Alert: resourcesmonitor.AlertConfig{
154 MinimumNOKsPercent: 20,
155 ConsecutiveNOKsPercent: 50,
156 },
157 },
158 }
159
160 api.StatsAPI = &StatsAPI{
161 AgentID: agent.ID,
162 AgentName: agent.Name,
163 Workspace: api.cachedWorkspaceFields,
164 Database: opts.Database,
165 Log: opts.Log,

Callers 1

workspaceAgentRPCMethod · 0.92

Calls 3

startCacheRefreshLoopMethod · 0.95
UpdateValuesMethod · 0.80
IsPrebuildMethod · 0.65

Tested by

no test coverage detected