Skip to content

Commit

Permalink
Refactor StateManager to use the new client. (dapr#101)
Browse files Browse the repository at this point in the history
* Deprecate old state manager

* Try to safely replace the old statemanager

* Update tests

* Move transactional state

* Update transaction tests

* If no etag, then bail

* Use latest rc

* Update to use new client in integration tests

* address runtime issues

* decode results

* Deletect failures better

* Handle cases when it is not a string

* Ensure we use default value

* Make the tests more better

* Test more versions of dapr
  • Loading branch information
withinboredom authored Jul 17, 2021
1 parent f87e3d3 commit 5e2e0b4
Show file tree
Hide file tree
Showing 19 changed files with 1,229 additions and 665 deletions.
72 changes: 71 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,88 @@ jobs:

- name: Run test suite
run: composer run-script lint
build-integration-test-containers:
runs-on: ubuntu-latest
strategy:
matrix:
image: [ 'caddy', 'tests' ]
include:
- image: caddy
dockerfile: images/caddy.Dockerfile
target: base
- image: tests
dockerfile: images/tests.Dockerfile
target: production
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master
with:
install: true
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.${{ matrix.image }}-cache
key: ${{ runner.os }}-${{ matrix.image }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-${{ matrix.image }}-
- uses: shivammathur/[email protected]
with:
php-version: 8.0
- name: Validate composer.json and composer.lock
run: composer validate
- name: Build and push
uses: docker/build-push-action@v2
with:
context: ./
file: ${{ matrix.dockerfile }}
push: false
pull: true
outputs: type=docker,dest=/tmp/${{ matrix.image }}.tar
target: ${{ matrix.target }}
tags: ${{ matrix.image }}:${{ github.sha }}
builder: ${{ steps.buildx.outputs.name }}
cache-from: type=local,src=/tmp/.${{ matrix.image }}-cache
cache-to: type=local,mode=max,dest=/tmp/.${{ matrix.image }}-cache
- name: upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.image }}
path: /tmp/${{ matrix.image }}.tar
integration-tests:
runs-on: ubuntu-latest
needs:
- build-integration-test-containers
timeout-minutes: 5
strategy:
matrix:
dapr-version: [ 1.3.0-rc.1, 1.2.0, 1.2.1, 1.2.2 ]
steps:
- name: Download Caddy Image
uses: actions/download-artifact@v2
with:
name: caddy
path: /tmp
- name: Download Tests Image
uses: actions/download-artifact@v2
with:
name: tests
path: /tmp
- name: Import images
run: |
docker load --input /tmp/caddy.tar
docker load --input /tmp/tests.tar
- uses: actions/checkout@v2
- uses: shivammathur/[email protected]
with:
php-version: 8.0
- name: Validate composer.json and composer.lock
run: composer validate
- name: Integration Environment Startup
run: composer run-script start
env:
DAPR_VERSION: ${{ matrix.dapr-version }}
run: docker-compose up -d
- name: Wait for environment stabilization
run: sleep 10
- name: Execute Tests
Expand Down
12 changes: 4 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,21 @@
version: "3"
services:
placement:
image: daprio/dapr:1.1.0
image: daprio/dapr:${DAPR_VERSION}
command: [ "./placement","-port","50006" ]
dev:
build:
dockerfile: images/tests.Dockerfile
context: .
image: tests:${GITHUB_SHA}
depends_on:
- placement
ports:
- 9502:80
dev-caddy:
build:
dockerfile: images/caddy.Dockerfile
context: .
image: caddy:${GITHUB_SHA}
depends_on:
- dev
network_mode: service:dev
dev-daprd:
image: daprio/daprd:1.1.0
image: daprio/daprd:${DAPR_VERSION}
command: [ "./daprd","-app-id","dev","-app-port","80","-placement-host-address","placement:50006","-components-path","/components" ]
volumes:
- ./components:/components
Expand Down
4 changes: 2 additions & 2 deletions images/tests.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ RUN apt-get update && apt-get install -y wget git unzip && apt-get clean
RUN install-php-extensions curl zip && mkdir -p /tests
WORKDIR /tests

