-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4fdf6a9
commit 32ea276
Showing
10 changed files
with
66 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
package fas | ||
|
||
import "context" | ||
import ( | ||
"context" | ||
"os" | ||
) | ||
|
||
// MetricCollector represents a client for collecting metrics from an external source. | ||
type MetricCollector interface { | ||
Name() string | ||
CollectMetric(ctx context.Context) (float64, error) | ||
CollectMetric(ctx context.Context, app string) (float64, error) | ||
} | ||
|
||
// ExpandMetricQuery replaces variables in query with their values. | ||
func ExpandMetricQuery(ctx context.Context, query, app string) string { | ||
return os.Expand(query, func(key string) string { | ||
switch key { | ||
case "APP_NAME": | ||
return app | ||
default: | ||
return "" | ||
} | ||
}) | ||
} |
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,31 @@ | ||
package fas_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
fas "github.com/superfly/fly-autoscaler" | ||
) | ||
|
||
func TestExpandMetricQuery(t *testing.T) { | ||
t.Run("Static", func(t *testing.T) { | ||
result := fas.ExpandMetricQuery(context.Background(), "foo", "my-app") | ||
if got, want := result, `foo`; got != want { | ||
t.Fatalf("got %q, want %q", got, want) | ||
} | ||
}) | ||
|
||
t.Run("Bare", func(t *testing.T) { | ||
result := fas.ExpandMetricQuery(context.Background(), "foo $APP_NAME bar", "my-app") | ||
if got, want := result, `foo my-app bar`; got != want { | ||
t.Fatalf("got %q, want %q", got, want) | ||
} | ||
}) | ||
|
||
t.Run("Wrapped", func(t *testing.T) { | ||
result := fas.ExpandMetricQuery(context.Background(), "foo${APP_NAME}bar", "my-app") | ||
if got, want := result, `foomy-appbar`; got != want { | ||
t.Fatalf("got %q, want %q", got, want) | ||
} | ||
}) | ||
} |
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
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