forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(controller): Enable dummy metrics server on non-leader workflow c…
…ontroller (argoproj#11295) Signed-off-by: sakai <sakai.at24@gmail.com> Signed-off-by: Dillen Padhiar <dillen_padhiar@intuit.com>
- Loading branch information
Showing
4 changed files
with
123 additions
and
13 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package metrics | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestDisableMetricsServer(t *testing.T) { | ||
config := ServerConfig{ | ||
Enabled: false, | ||
Path: DefaultMetricsServerPath, | ||
Port: DefaultMetricsServerPort, | ||
} | ||
m := New(config, config) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
m.RunServer(ctx, false) | ||
time.Sleep(1 * time.Second) // to confirm that the server doesn't start, even if we wait | ||
resp, err := http.Get(fmt.Sprintf("http://localhost:%d%s", DefaultMetricsServerPort, DefaultMetricsServerPath)) | ||
if resp != nil { | ||
defer resp.Body.Close() | ||
} | ||
|
||
assert.Error(t, err) | ||
assert.Contains(t, err.Error(), "connection refused") // expect that the metrics server not to start | ||
} | ||
|
||
func TestMetricsServer(t *testing.T) { | ||
config := ServerConfig{ | ||
Enabled: true, | ||
Path: DefaultMetricsServerPath, | ||
Port: DefaultMetricsServerPort, | ||
} | ||
m := New(config, config) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
m.RunServer(ctx, false) | ||
time.Sleep(1 * time.Second) | ||
resp, err := http.Get(fmt.Sprintf("http://localhost:%d%s", DefaultMetricsServerPort, DefaultMetricsServerPath)) | ||
assert.NoError(t, err) | ||
assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
|
||
defer resp.Body.Close() | ||
|
||
bodyBytes, err := io.ReadAll(resp.Body) | ||
assert.NoError(t, err) | ||
|
||
bodyString := string(bodyBytes) | ||
assert.NotEmpty(t, bodyString) | ||
} | ||
|
||
func TestDummyMetricsServer(t *testing.T) { | ||
config := ServerConfig{ | ||
Enabled: true, | ||
Path: DefaultMetricsServerPath, | ||
Port: DefaultMetricsServerPort, | ||
} | ||
m := New(config, config) | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
m.RunServer(ctx, true) | ||
time.Sleep(1 * time.Second) | ||
resp, err := http.Get(fmt.Sprintf("http://localhost:%d%s", DefaultMetricsServerPort, DefaultMetricsServerPath)) | ||
assert.NoError(t, err) | ||
assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
|
||
defer resp.Body.Close() | ||
|
||
bodyBytes, err := io.ReadAll(resp.Body) | ||
assert.NoError(t, err) | ||
|
||
bodyString := string(bodyBytes) | ||
|
||
assert.Empty(t, bodyString) // expect the dummy metrics server to provide no metrics responses | ||
} |