-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[elastic-agent] proxy requests to subprocesses to their metrics endpo…
- Loading branch information
1 parent
abc47e9
commit 61c621d
Showing
4 changed files
with
85 additions
and
17 deletions.
There are no files selected for viewing
This file contains 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 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
46 changes: 46 additions & 0 deletions
46
x-pack/elastic-agent/pkg/core/monitoring/server/process_linux_test.go
This file contains 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,46 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
//go:build linux | ||
// +build linux | ||
|
||
package server | ||
|
||
import ( | ||
"context" | ||
"net" | ||
"net/http" | ||
"net/http/httptest" | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestProcessProxyRequest(t *testing.T) { | ||
sock := "/tmp/elastic-agent-test.sock" | ||
defer os.Remove(sock) | ||
|
||
endpoint := "http+unix://" + sock | ||
server := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
// Write the path to the client so they can verify the request | ||
// was correct | ||
w.Write([]byte(r.URL.Path)) | ||
})) | ||
|
||
// Mimic subprocesses and listen on a unix socket | ||
l, err := net.Listen("unix", sock) | ||
require.NoError(t, err) | ||
server.Listener = l | ||
server.Start() | ||
defer server.Close() | ||
|
||
for _, path := range []string{"stats", "", "state"} { | ||
respBytes, _, err := processMetrics(context.Background(), endpoint, path) | ||
require.NoError(t, err) | ||
// Verify that the server saw the path we tried to request | ||
assert.Equal(t, "/"+path, string(respBytes)) | ||
} | ||
} |
This file contains 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