From 685e7b9a47838bffe762e50f7e8487f8b21ec60b Mon Sep 17 00:00:00 2001 From: Edgar Ruiz Date: Fri, 18 Aug 2023 17:14:24 -0500 Subject: [PATCH 1/5] Improvements to user agent to make them more Posit product specific --- R/spark-connect.R | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/R/spark-connect.R b/R/spark-connect.R index 1a3dac4..fe71638 100644 --- a/R/spark-connect.R +++ b/R/spark-connect.R @@ -79,20 +79,49 @@ py_spark_connect <- function(master, cluster_id = cluster_id ) + product <- NULL + in_rstudio <- FALSE + in_connect <- FALSE + check_rstudio <- try(RStudio.Version(), silent = TRUE) + if (!inherits(check_rstudio, "try-error")) { + in_rstudio <- TRUE + } + + if(Sys.getenv("R_CONFIG_ACTIVE") == "rsconnect") { + in_connect <- TRUE + } - if (inherits(check_rstudio, "try-error")) { - rstudio_chr <- NULL - } else { - rstudio_chr <- glue("rstudio/{check_rstudio$long_version}") + if(in_connect) { + product <- "posit-connect" + } + + if (in_rstudio && !in_connect) { + edition <- check_rstudio$edition + if(length(edition) == 0) edition <- "" + + mod <- check_rstudio$mode + if(length(mod) == 0) mod <- "" + + if(edition == "Professional") { + if(mod == "server") { + prod <- "posit-workbench" + } else { + prod <- "posit-rstudiopro" + } + } else { + prod <- "posit-rstudio" + } + product <- glue("{prod}/{check_rstudio$long_version}") } user_agent <- glue( paste( "sparklyr/{packageVersion('sparklyr')}", - rstudio_chr + product + ) ) - ) + conn <- remote$userAgent(user_agent) con_class <- "connect_databricks" master_label <- glue("Databricks Connect - Cluster: {cluster_id}") From e864797276ac9fafd51e965efdca9869fec202cf Mon Sep 17 00:00:00 2001 From: Edgar Ruiz Date: Mon, 21 Aug 2023 08:28:43 -0500 Subject: [PATCH 2/5] Improvements to user agent builder, moves to its own funtion for easier dev and debug --- R/spark-connect.R | 89 +++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 42 deletions(-) diff --git a/R/spark-connect.R b/R/spark-connect.R index fe71638..e1347f8 100644 --- a/R/spark-connect.R +++ b/R/spark-connect.R @@ -79,48 +79,7 @@ py_spark_connect <- function(master, cluster_id = cluster_id ) - product <- NULL - in_rstudio <- FALSE - in_connect <- FALSE - - check_rstudio <- try(RStudio.Version(), silent = TRUE) - if (!inherits(check_rstudio, "try-error")) { - in_rstudio <- TRUE - } - - if(Sys.getenv("R_CONFIG_ACTIVE") == "rsconnect") { - in_connect <- TRUE - } - - if(in_connect) { - product <- "posit-connect" - } - - if (in_rstudio && !in_connect) { - edition <- check_rstudio$edition - if(length(edition) == 0) edition <- "" - - mod <- check_rstudio$mode - if(length(mod) == 0) mod <- "" - - if(edition == "Professional") { - if(mod == "server") { - prod <- "posit-workbench" - } else { - prod <- "posit-rstudiopro" - } - } else { - prod <- "posit-rstudio" - } - product <- glue("{prod}/{check_rstudio$long_version}") - } - - user_agent <- glue( - paste( - "sparklyr/{packageVersion('sparklyr')}", - product - ) - ) + user_agent <- build_user_agent() conn <- remote$userAgent(user_agent) con_class <- "connect_databricks" @@ -240,3 +199,49 @@ python_sdf <- function(x) { } out } + + +build_user_agent <- function() { + product <- NULL + in_rstudio <- FALSE + in_connect <- FALSE + + check_rstudio <- try(RStudio.Version(), silent = TRUE) + if (!inherits(check_rstudio, "try-error")) { + in_rstudio <- TRUE + } + + if(Sys.getenv("RSTUDIO_PRODUCT") == "CONNECT") { + in_connect <- TRUE + } + + if(in_connect) { + product <- "posit-connect" + } + + if (in_rstudio && !in_connect) { + edition <- check_rstudio$edition + if(length(edition) == 0) edition <- "" + + mod <- check_rstudio$mode + if(length(mod) == 0) mod <- "" + + if(edition == "Professional") { + if(mod == "server") { + prod <- "workbench-rstudio" + } else { + prod <- "rstudio-pro" + } + } else { + prod <- "rstudio" + } + product <- glue("posit-{prod}/{check_rstudio$long_version}") + } + + glue( + paste( + "sparklyr/{packageVersion('sparklyr')}", + product + ) + ) +} From c6335bc3792ccce0182d687cb2f21c647f42bb40 Mon Sep 17 00:00:00 2001 From: Edgar Ruiz Date: Mon, 21 Aug 2023 09:55:22 -0500 Subject: [PATCH 3/5] Adds identifier for Cloud --- R/spark-connect.R | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/R/spark-connect.R b/R/spark-connect.R index e1347f8..762f1b1 100644 --- a/R/spark-connect.R +++ b/R/spark-connect.R @@ -206,36 +206,35 @@ build_user_agent <- function() { in_rstudio <- FALSE in_connect <- FALSE - check_rstudio <- try(RStudio.Version(), silent = TRUE) - if (!inherits(check_rstudio, "try-error")) { - in_rstudio <- TRUE + if (Sys.getenv("RSTUDIO_PRODUCT") == "CONNECT") { + product <- "posit-connect" } - if(Sys.getenv("RSTUDIO_PRODUCT") == "CONNECT") { - in_connect <- TRUE - } + if (is.null(product)) { + check_rstudio <- try(RStudio.Version(), silent = TRUE) + if (!inherits(check_rstudio, "try-error")) { + prod <- "rstudio" - if(in_connect) { - product <- "posit-connect" - } + edition <- check_rstudio$edition + if (length(edition) == 0) edition <- "" - if (in_rstudio && !in_connect) { - edition <- check_rstudio$edition - if(length(edition) == 0) edition <- "" + mod <- check_rstudio$mode + if (length(mod) == 0) mod <- "" - mod <- check_rstudio$mode - if(length(mod) == 0) mod <- "" + if (edition == "Professional") { + if (mod == "server") { + prod <- "workbench-rstudio" + } else { + prod <- "rstudio-pro" + } + } - if(edition == "Professional") { - if(mod == "server") { - prod <- "workbench-rstudio" - } else { - prod <- "rstudio-pro" + if (Sys.getenv("R_CONFIG_ACTIVE") == "rstudio_cloud") { + prod <- "cloud" } - } else { - prod <- "rstudio" + + product <- glue("posit-{prod}/{check_rstudio$long_version}") } - product <- glue("posit-{prod}/{check_rstudio$long_version}") } glue( From 5eb8b1e68868b5b3eced7788056fdb8437c54d0c Mon Sep 17 00:00:00 2001 From: Edgar Ruiz Date: Mon, 21 Aug 2023 09:56:24 -0500 Subject: [PATCH 4/5] Adds ide to cloud tag --- R/spark-connect.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/spark-connect.R b/R/spark-connect.R index 762f1b1..b6add1e 100644 --- a/R/spark-connect.R +++ b/R/spark-connect.R @@ -230,7 +230,7 @@ build_user_agent <- function() { } if (Sys.getenv("R_CONFIG_ACTIVE") == "rstudio_cloud") { - prod <- "cloud" + prod <- "cloud-rstudio" } product <- glue("posit-{prod}/{check_rstudio$long_version}") From 18873cf8c2900e31adc40ac4750ad208020becb7 Mon Sep 17 00:00:00 2001 From: Edgar Ruiz Date: Tue, 22 Aug 2023 14:02:45 -0500 Subject: [PATCH 5/5] Re-adds library snapshot for installation --- R/install.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/R/install.R b/R/install.R index 53f4d3b..37f552d 100644 --- a/R/install.R +++ b/R/install.R @@ -27,8 +27,7 @@ install_pyspark <- function(envname = "r-sparklyr", "delta-spark" ) - pip_options <- "--index-url https://packagemanager.posit.co/pypi/latest/simple" - # pip_options <- "--index-url https://packagemanager.posit.co/pypi/2023-06-15/simple" + pip_options <- "--index-url https://packagemanager.posit.co/pypi/2023-06-15/simple" # in cause user supplied pip_options in ... pip_options <- c(pip_options, list(...)$pip_options)