Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add capability to run to support -f flag #1161

Merged
merged 18 commits into from
Jan 20, 2023

Conversation

mukundansundar
Copy link
Collaborator

@mukundansundar mukundansundar commented Jan 10, 2023

Description

This adds the initial commits and changes for dapr run -f.
Renames Apps as App struct.
Refactors run in different functions without modifying existing Run code.
Adds code to execute run on multiple apps, with ability to write logs to files as needed.

LIMITATIONS

  • if dapr stop is used to stop all the apps started using CLI dapr run -f command, the CLI process will still remain running waiting for a SIGINT.
  • if there is shell based color codes being emitted by the app, then it will show up as special chars in the logs for example:
�[31m�[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.�[0m

That is for adding red color to the text when viewed in shell.

FOLLOW-UP WORK

version: 1
common:
  resources_path: ./resources
  app_protocol: http
  dapr_http_max_request_size: -1 # part of proper default parsing
  dapr_http_read_buffer_size: -1
apps:
  - app_dir_path: ./processor/
    app_port: 8001
    dapr_http_port: 3501
    command: ["python3", "app.py"]
  - app_id: emit-metrics
    app_dir_path: ./emit-metrics/
    dapr_http_port: 3500
    command: ["python3", "app.py"]

Output of dapr run -f dapr.yaml:

$ dapr run -f ./dapr.yaml
ℹ️  Validating config and starting app "processor"               
ℹ️  Started Dapr with app id processor. HTTP Port: 3501. gRPC Port: 0
ℹ️  Writing log files to directory : /absolute/path/processor/.dapr/logs
ℹ️  Validating config and starting app "emit-metrics"
ℹ️  Started Dapr with app id emit-metrics. HTTP Port: 3500. gRPC Port: 0
ℹ️  Writing log files to directory : /absoulte/path/emit-metrics/.dapr/logs
^C
ℹ️  Received signal to stop Dapr and app processes. Shutting down Dapr and app processes.

Output of dapr list:

$ dapr list           
  APP ID        HTTP PORT  GRPC PORT  APP PORT  COMMAND         AGE  CREATED              DAPRD PID  CLI PID  
  emit-metrics  3500       61050      0         python3 app.py  3s   2023-01-10 16:20.48  19043      0        
  processor     3501       61003      8001      python3 app.py  4s   2023-01-10 16:20.47  19036      0    

Note: Here CLI PID is specifically set to 0, such that stopping one app does not stop the CLI process.

daprd Logs for processor

$ cat ./processor/.dapr/logs/daprd.log 

Starting Dapr with id processor. HTTP Port: 3501. gRPC Port: 60538
time="2023-01-10T15:49:11.51382+05:30" level=info msg="starting Dapr Runtime -- version 1.9.5 -- commit f5f847eef8721d85f115729ee9efa820fe7c4cd3" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.513865+05:30" level=info msg="log level set to: info" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.513918+05:30" level=info msg="metrics server started on :60539/" app_id=processor instance=localhost scope=dapr.metrics type=log ver=1.9.5
time="2023-01-10T15:49:11.514034+05:30" level=info msg="loading default configuration" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.51405+05:30" level=info msg="standalone mode configured" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.514057+05:30" level=info msg="app id: processor" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.514357+05:30" level=info msg="mTLS is disabled. Skipping certificate request and tls validation" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.514439+05:30" level=info msg="Dapr trace sampler initialized: DaprTraceSampler(P=0.000100)" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.514931+05:30" level=info msg="local service entry announced: processor -> 192.168.1.34:60540" app_id=processor instance=localhost scope=dapr.contrib type=log ver=1.9.5
time="2023-01-10T15:49:11.514951+05:30" level=info msg="Initialized name resolution to mdns" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.514975+05:30" level=info msg="loading components" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.515376+05:30" level=info msg="waiting for all outstanding components to be processed" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.515395+05:30" level=info msg="all outstanding components processed" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.515404+05:30" level=info msg="gRPC proxy enabled" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.515442+05:30" level=info msg="enabled gRPC tracing middleware" app_id=processor instance=localhost scope=dapr.runtime.grpc.api type=log ver=1.9.5
time="2023-01-10T15:49:11.515452+05:30" level=info msg="enabled gRPC metrics middleware" app_id=processor instance=localhost scope=dapr.runtime.grpc.api type=log ver=1.9.5
time="2023-01-10T15:49:11.515493+05:30" level=info msg="API gRPC server is running on port 60538" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.515601+05:30" level=info msg="enabled metrics http middleware" app_id=processor instance=localhost scope=dapr.runtime.http type=log ver=1.9.5
time="2023-01-10T15:49:11.515608+05:30" level=info msg="enabled tracing http middleware" app_id=processor instance=localhost scope=dapr.runtime.http type=log ver=1.9.5
time="2023-01-10T15:49:11.515637+05:30" level=info msg="http server is running on port 3501" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.515643+05:30" level=info msg="The request body size parameter is: 4" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.515662+05:30" level=info msg="enabled gRPC tracing middleware" app_id=processor instance=localhost scope=dapr.runtime.grpc.internal type=log ver=1.9.5
time="2023-01-10T15:49:11.515678+05:30" level=info msg="enabled gRPC metrics middleware" app_id=processor instance=localhost scope=dapr.runtime.grpc.internal type=log ver=1.9.5
time="2023-01-10T15:49:11.515694+05:30" level=info msg="internal gRPC server is running on port 60540" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.515701+05:30" level=info msg="application protocol: http. waiting on port 8001.  This will block until the app is listening on that port." app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.618867+05:30" level=info msg="application discovered on port 8001" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.620415+05:30" level=info msg="application configuration loaded" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.620482+05:30" level=info msg="actors: state store is not configured - this is okay for clients but services with hosted actors will fail to initialize!" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:11.620519+05:30" level=info msg="actor runtime started. actor idle timeout: 1h0m0s. actor scan interval: 30s" app_id=processor instance=localhost scope=dapr.runtime.actor type=log ver=1.9.5
time="2023-01-10T15:49:11.620541+05:30" level=info msg="dapr initialized. Status: Running. Init Elapsed 106ms" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
Updating metadata for app command: python3 app.py
You're up and running! Both Dapr and your app logs will appear here.

time="2023-01-10T15:49:22.539756+05:30" level=info msg="placement tables updated, version: 0" app_id=processor instance=localhost scope=dapr.runtime.actor.internal.placement type=log ver=1.9.5
time="2023-01-10T15:49:52.293348+05:30" level=info msg="stopping mDNS server for app id: processor" app_id=processor instance=localhost scope=dapr.contrib type=log ver=1.9.5
time="2023-01-10T15:49:52.293376+05:30" level=info msg="dapr shutting down." app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:52.293444+05:30" level=info msg="Stopping PubSub subscribers and input bindings" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:52.293459+05:30" level=info msg="Shutting down actor" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:52.551311+05:30" level=info msg="Stopping Dapr APIs" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:52.551839+05:30" level=info msg="Waiting 5s to finish outstanding operations" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
time="2023-01-10T15:49:57.553426+05:30" level=info msg="Shutting down all remaining components" app_id=processor instance=localhost scope=dapr.runtime type=log ver=1.9.5
Exited Dapr successfully

termination signal received: shutting down
Exited App successfully

app logs for processor

$ cat ./processor/.dapr/logs/app.log 

cat ./processor/.dapr/logs/app.log  
 * Serving Flask app 'app'
 * Debug mode: off
�[31m�[1mWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.�[0m
 * Running on http://127.0.0.1:8001
Press CTRL+C to quit
127.0.0.1 - - [10/Jan/2023 15:49:11] "GET /dapr/config HTTP/1.1" 404 -
Metrics received : {"metricsId": 1}
Checking Availability of dependency
Sending response for : {"metricsId": 1}

127.0.0.1 - - [10/Jan/2023 15:49:13] "POST /metrics HTTP/1.1" 200 -
Metrics received : {"metricsId": 2}
Checking Availability of dependency
Sending response for : {"metricsId": 2}

127.0.0.1 - - [10/Jan/2023 15:49:14] "POST /metrics HTTP/1.1" 200 -
Metrics received : {"metricsId": 3}
Checking Availability of dependency
Sending response for : {"metricsId": 3}

127.0.0.1 - - [10/Jan/2023 15:49:15] "POST /metrics HTTP/1.1" 200 -
Metrics received : {"metricsId": 4}
Checking Availability of dependency
Sending response for : {"metricsId": 4}

127.0.0.1 - - [10/Jan/2023 15:49:16] "POST /metrics HTTP/1.1" 200 -
Metrics received : {"metricsId": 5}
Checking Availability of dependency
Sending response for : {"metricsId": 5}

127.0.0.1 - - [10/Jan/2023 15:49:17] "POST /metrics HTTP/1.1" 200 -
Metrics received : {"metricsId": 6}
Checking Availability of dependency
Sending response for : {"metricsId": 6}

127.0.0.1 - - [10/Jan/2023 15:49:18] "POST /metrics HTTP/1.1" 200 -
Metrics received : {"metricsId": 7}
Checking Availability of dependency
Sending response for : {"metricsId": 7}

termination signal received: shutting down

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

related to #1143

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Jan 10, 2023

Codecov Report

Merging #1161 (7f43552) into master (b51eda4) will decrease coverage by 5.27%.
The diff coverage is 17.33%.

@@            Coverage Diff             @@
##           master    #1161      +/-   ##
==========================================
- Coverage   31.67%   26.40%   -5.27%     
==========================================
  Files          36       38       +2     
  Lines        2526     2579      +53     
==========================================
- Hits          800      681     -119     
- Misses       1630     1832     +202     
+ Partials       96       66      -30     
Impacted Files Coverage Δ
pkg/standalone/run.go 0.00% <0.00%> (-64.62%) ⬇️
pkg/standalone/runfileconfig/run_file_config.go 0.00% <0.00%> (ø)
...standalone/runfileconfig/run_file_config_parser.go 73.21% <ø> (ø)
pkg/runexec/runexec.go 29.54% <29.54%> (ø)
pkg/standalone/common.go 40.00% <0.00%> (-10.00%) ⬇️
pkg/standalone/list.go 0.00% <0.00%> (-6.46%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
@mukundansundar mukundansundar marked this pull request as ready for review January 10, 2023 10:44
@mukundansundar mukundansundar requested review from a team as code owners January 10, 2023 10:44
@mukundansundar mukundansundar changed the title [WIP] Refactor run to support -f flag Refactor run to support -f flag Jan 10, 2023
assert.Contains(t, output, "failed to load components: open ../testdata/nonexistentdir:")
assert.Contains(t, output, "Exited App successfully")
assert.Contains(t, output, "Exited Dapr successfully")
require.Error(t, err, "run did not fail")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run must fail if a non existent dir is given.

@@ -169,6 +171,7 @@ dapr run --app-id myapp --dapr-path /usr/local/dapr
print.FailureStatusEvent(os.Stderr, err.Error())
os.Exit(1)
}
// TODO: In future release replace following logic with the refactored functions seen below.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This refactor of actual run will be done after the initial release for run -f feature.

if logAsJSON {
logJSON(w, string(status), fmt.Sprintf(fmtstr, a...))
} else {
if (w == os.Stdout || w == os.Stderr) && runtime.GOOS != windowsOS {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this check so that, in future, normal dapr run outputing to stdout can automatically use this StatusEvent function. This is the function used in the individual functions inside cmd/run.go

@@ -1,5 +1,5 @@
/*
Copyright 2021 The Dapr Authors
Copyright 2023 The Dapr Authors
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just moves the pkg/standalone/run_test.go file into this package and modifies the imports for that.

Comment on lines +83 to +87
dirPath := config.ResourcesPath
if dirPath == "" {
dirPath = config.ComponentsPath
}
_, err := os.Stat(dirPath)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the function that is introducing the E2E change seen in this PR. Previously resources path value was not validated. Now it is being validated.

}

// RunOutput represents the run execution.
type RunOutput struct {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will later be removed, once the normal dapr run also migrates to using the RunExec struct.

return nil
}

func NewOutput(config *standalone.RunConfig) (*RunOutput, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly same as pkg/standalone/run.go#Run function. moved here and renamed.

Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
@pravinpushkar
Copy link
Contributor

@mukundansundar Multiple attempt to use dapr run -f <> will corrupt the logfile. So, log file suffix is needed.

@mukundansundar
Copy link
Collaborator Author

@mukundansundar Multiple attempt to use dapr run -f <> will corrupt the logfile. So, log file suffix is needed.

Will add it as a change in the follow up E2E PR.

Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
@mukundansundar
Copy link
Collaborator Author

mukundansundar commented Jan 20, 2023

Resolved the above comments with the following summary:

Changes that will be done in follow-up PRs

@artursouza CLI PID properly set for run -f and stop enhancements
Already part of PR #1169
@philliphoff App log file name change and side by side for multiple runs
Planned for PR #1170
@philliphoff runFilePath in metadata
Already part of PR #1169

Changes planned for next release

@philliphoff ignore start up errors Issue #1173
@philliphoff parallelize app start up Issue #1174

@mukundansundar
Copy link
Collaborator Author

@artursouza the changes are done. Please review

Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
pravinpushkar
pravinpushkar previously approved these changes Jan 20, 2023
Copy link
Contributor

@pravinpushkar pravinpushkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm
Follow up work items mentioned in this comment -#1161 (comment)

Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
@mukundansundar mukundansundar changed the title Refactor run to support -f flag Add capability to run to support -f flag Jan 20, 2023
Copy link
Contributor

@pravinpushkar pravinpushkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of nits. But LGTM

@artursouza artursouza merged commit 36893d9 into dapr:master Jan 20, 2023
@mukundansundar mukundansundar deleted the refactor-run branch January 20, 2023 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants