Cloud Cost Fitness
A library to express and test your cloud costs as architecture fitness functions.
Usage
Dependency Definition
If you are using Gradle as a build tool the following dependency needs to be added to your project dependencies.
testImplementation 'de.qaware.cloud.cost:cloud-cost-fitness-api:1.0.0'
testRuntimeOnly 'de.qaware.cloud.cost:cloud-cost-fitness-aws:1.0.0'
If you are using Maven as a build tool the following dependency needs to be added to your project dependencies.
<dependency>
<groupId>de.qaware.cloud.cost</groupId>
<artifactId>cloud-cost-fitness-api</artifactId>
<version>1.0.0</version>
<type>test</type>
</dependency>
<dependency>
<groupId>de.qaware.cloud.cost</groupId>
<artifactId>cloud-cost-fitness-aws</artifactId>
<version>1.0.0</version>
<type>test</type>
</dependency>
Cloud Cost Fitness Tests using Spock
The Cloud Cost Fitness library can be used nicely in combination with the Spock Framework. Simply define a test specification, create a cost explorer for the desired cloud provider and implement a dedicated test for each cloud cost fitness function.
@Requires({ sys['aws.access.key'] && sys['aws.secret.key'] })
class CloudCostFitnessSpec extends Specification {
@Shared
CostExplorer costExplorer = CloudProvider.AMAZON_AWS.getCostExplorer()
def "checks the total costs"() {
expect: "the total costs to be less than a limit"
costExplorer.during(YESTERDAY).getCosts().sum().lessThan(100.0)
}
@Unroll
def "check the costs of EC2 instance #service"() {
expect: "the cost is less than the limit"
costExplorer.during(LAST_7_DAYS).forService(service).getCosts().sum().lessThan(250.0)
where:
service << costExplorer.forService("Amazon Elastic *").getNames()
}
}
For the complete example have a look at CloudCostFitnessSpec.groovy
found under src/test/groovy/
.
Cloud Cost Fitness Tests using JUnit 5
The Cloud Cost Fitness library can also be used nicely in combination with JUnit 5. Simply define a test class, create a cost explorer for the desired cloud provider and implement a dedicated test for each cloud cost fitness function.
@EnabledIfSystemProperty(named = "aws.access.key", matches = ".*")
@EnabledIfSystemProperty(named = "aws.secret.key", matches = ".*")
class CloudCostFitnessTest {
private static CostExplorer costExplorer;
@BeforeAll
static void setUpAll() {
costExplorer = CloudProvider.AMAZON_AWS.getCostExplorer();
}
@Test
void checkTheTotalCosts() {
ValueWithUnit sum = costExplorer.during(YESTERDAY).getCosts().sum();
assertTrue(sum.lessThan(42.0));
}
@ParameterizedTest
@MethodSource("serviceNameFactory")
void checkTheCostsOfElasticComputeInstance(String service) {
ValueWithUnit sum = costExplorer.during(LAST_7_DAYS).forService(service).getCosts().sum();
assertTrue(sum.lessThan(250.0));
}
static List<String> serviceNameFactory() {
return costExplorer.forService("Amazon Elastic *").getNames();
}
}
For the complete example have a look at CloudCostFitnessTest.java
found under src/test/java/
.
Maintainer
- Tobias Melson (@tmelson), [email protected]
- M.-Leander Reimer (@lreimer), [email protected]
License
This software is provided under the Apache v2 open source license, read the LICENSE
file for details.