-
Notifications
You must be signed in to change notification settings - Fork 901
chore: add prometheus monitoring of workspace traffic generation #7583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f62cf16
add prometheus metrics endpoint to workspacetraffic command
johnstcn 00b9eca
use self-managed prometheus
johnstcn 9a9778c
plumb in prom properly
johnstcn f00b8d7
fix label on second pod monitor
johnstcn 69bc5ad
do not clobber existing prometheus
johnstcn 57d338d
remote_write all metrics
johnstcn a1d14df
add convenience script to create traffic inside cluster
johnstcn fb96c4d
fixup! add convenience script to create traffic inside cluster
johnstcn 59ef445
make fmt, make gen
johnstcn 6734521
Update scaletest/terraform/prometheus.tf
johnstcn 4ab2314
Merge remote-tracking branch 'origin/main' into cj/workspacetraffic-p…
johnstcn d54af33
address PR comments
johnstcn 8c48d2b
move test to workspacetraffic package
johnstcn cf00b5a
Merge remote-tracking branch 'origin/main' into cj/workspacetraffic-p…
johnstcn e6917e6
update golden files
johnstcn ea71c4f
separate prom address var
johnstcn 399e506
break out errors in to read/write
johnstcn ec96a00
ignore certain errors such as websocket closing or context cancellation
johnstcn a4ecd0c
test metrics more closely
johnstcn fe0ecfc
fixup! test metrics more closely
johnstcn 239ba96
add wait for prometheus metrics
johnstcn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
move test to workspacetraffic package
- Loading branch information
commit 8c48d2b4845abee661202cde656d909b4c516d1b
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,115 @@ | ||
package workspacetraffic_test | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/coder/coder/agent" | ||
"github.com/coder/coder/coderd/coderdtest" | ||
"github.com/coder/coder/codersdk" | ||
"github.com/coder/coder/codersdk/agentsdk" | ||
"github.com/coder/coder/provisioner/echo" | ||
"github.com/coder/coder/provisionersdk/proto" | ||
"github.com/coder/coder/scaletest/workspacetraffic" | ||
"github.com/coder/coder/testutil" | ||
|
||
"github.com/google/uuid" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestRun(t *testing.T) { | ||
t.Parallel() | ||
|
||
// We need to stand up an in-memory coderd and run a fake workspace. | ||
var ( | ||
client = coderdtest.New(t, &coderdtest.Options{IncludeProvisionerDaemon: true}) | ||
user = coderdtest.CreateFirstUser(t, client) | ||
authToken = uuid.NewString() | ||
agentName = "agent" | ||
version = coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{ | ||
Parse: echo.ParseComplete, | ||
ProvisionPlan: echo.ProvisionComplete, | ||
ProvisionApply: []*proto.Provision_Response{{ | ||
Type: &proto.Provision_Response_Complete{ | ||
Complete: &proto.Provision_Complete{ | ||
Resources: []*proto.Resource{{ | ||
Name: "example", | ||
Type: "aws_instance", | ||
Agents: []*proto.Agent{{ | ||
// Agent ID gets generated no matter what we say ¯\_(ツ)_/¯ | ||
Name: agentName, | ||
Auth: &proto.Agent_Token{ | ||
Token: authToken, | ||
}, | ||
Apps: []*proto.App{}, | ||
}}, | ||
}}, | ||
}, | ||
}, | ||
}}, | ||
}) | ||
template = coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID) | ||
_ = coderdtest.AwaitTemplateVersionJob(t, client, version.ID) | ||
// In order to be picked up as a scaletest workspace, the workspace must be named specifically | ||
ws = coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID, func(cwr *codersdk.CreateWorkspaceRequest) { | ||
cwr.Name = "scaletest-test" | ||
}) | ||
_ = coderdtest.AwaitWorkspaceBuildJob(t, client, ws.LatestBuild.ID) | ||
) | ||
|
||
// We also need a running agent to run this test. | ||
agentClient := agentsdk.New(client.URL) | ||
agentClient.SetSessionToken(authToken) | ||
agentCloser := agent.New(agent.Options{ | ||
Client: agentClient, | ||
}) | ||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium) | ||
|
||
t.Cleanup(cancel) | ||
t.Cleanup(func() { | ||
_ = agentCloser.Close() | ||
}) | ||
// Make sure the agent is connected before we go any further. | ||
resources := coderdtest.AwaitWorkspaceAgents(t, client, ws.ID) | ||
var agentID uuid.UUID | ||
for _, res := range resources { | ||
for _, agt := range res.Agents { | ||
agentID = agt.ID | ||
} | ||
} | ||
require.NotEqual(t, uuid.Nil, agentID, "did not expect agentID to be nil") | ||
|
||
// Now we can start the runner. | ||
reg := prometheus.NewRegistry() | ||
metrics := workspacetraffic.NewMetrics(reg, "username", "workspace_name", "agent_name") | ||
runner := workspacetraffic.NewRunner(client, workspacetraffic.Config{ | ||
AgentID: agentID, | ||
AgentName: agentName, | ||
WorkspaceName: ws.Name, | ||
WorkspaceOwner: ws.OwnerName, | ||
BytesPerTick: 1024, | ||
TickInterval: testutil.IntervalMedium, | ||
Duration: testutil.WaitMedium - time.Second, | ||
Registry: reg, | ||
}, metrics) | ||
|
||
var logs strings.Builder | ||
require.NoError(t, runner.Run(ctx, "", &logs), "unexpected error calling Run()") | ||
|
||
var collected []prometheus.Metric | ||
collectCh := make(chan prometheus.Metric) | ||
go func() { | ||
for metric := range collectCh { | ||
collected = append(collected, metric) | ||
} | ||
}() | ||
reg.Collect(collectCh) | ||
assert.NotEmpty(t, collected) | ||
for _, m := range collected { | ||
assert.NotZero(t, m.Desc()) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.