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

showLogs() does not run if it does not find the deployment #989

Closed
alvarosantamariagomez opened this issue Sep 1, 2023 · 13 comments · Fixed by #1015
Closed

showLogs() does not run if it does not find the deployment #989

alvarosantamariagomez opened this issue Sep 1, 2023 · 13 comments · Fixed by #1015
Assignees

Comments

@alvarosantamariagomez
Copy link

After the update to 1.0.2 I cannot run rsconnect::showLogs() on a different machine that the one I use to develop and deploy.
showLogs() says it doesn't find any deployment.
This was not a problem before the last version change. Before the change, only the account (token) and the app details was enough to run showLogs().

A patch to this problem is to copy the app folder from the machine I use to deploy into the machine I use to run showLogs().
It's not a very clean solution, but at least showLogs() now finds the deployment and works again.

It would be nice if showLogs() could run anywhere independently of the app/deployment folder, as it was the case before.

Thanks, bye.

@aronatkins
Copy link
Contributor

Likely the same cause as #985

@aronatkins
Copy link
Contributor

@hadley it sounds as if a number of folks were using some of the shinyapps.io helpers to inspect and monitor their applications without deployment records on-disk in a rsconnect directory.

@hadley
Copy link
Member

hadley commented Sep 1, 2023

Interesting. How is it supposed to figure out what app they're interested in?

@aronatkins
Copy link
Contributor

We used deploymentTarget, which performed a search.

target <- deploymentTarget(appPath, appName, NULL, NULL, account, server)

rsconnect/R/deployApp.R

Lines 611 to 612 in 9ce427e

deploymentTarget <- function(appPath, appName, appTitle, appId, account,
server = NULL) {

@hadley
Copy link
Member

hadley commented Sep 1, 2023

So that ended up using the directory name?

@aronatkins
Copy link
Contributor

@alvarosantamariagomez - What was your working directory you used when calling showLogs()? Did the name of that directory correspond to your application name, or did you provide an appName argument to showLogs()? How many different applications do you have deployed to shinyapps.io? We are trying to understand if there was something about your installation that let you locate the target application and show its logs.

@aronatkins
Copy link
Contributor

@hadley - #980 and https://community.rstudio.com/t/shinyapps-io-deploy-error-409-application-exists-with-name/170488/7 also speak of similar problems. There was a separate problem with showProperties() (resolved by #984), but we're definitely missing something about how these apps were being discovered.

@alvarosantamariagomez
Copy link
Author

I have several apps deployed, but I check the logs of only one app.
None of the apps was deployed from the machine I use to check the logs.
The full command I was using in any directory of this machine was
rsconnect::showLogs(appName="one app", streaming=F, entries=1500)
Before being able to do that, I set my shinyapps.io account information with the token.
I assume rsconnect was using that information to locate the remote deployment of the app and get the log.

It could be useful to have that possibility back in the latest version, though simply copying the app folder (from the other machine where I develop & deploy) also solved my problem.
The command I have to use with rsconnect version 1.0.2 is
rsconnect::showLogs(appPath="path/to/the/copied/app/folder", streaming=F, entries=1500)

hope that helps

@aronatkins
Copy link
Contributor

Thanks for all that context, @alvarosantamariagomez.

@aronatkins
Copy link
Contributor

This issue also corresponds to customer ticket 94407.

@jacpete
Copy link

jacpete commented Sep 21, 2023

I was working with a customer on a shinyapps.io ticket and ran into this issue.
I can confirm that many shinyapps.io customers use this feature to pull logs for all their applications programmatically on a schedule because logs turn over every 1500 lines on the platform.

I found that if we just had the option to use the appName, server and account inputs to showLogs() directly, the problem could be bypassed. This removes the check that rsconnect:::findDeployment was doing by verifying information in the deployment logs in the rsconnect directory on-disk.

My modified function I sent to a customer to get them up and running with their scripts included a new verifyDeployment boolean parameter and only requires modifying lines around:

deployment <- findDeployment(appPath = appPath, appName = appName, 
                             server = server, account = account)
showLogs <- function(appFile = NULL, appName = NULL, 
                     account = NULL, server = NULL, 
                     entries = 50, streaming = FALSE, 
                     verifyDeployment = TRUE) {
  
  if (verifyDeployment) {
    deployment <- findDeployment(appPath = appPath, appName = appName, 
                                 server = server, account = account)
  } else {
    if (is.null(appName) | is.null(account) | is.null(server)) {
      stop('`appName`, `account`, and `server` must be specified if `verifyDeployment` is `FALSE`.')
    }
    
    deployment <- list(
      'account' = account,
      'server' = server,
      'name' = appName)
  }
  accountDetails <- rsconnect::accountInfo(deployment$account, deployment$server)
  client <- rsconnect:::clientForAccount(accountDetails)
  application <- rsconnect:::getAppByName(client, accountDetails, deployment$name)
  if (is.null(application)) 
    stop("No application found. Specify the application's directory, name, ", 
         "and/or associated account.")
  if (streaming) {
    skip <- 0
    repeat {
      tryCatch({
        rsconnect:::streamApplicationLogs(accountDetails, application$id, 
                                          entries, skip)
        entries <- 1
        skip <- 1
      }, error = function(e) {
        if (!identical(e$message, "transfer closed with outstanding read data remaining")) {
          stop(e)
        }
      })
    }
  }
  else {
    logs <- client$getLogs(application$id, entries)
    cat(logs)
  }
}

This was just to get them going but it does provide the workaround these folks are looking for to manage their servers. I have recommended a format similar to the one below for several customers and an example of how they are using this function in practice.

#set to home to show we can be in ANY directory now
setwd('~') 

#Grab a vector of 5 application names to test with
appNames <- rsconnect::applications(account ='testaccountjacpete', server = 'shinyapps.io')[['name']][1:5]

#Set the output location
file_loc <- '~/Downloads'


#Loop over the application names and save a copy of the logs using the modified `showLogs()` function
for (appName in appNames) {
  outputFile <- paste0(appName, "-logs_",format(Sys.time(), "%Y-%m-%d_%H-%M"), ".txt", sep = "")
  capture.output(
    {
      showLogs(appName = appName, account ='testaccountjacpete', server = 'shinyapps.io', 
               entries = 1500, verifyDeployment = FALSE)
    },
    file = file.path(file_loc, outputFile)
  )
}

@aronatkins aronatkins assigned aronatkins and unassigned hadley Oct 10, 2023
aronatkins added a commit that referenced this issue Oct 10, 2023
The stub deployment is subsequently used to look-up the application by name.
This lets showLogs, configureApp, setProperty, and unsetProperty interact with
shinyapps.io when the client lacks a deployment record.

Does not address issues with publishing, such as #1013.

Fixes #985
Fixes #989
aronatkins added a commit that referenced this issue Oct 11, 2023
The stub deployment is subsequently used to look-up the application by name.
This lets showLogs, configureApp, setProperty, and unsetProperty interact with
shinyapps.io when the client lacks a deployment record.

Does not address issues with publishing, such as #1013.

Fixes #985
Fixes #989
@aronatkins
Copy link
Contributor

@alvarosantamariagomez - Could you test the development version of rsconnect to see if your problem has been resolved?

remotes::install_github("rstudio/rsconnect")

@alvarosantamariagomez
Copy link
Author

@aronatkins problem solved in showLogs() without the need of having the deployed app folder, thanks

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 a pull request may close this issue.

4 participants