FROM withinboredom/php-base-min AS vendor
FROM base AS vendor
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY composer.json composer.json
COPY composer.lock composer.lock
RUN composer install --no-dev -o -n

FROM withinboredom/php-base-min AS config
FROM base AS config
COPY --from=vendor /tests/vendor vendor
COPY . /tests

Expand Down
106 changes: 55 additions & 51 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Monolog\Processor\PsrLogMessageProcessor;
use Nyholm\Psr7\Factory\Psr17Factory;
use Nyholm\Psr7Server\ServerRequestCreator;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;

Expand All @@ -46,111 +47,114 @@

return [
// logging
'dapr.log.level' => LogLevel::WARNING,
'dapr.log.handler' => [
'dapr.log.level' => LogLevel::WARNING,
'dapr.log.handler' => [
create(ErrorLogHandler::class)->constructor(
level: get('dapr.log.level')
),
],
'dapr.log.processor' => [create(PsrLogMessageProcessor::class)],
'dapr.logger' => create(Logger::class)->constructor(
'dapr.log.processor' => [create(PsrLogMessageProcessor::class)],
'dapr.logger' => create(Logger::class)->constructor(
'DAPR',
get('dapr.log.handler'),
get('dapr.log.processor')
),

// default logger to prevent breaking existing code
LoggerInterface::class => create(Logger::class)->constructor(
LoggerInterface::class => create(Logger::class)->constructor(
'APP',
get('dapr.log.handler'),
get('dapr.log.processor')
),

// internal functionality
'dapr.internal.serializer' => autowire(Serializer::class)->constructorParameter('logger', get('dapr.logger')),
'dapr.internal.deserializer' => autowire(Deserializer::class)->constructorParameter(
'dapr.internal.serializer' => autowire(Serializer::class)->constructorParameter('logger', get('dapr.logger')),
'dapr.internal.deserializer' => autowire(Deserializer::class)->constructorParameter(
'logger',
get('dapr.logger')
),
\Dapr\Client\DaprClient::class => fn(ContainerInterface $container) => \Dapr\Client\DaprClient::clientBuilder()
->withDeserializationConfig($container->get(DeserializationConfig::class))
->withSerializationConfig($container->get(SerializationConfig::class))
->withLogger($container->get('dapr.logger'))
->useHttpClient('http://localhost:' . $container->get('dapr.port'))
->build(),

// SDK wiring
ActorConfig::class => autowire()
ActorConfig::class => autowire()
->constructorParameter('actor_name_to_type', get('dapr.actors'))
->constructorParameter('idle_timeout', get('dapr.actors.idle_timeout'))
->constructorParameter('scan_interval', get('dapr.actors.scan_interval'))
->constructorParameter('drain_timeout', get('dapr.actors.drain_timeout'))
->constructorParameter('drain_enabled', get('dapr.actors.drain_enabled')),
ActorRuntime::class => autowire()
ActorRuntime::class => autowire()
->constructorParameter('logger', get('dapr.logger'))
->constructorParameter('deserializer', get('dapr.internal.deserializer')),
ActorState::class => autowire()->constructorParameter('logger', get('dapr.logger')),
ActorProxy::class => autowire()->constructorParameter('logger', get('dapr.logger')),
ApplicationJson::class => autowire(),
App::class => autowire()
ActorState::class => autowire()->constructorParameter('logger', get('dapr.logger')),
ActorProxy::class => autowire()->constructorParameter('logger', get('dapr.logger')),
ApplicationJson::class => autowire(),
App::class => autowire()
->constructorParameter('logger', get('dapr.logger'))
->constructorParameter('serializer', get('dapr.internal.serializer')),
CachedGenerator::class => autowire(),
DynamicGenerator::class => autowire(),
DaprClient::class => autowire()
CachedGenerator::class => autowire(),
DynamicGenerator::class => autowire(),
DaprClient::class => autowire()
->constructorParameter('port', get('dapr.port'))
->constructorParameter('logger', get('dapr.logger')),
DeserializationConfig::class => autowire()->constructorParameter(
DeserializationConfig::class => autowire()->constructorParameter(
'deserializers',
get('dapr.deserializers.custom')
),
ExistingOnly::class => autowire(),
FileGenerator::class => autowire(),
IDeserializer::class => autowire(Deserializer::class)->constructorParameter(
ExistingOnly::class => autowire(),
FileGenerator::class => autowire(),
IDeserializer::class => autowire(Deserializer::class)->constructorParameter(
'logger',
get('dapr.logger')
),
IManageState::class => autowire(StateManager::class)->constructorParameter(
'logger',
get('dapr.logger')
),
ISerializer::class => autowire(Serializer::class)->constructorParameter('logger', get('dapr.logger')),
ProxyFactory::class => autowire()->constructorParameter(
IManageState::class => autowire(StateManager::class),
ISerializer::class => autowire(Serializer::class)->constructorParameter('logger', get('dapr.logger')),
ProxyFactory::class => autowire()->constructorParameter(
'mode',
get('dapr.actors.proxy.generation')
),
Psr17Factory::class => autowire(),
Publish::class => autowire()->constructorParameter('pubsub', get('dapr.pubsub.default')),
RouteCollector::class => autowire()
Psr17Factory::class => autowire(),
Publish::class => autowire()->constructorParameter('pubsub', get('dapr.pubsub.default')),
RouteCollector::class => autowire()
->constructorParameter('routeParser', create(Std::class))
->constructorParameter('dataGenerator', create(GroupCountBased::class)),
SecretManager::class => autowire()->constructorParameter('logger', get('dapr.logger')),
SerializationConfig::class => autowire()->constructorParameter('serializers', get('dapr.serializers.custom')),
ServerRequestCreator::class => create()->constructor(
SecretManager::class => autowire()->constructorParameter('logger', get('dapr.logger')),
SerializationConfig::class => autowire()->constructorParameter('serializers', get('dapr.serializers.custom')),
ServerRequestCreator::class => create()->constructor(
get(Psr17Factory::class),
get(Psr17Factory::class),
get(Psr17Factory::class),
get(Psr17Factory::class)
),
StateManager::class => autowire(),
Subscriptions::class => autowire()->constructorParameter(
StateManager::class => autowire(),
Subscriptions::class => autowire()->constructorParameter(
'subscriptions',
get('dapr.subscriptions')
),
Topic::class => autowire()
Topic::class => autowire()
->constructorParameter('logger', get('dapr.logger'))
->constructorParameter('client', get(DaprClient::class)),
Tracing::class => autowire(),
Transaction::class => autowire(),
TransactionalState::class => autowire()->constructorParameter('logger', get('dapr.logger')),
Tracing::class => autowire(),
Transaction::class => autowire(),
TransactionalState::class => autowire()->constructorParameter('logger', get('dapr.logger')),

// default application settings
'dapr.pubsub.default' => 'pubsub',
'dapr.actors.proxy.generation' => ProxyFactory::GENERATED,
'dapr.subscriptions' => [],
'dapr.actors' => [],
'dapr.actors.idle_timeout' => null,
'dapr.actors.scan_interval' => null,
'dapr.actors.drain_timeout' => null,
'dapr.actors.drain_enabled' => null,
'dapr.actors.cache' => FileCache::class,
'dapr.http.middleware.request' => [get(Tracing::class)],
'dapr.pubsub.default' => 'pubsub',
'dapr.actors.proxy.generation' => ProxyFactory::GENERATED,
'dapr.subscriptions' => [],
'dapr.actors' => [],
'dapr.actors.idle_timeout' => null,
'dapr.actors.scan_interval' => null,
'dapr.actors.drain_timeout' => null,
'dapr.actors.drain_enabled' => null,
'dapr.actors.cache' => FileCache::class,
'dapr.http.middleware.request' => [get(Tracing::class)],
'dapr.http.middleware.response' => [get(ApplicationJson::class), get(Tracing::class)],
'dapr.port' => env('DAPR_HTTP_PORT', "3500"),
'dapr.serializers.custom' => [],
'dapr.deserializers.custom' => [],
'dapr.port' => env('DAPR_HTTP_PORT', "3500"),
'dapr.serializers.custom' => [],
'dapr.deserializers.custom' => [],
];
Loading

0 comments on commit 5e2e0b4

Please sign in to comment.