1

I have a simple Dapr project for state management. I have one model class holding data and storing that model data into a redis state store. I have a statestore.yml file for configuration.

When I run project with dapr run --app-id [appname] --app-port [port] dontnet run command in the command line while running default images (redis, zipkin, daprio/dapr) freshly pulling from dockerhub, the state store endpoints work.

However, when I create a docker-compose and run it, then I end up with exception shown below. I couldn't find the exact solution for this on Stack Overflow. Does anyone know what could cause this issue?

====== docker-compose.yml =======

version: '3.4'

services:
  daprtestapi:
    image: ${DOCKER_REGISTRY-}daprtestapi
    build:
      context: .
      dockerfile: DaprTestApi/Dockerfile
    ports:
     - "52000:50001"
    depends_on:
     - redis

  daprtestapi-dapr:
    image: "daprio/daprd:latest"
    command: ["./daprd", "-app-id", "daprtestapi", "-app-port", "80", "-components-path", "/DaprTestApi/Components"]
    depends_on:
        - daprtestapi
    network_mode: "service:daprtestapi"

  redis:
    container_name: "dapr_redis" 
    image: "redis:latest"

======== Exception Thrown ==============

Dapr.DaprException: State operation failed: the Dapr endpoint indicated a failure. See InnerException for details.
 ---> Grpc.Core.RpcException: Status(StatusCode="FailedPrecondition", Detail="state store is not configured")
   at Dapr.Client.DaprClientGrpc.GetStateAndETagAsync[TValue](String storeName, String key, Nullable`1 consistencyMode, IReadOnlyDictionary`2 metadata, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at Dapr.Client.DaprClientGrpc.GetStateAndETagAsync[TValue](String storeName, String key, Nullable`1 consistencyMode, IReadOnlyDictionary`2 metadata, CancellationToken cancellationToken)
   at Dapr.Client.DaprClient.GetStateEntryAsync[TValue](String storeName, String key, Nullable`1 consistencyMode, IReadOnlyDictionary`2 metadata, CancellationToken cancellationToken)
   at Dapr.AspNetCore.StateEntryModelBinder.GetStateEntryAsync[T](DaprClient daprClient, String storeName, String key)
   at Dapr.AspNetCore.StateEntryModelBinder.BindModelAsync(ModelBindingContext bindingContext)
   at Microsoft.AspNetCore.Mvc.ModelBinding.ParameterBinder.BindModelAsync(ActionContext actionContext, IModelBinder modelBinder, IValueProvider valueProvider, ParameterDescriptor parameter, ModelMetadata metadata, Object value, Object container)
   at Microsoft.AspNetCore.Mvc.Controllers.ControllerBinderDelegateProvider.<>c__DisplayClass0_0.<<CreateBinderDelegate>g__Bind|0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

HEADERS
=======
:authority: localhost:57104
:method: GET
:path: /get/1
:scheme: https
Accept: text/plain
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9
Cookie: language=en,region=en-US
Host: localhost:57104
Referer: https://localhost:57104/swagger/index.html
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.38
sec-ch-ua: "Microsoft Edge";v="93", " Not;A Brand";v="99", "Chromium";v="93"
sec-ch-ua-mobile: ?0
sec-ch-ua-platform: "Windows"
sec-fetch-site: same-origin
sec-fetch-mode: cors
sec-fetch-dest: empty
2
  • What the DaprTestApi look like and how are you trying to access the state store? Commented Sep 21, 2021 at 10:30
  • @tmarwen DaprTestApi is very simple .net core API with controller to expose endpoints. I'm calling dapr client method to add data in statestore. I have statestore configuration yml as well. This is code for adding data to statestore which throws exception. var state = await daprClient.GetStateEntryAsync<ProducerStore>(StoreName, pDashboard.Id.ToString()); state.Value ??= new ProducerStore() { Id = pDashboard.Id.ToString()}; state.Value.Dashboard = pDashboard; await state.SaveAsync(); return Ok(state.Value); Commented Sep 28, 2021 at 18:15

1 Answer 1

1

There should be a statestore.yaml as the configuration file. And in the docker-compose.yaml, a "volumes" section is used for mapping the path of statestore.yaml on your host to /DaprTestApi/Components, such as:

daprtestapi-dapr:
    image: "daprio/daprd:latest"
    command: ["./daprd", "-app-id", "daprtestapi", "-app-port", "80", "-components-path", "/DaprTestApi/Components"]
    depends_on:
        - daprtestapi
    network_mode: "service:daprtestapi"
    volumes:
        - [path for statestore.yaml]:/DaprTestApi/Components

Finally ,the statestore.yaml seems like:

apiVersion: dapr.io/v1
kind: Component
metadata:
  name: statestore
spec:
  type: state.redis
  version: v1
  metadata:
  - name: redisHost
    value: redis:6379
  - name: redisPassword
    value: ""
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.