Skip to content

Commit

Permalink
Merge branch 'main' into fix-set-pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
bonzofenix authored Aug 21, 2024
2 parents ae1ec55 + c842efd commit 4f3bc59
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ci/autoscaler/scripts/cleanup-autoscaler.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ function main() {
bosh_login
cf_login

cleanup_apps
cleanup_acceptance_run
cleanup_service_broker
cleanup_bosh_deployment
delete_releases
cleanup_credhub
cleanup_apps
}

[ "${BASH_SOURCE[0]}" == "${0}" ] && main "$@"
14 changes: 13 additions & 1 deletion ci/autoscaler/scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,20 @@ function cleanup_credhub(){
}

function cleanup_apps(){
step "cleaning up apps"
local mtar_app
local space_guid

cf_target "${autoscaler_org}" "${autoscaler_space}"
cf undeploy com.github.cloudfoundry.app-autoscaler-release -f

space_guid="$(cf space --guid "${autoscaler_space}")"
mtar_app="$(curl --header "Authorization: $(cf oauth-token)" "deploy-service.${system_domain}/api/v2/spaces/${space_guid}/mtas" | jq ". | .[] | .metadata | .id" -r)"

if [ -n "${mtar_app}" ]; then
cf undeploy "${mtar_app}" -f
else
echo "No app to undeploy"
fi

if ! cf spaces | grep --quiet --regexp="^${AUTOSCALER_SPACE}$"; then
cf delete-space -f "${AUTOSCALER_SPACE}"
Expand Down
3 changes: 3 additions & 0 deletions src/autoscaler/metricsforwarder/manager/policyManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ func (pm *PolicyManager) RefreshAllowedMetricCache(policies map[string]*models.A
pm.logger.Error("Error updating allowedMetricCache", err)
return err
}
} else {
//If the policy is not present in the cache, remove the entry from the cache
pm.allowedMetricCache.Delete(applicationId)
}
}
return nil
Expand Down
49 changes: 34 additions & 15 deletions src/autoscaler/metricsforwarder/manager/policyManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ var _ = Describe("PolicyManager", func() {
policyManager.Stop()
})

Context("when allowedMetricCache has already filled with metricstype details of the same appilication", func() {
When("allowedMetricCache has already filled with metricstype details of the same appilication", func() {

BeforeEach(func() {
scalingPolicy = &models.ScalingPolicy{
Expand All @@ -114,22 +114,41 @@ var _ = Describe("PolicyManager", func() {
Expect(found).To(BeTrue())
Expect(maps).Should(HaveKey("queuelength"))

database.RetrievePoliciesStub = func() ([]*models.PolicyJson, error) {
return []*models.PolicyJson{{AppId: testAppId, PolicyStr: policyStr}}, nil
}

})
It("should be able refresh allowed metrics cache", func() {
Eventually(database.RetrievePoliciesCallCount).Should(Equal(1))
clock.Increment(1 * testPolicyPollerInterval)
Eventually(database.RetrievePoliciesCallCount).Should(Equal(2))

res, found := allowedMetricCache.Get(testAppId)
maps := res.(map[string]struct{})

Expect(found).To(BeTrue())
Expect(maps).Should(HaveKey("test-metric-name"))
Expect(maps).ShouldNot(HaveKey("queuelength"))
When("the policy is updated", func() {
BeforeEach(func() {
database.RetrievePoliciesStub = func() ([]*models.PolicyJson, error) {
return []*models.PolicyJson{{AppId: testAppId, PolicyStr: policyStr}}, nil
}
})
It("should refresh the allowed metrics cache", func() {
Eventually(database.RetrievePoliciesCallCount).Should(Equal(1))
clock.Increment(1 * testPolicyPollerInterval)
Eventually(database.RetrievePoliciesCallCount).Should(Equal(2))

res, found := allowedMetricCache.Get(testAppId)
maps := res.(map[string]struct{})

Expect(found).To(BeTrue())
Expect(maps).Should(HaveKey("test-metric-name"))
Expect(maps).ShouldNot(HaveKey("queuelength"))
})
})
When("the policy is deleted", func() {
BeforeEach(func() {
database.RetrievePoliciesStub = func() ([]*models.PolicyJson, error) {
return []*models.PolicyJson{}, nil
}
})
It("should refresh the allowed metrics cache", func() {
Eventually(database.RetrievePoliciesCallCount).Should(Equal(1))
clock.Increment(1 * testPolicyPollerInterval)
Eventually(database.RetrievePoliciesCallCount).Should(Equal(2))

_, found := allowedMetricCache.Get(testAppId)
Expect(found).To(BeFalse())
})
})
})
})
Expand Down

0 comments on commit 4f3bc59

Please sign in to comment.