-
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
3adaa1e
commit 5125fb6
Showing
16 changed files
with
923 additions
and
427 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
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) | ||
} | ||
}) | ||
} |
Oops, something went wrong.