Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,12 @@ bosh-release: build/autoscaler-test.tgz_CI_true
# already there for `go-mod-tidy` to work. See additional comment for that target in
# ./src/autoscaler/Makefile.
build/autoscaler-test.tgz: build_all go-mod-tidy go-mod-vendor
@echo " - creating bosh release into build/autoscaler-test.tgz"; \
@bosh create-release --force --timestamp-version --tarball=build/autoscaler-test.tgz; \
@echo ' - creating bosh release into build/autoscaler-test.tgz'
@bosh create-release --force --timestamp-version --tarball='build/autoscaler-test.tgz'

build/autoscaler-test.tgz_CI_true: go-mod-tidy go-mod-vendor
@echo " - creating bosh release into ${AUTOSCALER_BOSH_TARBALL_PATH}"
@bosh create-release ${AUTOSCALER_BOSH_BUILD_OPTS} --version ${AUTOSCALER_BOSH_VERSION} --tarball=${AUTOSCALER_BOSH_TARBALL_PATH}
@echo ' - creating bosh release into ${AUTOSCALER_BOSH_TARBALL_PATH}'
@bosh create-release ${AUTOSCALER_BOSH_BUILD_OPTS} --version='${AUTOSCALER_BOSH_VERSION}' --tarball='${AUTOSCALER_BOSH_TARBALL_PATH}'

.PHONY: generate-fakes autoscaler.generate-fakes test-app.generate-fakes
generate-fakes: autoscaler.generate-fakes test-app.generate-fakes
Expand Down
648 changes: 324 additions & 324 deletions devbox.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion jobs/golangapiserver/templates/apiserver.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ broker_credentials:
catalog_path: /var/vcap/jobs/golangapiserver/config/catalog.json
catalog_schema_path: /var/vcap/packages/golangapiserver/catalog.schema.json
info_file_path: /var/vcap/jobs/golangapiserver/config/info.json
policy_schema_path: /var/vcap/packages/golangapiserver/policy_json.schema.json
policy_schema_path: /var/vcap/packages/golangapiserver/scaling-policy.schema.json
dashboard_redirect_uri: <%= p("autoscaler.apiserver.broker.server.dashboard_redirect_uri") %>
default_credential_type: <%= p("autoscaler.apiserver.broker.default_credential_type") %>

Expand Down
6 changes: 3 additions & 3 deletions nix/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 9 additions & 12 deletions packages/golangapiserver/packaging
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
set -e -x

export GOROOT=$(readlink -nf /var/vcap/packages/golang-1-linux)
export PATH=$GOROOT/bin:$PATH
export GOPATH=${BOSH_COMPILE_TARGET}
export GOROOT=$(readlink --no-newline --canonicalize /var/vcap/packages/golang-1-linux)
export PATH="${GOROOT}/bin:${PATH}"
export GOPATH="${BOSH_COMPILE_TARGET}"
export GOCACHE=/tmp/gocache

pushd ${BOSH_COMPILE_TARGET}/autoscaler
pushd "${BOSH_COMPILE_TARGET}/autoscaler"
GOPROXY=off make build-api
popd

cp -a ${BOSH_COMPILE_TARGET}/autoscaler/build/api ${BOSH_INSTALL_TARGET}
cp -a ${BOSH_COMPILE_TARGET}/autoscaler/api/db/api.db.changelog.yml ${BOSH_INSTALL_TARGET}
cp -a ${BOSH_COMPILE_TARGET}/autoscaler/api/db/servicebroker.db.changelog.yaml ${BOSH_INSTALL_TARGET}

cp -a ${BOSH_COMPILE_TARGET}/autoscaler/api/policyvalidator/policy_json.schema.json ${BOSH_INSTALL_TARGET}
cp -a ${BOSH_COMPILE_TARGET}/autoscaler/api/schemas/catalog.schema.json ${BOSH_INSTALL_TARGET}


cp --archive "${BOSH_COMPILE_TARGET}/autoscaler/build/api" "${BOSH_INSTALL_TARGET}"
cp --archive "${BOSH_COMPILE_TARGET}/autoscaler/api/db/api.db.changelog.yml" "${BOSH_INSTALL_TARGET}"
cp --archive "${BOSH_COMPILE_TARGET}/autoscaler/api/db/servicebroker.db.changelog.yaml" "${BOSH_INSTALL_TARGET}"

