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

PF-3004: Fix stairctl so it runs again, other updates #154

Merged
merged 4 commits into from
Aug 5, 2024

Conversation

pshapiro4broad
Copy link
Member

@pshapiro4broad pshapiro4broad commented Jul 12, 2024

This PR updates the configuration of stairctl so it works again.

While updating it, I noticed that it makes heavy use of System.out, which isn't the recommended approach for Spring Shell apps. I updated it to use Terminal instead.

While testing, I've used this to look at TDR flight logs in dev and locally, and it seems like it might be useful. It may be useful for other Terra apps that use stairway, for developers, or a tool for support, so they can look at flight failures in more detail without needing to search production logs.

Here's an example session using stairctl:

❯ java -jar stairctl/build/libs/stairctl-1.1.9-SNAPSHOT.jar
StairCtl  (v1.1.9-SNAPSHOT)

[main] INFO bio.terra.stairctl.Application - Starting Application v1.1.9-SNAPSHOT using Java 17.0.4.1 with PID 68497 (/Users/pshapiro/source/stairway/stairctl/build/libs/stairctl-1.1.9-SNAPSHOT.jar started by pshapiro in /Users/pshapiro/source/stairway)
[main] INFO bio.terra.stairctl.Application - No active profile set, falling back to 1 default profile: "default"
[main] INFO bio.terra.stairctl.Application - Started Application in 2.031 seconds (process running for 2.434)
stairctl> connect
Connected to Stairway
Connected to Stairway on database stairwaylib
stairctl> show connection
Stairway Connection:
  dbname  : stairwaylib
  username: stairwayuser
  host    : 127.0.0.1
  port    : 5432
stairctl> list flights

Offset FlightId                             Class                                Submitted                   Completed                   Status       StairwayId                    
------ ------------------------------------ ------------------------------------ --------------------------- --------------------------- ------------ ------------------------------
     0 undoTest                             b.t.s.flights.TestFlightRecoveryUndo 2024-07-12T15:36:39.407627Z 2024-07-12T15:36:44.511316Z ERROR                                      

stairctl> get flight --flightId undoTest

Flight: undoTest
  class     : bio.terra.stairway.flights.TestFlightRecoveryUndo
  submitted : 2024-07-12T15:36:39.407627Z
  completed : 2024-07-12T15:36:44.511316Z
  duration  : 0:00:05.103
  status    : ERROR
  exception : java.lang.RuntimeException;TestStepTriggerUndo
  stairwayId: 
stairctl> 


spring:
shell:
interactive:
Copy link
Member Author

@pshapiro4broad pshapiro4broad Jul 12, 2024

Choose a reason for hiding this comment

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

Spring shell 3.3 disables the interactive shell by default, so we need to set this property to enable it.

https://github.com/spring-projects/spring-shell/wiki/Spring-Shell-3.3-Release-Notes

exclude module: 'spring-boot-starter-logging'
}

implementation 'org.slf4j:slf4j-simple:1.7.36'
Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't necessary but it cleans up the log configuration errors you get on startup

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough, would you mind adding a comment to that effect on the exclusion?

- use `Terminal` not System.out for output
- remove apache utils where possible
@pshapiro4broad pshapiro4broad marked this pull request as ready for review July 26, 2024 13:46
@@ -31,47 +33,41 @@ public void connect(
defaultValue = ShellOption.NULL)
String dbname,
@ShellOption(
value = {"-h", "--host"},
value = {"-H", "--host"},
Copy link
Member Author

Choose a reason for hiding this comment

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

This was required as -h conflicts with help, which is a global option. Spring shell didn't report an error but it did cause some odd problems when trying to use other options for this command.

Copy link
Contributor

@okotsopoulos okotsopoulos left a comment

Choose a reason for hiding this comment

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

Thank you for noodling on this! Would you mind also looking at the stairctl readme to see if any updates are needed in light of these changes?

I think that the ticket number also needs to be associated with this PR - https://broadworkbench.atlassian.net/browse/PF-3004

exclude module: 'spring-boot-starter-logging'
}

implementation 'org.slf4j:slf4j-simple:1.7.36'
Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough, would you mind adding a comment to that effect on the exclusion?

this.dbname = dbname;
return this;
}
public record ConnectParams(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, love a config-to-record refactor.

dbname = Optional.ofNullable(dbname).orElse(defaults.getDbname());
public ConnectParams withDefaults(ConnectParams defaults) {
return new ConnectParams(
Objects.requireNonNullElseGet(username, defaults::username),
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL about this Objects helper method.

@pshapiro4broad pshapiro4broad changed the title Fix stairctl so it runs again PF-3004: Fix stairctl so it runs again, other updates Aug 1, 2024
- update to latest slf4j. This required converting logback.groovy to logback.xml
- change stairctl to not log at all
@@ -14,7 +13,7 @@ repositories {

dependencies {
// For logging
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.36'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '2.0.13'
Copy link
Member Author

Choose a reason for hiding this comment

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

I was able to remove the stairctl subproject dependency exclusion by updating the slf4j version to the current release. This required changing the logback config files to xml, as groovy was deprecated a while ago due to security issues.

script:
enabled: true

# Disable logging
Copy link
Member Author

Choose a reason for hiding this comment

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

While looking the logging dependencies, I thought that, as a command line program, stairctl shouldn't log at all, so I added a config to properties to disable logging.

Copy link

sonarqubecloud bot commented Aug 1, 2024

Copy link
Collaborator

@fboulnois fboulnois left a comment

Choose a reason for hiding this comment

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

👍

@pshapiro4broad pshapiro4broad merged commit baceb1d into develop Aug 5, 2024
3 checks passed
@pshapiro4broad pshapiro4broad deleted the ps/fix-stairctl branch August 5, 2024 18:07
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.

3 participants