ApiPlatform/Doctrine - Unable to use Second Level Cache with error "Unable to use access strategy type of [3] without a ConcurrentRegion" - doctrine

My environment is:
api-platform: v3.0.0
symfony: 6.1.0
doctrine\cache: 2.2
doctrine\orm: 2.13.1
I am trying to set up a second level cache region with READ_WRITE access. Per specification READ_WRITE usage requires the use of a ConcurrentRegion due to the cache being locked as long as it is written or read.
I've created a cache pool to use on the second level cache:
### config/packages/cache.yaml
framework:
cache:
app: cache.adapter.redis
default_redis_provider: '%env(REDIS_URL)%'
pools:
doctrine.second_level_cache:
adapter: cache.adapter.redis
default_lifetime: 3600
The second level cache is configured as follows:
### config/packages/doctrine.yaml
doctrine:
orm:
second_level_cache:
enabled: true
region_cache_driver:
type: pool
pool: doctrine.second_level_cache # referenced in cache.yaml
regions:
locked_region:
cache_driver:
type: pool
pool: doctrine.second_level_cache # referenced in cache.yaml
lock_path: '%kernel.cache_dir%/doctrine/orm/lock'
I am using the default doctrine UserProvider loading the User-Entity upon authentication. In order to use the Cache-Region with the User-Entity the Cache-Attribute is added:
### App\Entity\User.php
use Doctrine\ORM\Mapping\Cache;
#[Cache("READ_WRITE", "locked_region")]
class User implements UserInterface, PasswordAuthenticatedUserInterface, EquatableInterface
{
Now upon login (executing a POST) an InvalidArgumentException is thrown in vendor/doctrine/orm/lib/Doctrine/ORM/Cache/DefaultCacheFactory.php (line 136) with the message Unable to use access strategy type of [3] without a ConcurrentRegion.
Doctrine is refusing to use the existing cache region because it expects a ConcurrentRegion (required on READ_WRITE) but receives a DefaultRegion. I am pretty sure my .yaml configuration is faulty...is the lock_path supposed to be a file-path - even when using Redis?
Thanks!

The fault lies in the configuration - the type property was missing.
This works:
### config/packages/doctrine.yaml
doctrine:
second_level_cache:
enabled: true
regions:
locked_region:
cache_driver:
type: pool
pool: doctrine.second_level_cache
type: filelock # <-- this one was missing
lock_path: '%kernel.cache_dir%/doctrine/orm/lock'

Related

Unknown processors type "resourcedetection" for "resourcedetection"

Running OT Collector with image ghcr.io/open-telemetry/opentelemetry-collector-releases/opentelemetry-collector:0.58.0
In config.yaml I have,
processors:
batch:
resourcedetection:
detectors: [ env ]
timeout: 2s
override: false
The collector is deployed as a sidecar but it keeps failing with
collector server run finished with error: failed to get config: cannot unmarshal the configuration: unknown processors type "resourcedetection" for "resourcedetection" (valid values: [resource span probabilistic_sampler filter batch memory_limiter attributes])
Any idea as to what is causing this? I haven't found any relevant documentation/question
The Resource Detection Processor is part of the otelcol-contrib distro upstream and you'd hence would need to use otel/opentelemetry-collector-contrib:0.58.0 (or the equivalent on your container registry of choice) for this processor to be available in your collector.

How to update loggingService of container.v1.cluster with deployment-manager

I want to set the loggingService field of an existing container.v1.cluster through deployment-manager.
I have the following config
resources:
- name: px-cluster-1
type: container.v1.cluster
properties:
zone: europe-west1-b
cluster:
description: "dev cluster"
initialClusterVersion: "1.13"
nodePools:
- name: cluster-pool
config:
machineType: "n1-standard-1"
oauthScopes:
- https://www.googleapis.com/auth/compute
- https://www.googleapis.com/auth/devstorage.read_only
- https://www.googleapis.com/auth/logging.write
- https://www.googleapis.com/auth/monitoring
management:
autoUpgrade: true
autoRepair: true
initialNodeCount: 1
autoscaling:
enabled: true
minNodeCount: 3
maxNodeCount: 10
ipAllocationPolicy:
useIpAliases: true
loggingService: "logging.googleapis.com/kubernetes"
masterAuthorizedNetworksConfig:
enabled: false
locations:
- "europe-west1-b"
- "europe-west1-c"
When I try to run gcloud deployment-manager deployments update ..., I get the following error
ERROR: (gcloud.deployment-manager.deployments.update) Error in Operation [operation-1582040492957-59edb819a5f3c-7155f798-5ba37285]: errors:
- code: NO_METHOD_TO_UPDATE_FIELD
message: No method found to update field 'cluster' on resource 'px-cluster-1' of
type 'container.v1.cluster'. The resource may need to be recreated with the new
field.
The same succeeds if I remove loggingService.
Is there a way to update loggingService using deployment-manager without deleting the cluster?
The error NO_METHOD_TO_UPDATE_FIELD is due to updating "initialClusterVersion" when you issued the update call to GKE. This field is only used on creation of the cluster, and the type definition doesn't currently allow for it to be updated later. So that should remain static at the original value and will have no effect on the deployment moving forward or try to delete/comment that line.
Even when the previous entry is true, there is also no method to update the logging service, actually Deployment Manager doesn't have many update methods, so, try using the gcloud command to update the cluster directly, keep in mind that you have to use the monitoring service together with the logging service, so, the commando would look like:
gcloud container clusters update px-cluster-1 --logging-service=logging.googleapis.com/kubernetes --monitoring-service=monitoring.googleapis.com/kubernetes --zone=europe-west1-b

Unable to find wrapper "gs" using Laravel in Google App Engine

I'm trying to deploy a Laravel 5.2 project to google app engine.
The deployment works but when I'm opening the application in the browser I get the following error:
PHP message: PHP Fatal error: Uncaught ErrorException: file_exists(): Unable to find the wrapper "gs" - did you forget to enable it when you configured PHP? in /srv/bootstrap/cache/compiled.php:13958
The app.yaml looks like this:
runtime: php72
handlers:
- url: /*
script: auto
secure: always
redirect_http_response_code: 301
automatic_scaling:
target_cpu_utilization: 0.65
min_instances: 1
max_instances: 1
min_pending_latency: 30ms
max_pending_latency: automatic
env_variables:
APP_ENV: local
APP_DEBUG: true
APP_KEY: my-key
APP_STORAGE: gs://my-bucket
CACHE_DRIVER: file
SESSION_DRIVER: file
QUEUE_DRIVER: sync
I configured my application to use a google storage bucket as my storage directory since the standard environment is a read only filesystem.
I added a php.ini file to the root of my project whith the following contents:
google_app_engine.allow_include_gs_buckets="#default#, my-bucket"
What can be the cause of this problem?

Configurable Replica Number in Template using ValueFrom

I have a template.yml file that is used when deploying to any OpenShift project. Each project has specific project-props configMap to be used, this is part of our CICD pipeline, so each project has a unique project.props available to it
I would like to be able to control the number of replicas and CPU/Memory limits based on what project I am deploying to. For example a branch testing OpenShift project vs Performance testing OpenShift project would have a different CPU request and limit than an ephemeral OpenShift project.
My template.yml file looks something like this:
// <snip>
spec:
replicas: "${OS_REPLICAS}"
// <snip>
resources:
limits:
cpu: "${OS_CPU_LIMIT}"
memory: "${OS_MEMORY_LIMIT}"
requests:
cpu: "${OS_CPU_REQUEST}"
memory: "${OS_MEMORY_REQUEST}"
// <snip>
parameters:
- name: OS_REPLICAS
displayName: OS Number of Replicas
valueFrom:
configMapKeyRef:
name: project-props
key: os.replicas
// rest of params are similar
My relevant project-props section is:
os.replicas=2
os.cpu.limit=2
os.cpu.request=250m
os.memory.limit=1Gi
os.memory.request=1Gi
When I try to deploy this I get the following error:
quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$'
If I change template.yml to have a parameter defined it works fine
parameters:
- name: OS_REPLICAS
displayName: OS Number of Replicas
value: 2
It seems that valueFrom vs value has a different behavior. Is this impossible to do using valueFrom? Is there another way I can dynamically change spec and resources using a configMap?
The alternative is to deploy and then use oc scale dc <deploy_config_name> --replicas=<number> but it's not very elegant.
Where you have:
spec:
replicas: "${OS_REPLICAS}"
you should have:
spec:
replicas: "${{OS_REPLICAS}}"
With template parameter of:
parameters:
- name: OS_REPLICAS
displayName: OS Number of Replicas
value: 2
See:
https://docs.openshift.org/latest/dev_guide/templates.html#writing-parameters
for use of "${{}}".
What it does is interpret the contents of the parameter as JSON/YAML, rather than a string value. This allows you to supply an integer, which replicas requires.
So you don't need valueFrom, which wouldn't work anyway as that is only usable for environment variables and not arbitrary fields like replicas.
As to trying to set a default for memory and CPU for pods deployed in a project, you should look at having a LimitRange resource defined against the project and set a default.
https://docs.openshift.com/container-platform/3.5/dev_guide/compute_resources.html#dev-limit-ranges
I figured out the answer, it's does not read the values from the file but at least they can be dynamic.
OpenShift has an oc process command that you can be run when using a template.
So this works by doing:
oc process -f <template_name>.yaml -v <param_name>=<param_value>
This will over write the parameter value with the one being inserted by -v.
An actual example would be
oc process -f ./src/main/openshift/service.template.yaml -v OS_REPLICAS=2
You can read more about it OpenShift template documentation
It seems that the OS Origin team does not want to support using files for parameter insertion. You can read more about it here:
https://github.com/openshift/origin/pull/10952
https://github.com/openshift/origin/issues/10687

APIConnect: Using $ref to reuse code fragments in your OpenAPI (Swagger 2.0) files

I'm using IBM's APIConnect to create a few APIs. I've been trying to edit my API's YAML definition to create references to properties so that I can externalize them. But so far, I'v been encountering problems with the referencing. They either do not validate against "API Connect swagger extensions schema API definition" or against "IBM Swagger Version 2.0 schema API definition".
Here are the two referencing I tried:-
Referencing securityDefinitions:
As described in the IBM website: https://www.ibm.com/support/knowledgecenter/en/SSMNED_5.0.0/com.ibm.apic.toolkit.doc/rapic_swagger_ref_fragment.html
my YAML:-
swagger: '2.0'
info:
version: 1.0.0
title: PokemonApp
x-ibm-name: pokemonapp
host: $(catalog.host)
basePath: /api
paths:
/pokemon:
get:
responses:
'200':
description: 200 OK
securityDefinitions:
$ref: ./schemas/ClientID.yaml
security:
- clientID: []
x-ibm-configuration:
assembly:
execute:
- invoke:
target-url: $(TestProperty)
properties:
TestProperty:
value: 'https://pokemons.mybluemix.net/api/pokemons'
description: ''
encoded: false
gateway: micro-gateway
And it's corresponding reference file:-
clientID:
description: ''
in: query
name: client_id
type: apiKey
On doing an apic validate on the parent YAML, I get the following error:-
C:\Users\MyName\TestNotes\definitions>apic validate pokemonapp_1.0.0.yaml
Successfully validated pokemonapp_1.0.0.yaml against Swagger Version 2.0 schema API definition [pokemonapp:1.0.0].
Successfully validated pokemonapp_1.0.0.yaml against API Connect swagger extensions schema API definition [pokemonapp:1.0.0].
Error validating pokemonapp_1.0.0.yaml with IBM Swagger Version 2.0 schema API definition [pokemonapp:1.0.0].
Data does not match any schemas from "oneOf" (/securityDefinitions/$ref)
Error: Validation did not complete successfully.
Referencing properties:-
Here's the parent YAML:-
swagger: '2.0'
info:
version: 1.0.0
title: PokemonApp
x-ibm-name: pokemonapp
host: $(catalog.host)
basePath: /api
paths:
/pokemon:
get:
responses:
'200':
description: 200 OK
securityDefinitions:
clientID:
description: ''
in: query
name: client_id
type: apiKey
security:
- clientID: []
x-ibm-configuration:
assembly:
execute:
- invoke:
target-url: $(TestProperty)
properties:
$ref: ./schemas/properties.yaml
gateway: micro-gateway
And the corresponding reference file (./schemas/properties.yaml):-
TestProperty:
type: object
value: 'https://pokemons.mybluemix.net/api/pokemons'
description: ''
encoded: false
On validating this, the error is a different one. This YAML validates against Swagger Version 2.0 schema API definition and against IBM Swagger Version 2.0 schema API definition, but not against API Connect swagger extensions schema API definition.
Here's the error message:-
C:\Users\MyName\TestNotes\definitions>apic validate pokemonapp_1.0.0.yaml
Successfully validated pokemonapp_1.0.0.yaml against Swagger Version 2.0 schema API definition [pokemonapp:1.0.0].
Error validating pokemonapp_1.0.0.yaml with API Connect swagger extensions schema API definition [pokemonapp:1.0.0].
Invalid type: string (expected object) (/properties/$ref)
Successfully validated pokemonapp_1.0.0.yaml against IBM Swagger Version 2.0 schema API definition [pokemonapp:1.0.0].
Error: Validation did not complete successfully.
Anu idea what I'm doing wrong here?
P.S. in both the cases, the swagger validates against 'Swagger Version 2.0 schema API definition'. It's only against the IBM specific schemas that they don't.
I was able to solve your issue using the latest CLI, APIConnect version and fixing an error in your properties.yaml file:
Version: apiconnect: v2.6.2 (API Connect: v5.0.7.0)
The first thing I had to change was to remove the additional type property in your properties.yaml file. I was receiving the following error with the properties.yaml file above:
Additional properties not allowed (/properties/TestProperty/type)
After removing the type property the file now has the following content:
TestProperty:
value: 'https://pokemons.mybluemix.net/api/pokemons'
description: ''
encoded: false
I then used the validation tool provided by the apic CLI to make sure the configuration was completely valid:
macbook-pro-92:Test Algebra$ apic validate Test.yaml
Successfully validated Test.yaml against Swagger Version 2.0 schema API definition [pokemonapp:1.0.0].
Successfully validated Test.yaml against API Connect swagger extensions schema API definition [pokemonapp:1.0.0].
Successfully validated Test.yaml against IBM Swagger Version 2.0 schema API definition [pokemonapp:1.0.0].
So in order to solve your issue, I would recommend updating your APIConnect version and CLI and then remove the type property from your properties.yaml file. You should then be able to validate the configuration successfully.
For any version 5060 or later, the use of $ref won't work. There is a problem report filed against this already. Wait for a future release to use it.

Resources