cp --archive "${BOSH_COMPILE_TARGET}"/autoscaler/api/policyvalidator/*.json "${BOSH_INSTALL_TARGET}"
cp --archive "${BOSH_COMPILE_TARGET}/autoscaler/api/schemas/catalog.schema.json" "${BOSH_INSTALL_TARGET}"
2 changes: 1 addition & 1 deletion schema/api/policy-api.openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ components:
type: string
example: Asia/Shanghai
# TODO: Try to make use of <https://stackoverflow.com/a/71121905>
#- $ref: "../../src/autoscaler/api/policyvalidator/policy_json.schema.json#/" # TODO:
#- $ref: "../../src/autoscaler/schema/api/policyvalidator/policy_json.schema.json#/" # TODO:
recurring_schedule:
type: array
items:
Expand Down
7 changes: 7 additions & 0 deletions schema/json/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Read-me #

The currently used golang-library for json-schema, namely “[gojsonschema](<https://github.com/xeipuuv/gojsonschema>)” not seems to be capable to resolve references to other files correctly across different directories. Perhaps not limited to but especially when referencing up the file-system-hierarchy (parent-directories). In theory, symbolic links can be used to circumvent the issue … if there would not be another weakness in <https://github.com/cloudfoundry/bosh-compile-action> which we currently use in the workflow [bosh-release-checks.yaml](<../../../../.github/workflows/bosh-release-checks.yaml>) for making a compiled release: It can not handle symbolic links. Therefore it gets hard-linked here (which can not be tracked by git but it can somehow handle it!).

After phasing out the bosh-technology of “Application Autoscaler”, these hardlinks can be removed.

⚠️ This means the consinstence needs to be ensured manually. There is no CI/CD-check because Bosh is already in its phase-out for “Application Autoscaler”.
40 changes: 40 additions & 0 deletions schema/json/policy-configuration.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "http://json-schema.org/draft-05/schema#",
"title": "Autoscaler Scaling Policy Configuration Schema",
"description": "Schema for the configuration options of scaling policy.",
"type": "object",

"properties": {
"custom_metrics": {
"type": "object",
"properties": {
"metric_submission_strategy": {
"type": "object",
"properties": {
"allow_from": {
"type": "string",
"enum": [
"bound_app",
"same_app"
]
}
},
"required": [
"allow_from"
]
}
},
"required": [
"metric_submission_strategy"
],
"additionalProperties": false
},
"app_guid": {
"$ref": "./shared_definitions.json#/schemas/guid"
}
},
"required": [
"custom_metrics"
],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
@@ -1,51 +1,24 @@
{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"$schema": "http://json-schema.org/draft-05/schema#",
"title": "Autoscaler Policy JSON Schema",
"required": [
"instance_min_count",
"instance_max_count"
],
"anyOf": [
{
"required": [
"scaling_rules"
]
"description": "Schema for scaling-policies for Autoscaler",
"type": "object",

"properties": {
"schema-version": {
"description": "Version-identifier for the used schema of this parameters-object.",
"type": "string",
"pattern": "^[0-9]+(\\.[0-9]+)?$"
},
{
"required": [
"schedules"
"credential-type": {
"type": "string",
"enum": [
"x509",
"binding-secret"
]
}
],
"properties": {
},
"configuration": {
"type": "object",
"properties": {
"custom_metrics": {
"type": "object",
"properties": {
"metric_submission_strategy": {
"type": "object",
"properties": {
"allow_from": {
"type": "string",
"enum": [
"bound_app"
]
}
},
"required": [
"allow_from"
]
}
},
"required": [
"metric_submission_strategy"
]
}
}
"$ref": "./policy-configuration.schema.json"
},
"instance_min_count": {
"$id": "#/properties/instance_min_count",
Expand Down Expand Up @@ -88,6 +61,13 @@
"maximum": 3600,
"minimum": 60
},
"stats_window_secs": {
"$id": "#/properties/scaling_rules/items/properties/stats_window_secs",
"type": "integer",
"deprecated": true,
"title": "The stats_window_secs schema",
"description": "This is a legacy-parameter. 🏚️ It is silently ignored."
},
"threshold": {
"$id": "#/properties/scaling_rules/items/properties/threshold",
"type": "integer",
Expand Down Expand Up @@ -928,5 +908,23 @@
}
}
}
}
},

"required": [
"instance_min_count",
"instance_max_count"
],
"anyOf": [
{
"required": [
"scaling_rules"
]
},
{
"required": [
"schedules"
]
}
],
"additionalProperties": true
}
10 changes: 10 additions & 0 deletions schema/json/shared_definitions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"schemas": {
"guid": {
"type": "string",
"description": "Unique identificator for a CF-resource, e.g. app, space, service-binding, …",
"pattern": "(\\d|[a-f]){8}-(\\d|[a-f]){4}-(\\d|[a-f]){4}-(\\d|[a-f]){4}-(\\d|[a-f]){12}",
"example": "8d0cee08-23ad-4813-a779-ad8118ea0b91"
}
}
}
6 changes: 3 additions & 3 deletions src/acceptance/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,13 @@ var _ = Describe("AutoScaler Public API", func() {
It("should fail to create an invalid custom metrics submission", func() {
By("creating custom metrics submission with invalid string")
response, status := createPolicy(GenerateBindingsWithScalingPolicy("invalid-value", 1, 2, "memoryused", 30, 100))
Expect(string(response)).Should(MatchJSON(`[{"context":"(root).configuration.custom_metrics.metric_submission_strategy.allow_from","description":"configuration.custom_metrics.metric_submission_strategy.allow_from must be one of the following: \"bound_app\""}]`))
Expect(string(response)).Should(MatchJSON(`[{"context":"(root).configuration.custom_metrics.metric_submission_strategy.allow_from","description":"configuration.custom_metrics.metric_submission_strategy.allow_from must be one of the following: \"bound_app\", \"same_app\""}]`))
Expect(status).To(Equal(400))

By("creating custom metrics submission with empty value ' '")
policy := GenerateBindingsWithScalingPolicy("", 1, 2, "memoryused", 30, 100)
newPolicy, status := createPolicy(policy)
Expect(string(newPolicy)).Should(MatchJSON(`[{"context":"(root).configuration.custom_metrics.metric_submission_strategy.allow_from","description":"configuration.custom_metrics.metric_submission_strategy.allow_from must be one of the following: \"bound_app\""}]`))
Expect(string(newPolicy)).Should(MatchJSON(`[{"context":"(root).configuration.custom_metrics.metric_submission_strategy.allow_from","description":"configuration.custom_metrics.metric_submission_strategy.allow_from must be one of the following: \"bound_app\", \"same_app\""}]`))
Expect(status).To(Equal(400))
})

Expand Down Expand Up @@ -277,7 +277,7 @@ var _ = Describe("AutoScaler Public API", func() {
It("should fail to update an invalid custom metrics strategy", func() {
expectedPolicy = GenerateBindingsWithScalingPolicy("invalid-update", 1, 2, "memoryused", 30, 100)
actualPolicy, status = createPolicy(expectedPolicy)
Expect(string(actualPolicy)).Should(MatchJSON(`[{"context":"(root).configuration.custom_metrics.metric_submission_strategy.allow_from","description":"configuration.custom_metrics.metric_submission_strategy.allow_from must be one of the following: \"bound_app\""}]`))
Expect(string(actualPolicy)).Should(MatchJSON(`[{"context":"(root).configuration.custom_metrics.metric_submission_strategy.allow_from","description":"configuration.custom_metrics.metric_submission_strategy.allow_from must be one of the following: \"bound_app\", \"same_app\""}]`))
Expect(status).To(Equal(400))
})
It("should succeed to update a valid custom metrics strategy", func() {
Expand Down
2 changes: 1 addition & 1 deletion src/autoscaler/api/broker/broker_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var _ = BeforeSuite(func() {
conf = &config.Config{
CatalogPath: "../exampleconfig/catalog-example.json",
DashboardRedirectURI: dashBoardURL,
PolicySchemaPath: "../policyvalidator/policy_json.schema.json",
PolicySchemaPath: "../policyvalidator/scaling-policy.schema.json",
DefaultCustomMetricsCredentialType: "binding-secret",
}

Expand Down
7 changes: 4 additions & 3 deletions src/autoscaler/api/brokerserver/broker_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ var _ = Describe("BrokerHandler", func() {
"configuration": {
"custom_metrics": {
"metric_submission_strategy": {
"allow_from": "same_app"
"allow_from": "different_app"
}
}
},
Expand Down Expand Up @@ -995,7 +995,7 @@ var _ = Describe("BrokerHandler", func() {
verifyScheduleIsUpdatedInScheduler(testAppId, bindingPolicy)
})
It("should fail with 400", func() {
Expect(resp.Body.String()).To(ContainSubstring("{\"description\":\"invalid policy provided: [{\\\"context\\\":\\\"(root).configuration.custom_metrics.metric_submission_strategy.allow_from\\\",\\\"description\\\":\\\"configuration.custom_metrics.metric_submission_strategy.allow_from must be one of the following: \\\\\\\"bound_app\\\\\\\"\\\"}]\"}"))
Expect(resp.Body.String()).To(ContainSubstring("{\"description\":\"invalid policy provided: [{\\\"context\\\":\\\"(root).configuration.custom_metrics.metric_submission_strategy.allow_from\\\",\\\"description\\\":\\\"configuration.custom_metrics.metric_submission_strategy.allow_from must be one of the following: \\\\\\\"bound_app\\\\\\\", \\\\\\\"same_app\\\\\\\"\\\"}]\"}"))
Expect(resp.Code).To(Equal(http.StatusBadRequest))
})
})
Expand Down Expand Up @@ -1196,8 +1196,9 @@ var _ = Describe("BrokerHandler", func() {
})
It("fails with 400", func() {
Expect(resp.Code).To(Equal(http.StatusBadRequest))
Expect(resp.Body.String()).To(MatchJSON(`{"error": "validate-credential-type","description": "invalid credential type provided: allowed values are [binding-secret, x509]"}`))
Expect(resp.Body.String()).To(MatchJSON(`{"description": "invalid policy provided: [{\"context\":\"(root).credential-type\",\"description\":\"credential-type must be one of the following: \\\"x509\\\", \\\"binding-secret\\\"\"}]"}`))
})

})
Context("credential-type is set to binding-secret", func() {
const testBindingPolicy = `{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var _ = BeforeSuite(func() {
},
CatalogPath: "../exampleconfig/catalog-example.json",
CatalogSchemaPath: "../schemas/catalog.schema.json",
PolicySchemaPath: "../policyvalidator/policy_json.schema.json",
PolicySchemaPath: "../policyvalidator/scaling-policy.schema.json",
Scheduler: config.SchedulerConfig{
SchedulerURL: schedulerServer.URL(),
},
Expand Down
2 changes: 1 addition & 1 deletion src/autoscaler/api/cmd/api/api_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ var _ = SynchronizedBeforeSuite(func() []byte {

conf.CatalogPath = "../../exampleconfig/catalog-example.json"
conf.CatalogSchemaPath = "../../schemas/catalog.schema.json"
conf.PolicySchemaPath = "../../policyvalidator/policy_json.schema.json"
conf.PolicySchemaPath = "../policyvalidator/scaling-policy.schema.json"

schedulerServer = ghttp.NewServer()
conf.Scheduler.SchedulerURL = schedulerServer.URL()
Expand Down
2 changes: 1 addition & 1 deletion src/autoscaler/api/default_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"catalog_schema_path": "/home/vcap/app/api/schemas/catalog.schema.json",
"info_file_path": "/home/vcap/app/api/default_info.json",
"policy_schema_path": "/home/vcap/app/api/policyvalidator/policy_json.schema.json",
"policy_schema_path": "/home/vcap/app/api/policyvalidator/scaling-policy.schema.json",
"dashboard_redirect_uri": null,
"default_credential_type": "binding-secret",
"health": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"$schema": "http://json-schema.org/draft-05/schema#",
"title": "Autoscaler Scaling Policy Configuration Schema",
"description": "Schema for the configuration options of scaling policy.",
"type": "object",

"properties": {
"custom_metrics": {
"type": "object",
"properties": {
"metric_submission_strategy": {
"type": "object",
"properties": {
"allow_from": {
"type": "string",
"enum": [
"bound_app",
"same_app"
]
}
},
"required": [
"allow_from"
]
}
},
"required": [
"metric_submission_strategy"
],
"additionalProperties": false
},
"app_guid": {
"$ref": "./shared_definitions.json#/schemas/guid"
}
},
"required": [
"custom_metrics"
],
"additionalProperties": false
}
Loading
Loading