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

Use, when possible, an ENV var to get the installation type #8500

Merged
merged 6 commits into from Nov 19, 2021

Conversation

jredrejo
Copy link
Member

@jredrejo jredrejo commented Oct 14, 2021

Summary

Whenever it's available, use the KOLIBRI_INSTALLATION_TYPE env var to show the installation type instead of trying to guess it

In any case, with or without the env var, the output of the installation type follow the specs at https://docs.google.com/spreadsheets/d/1EpN4yIO9H0qkP0pY6jiEtfQIdyrEPChs3aDZwOMupcI/edit#gid=0

Example:
image

References

Closes: #7957

Reviewer guidance

Do the new constants names and descriptions make sense?

Testing checklist

  • Contributor has fully tested the PR manually
  • If there are any front-end changes, before/after screenshots are included
  • Critical user journeys are covered by Gherkin stories
  • Critical and brittle code paths are covered by unit tests

PR process

  • PR has the correct target branch and milestone
  • PR has 'needs review' or 'work-in-progress' label
  • If PR is ready for review, a reviewer has been added. (Don't use 'Assignees')
  • If this is an important user-facing change, PR or related issue has a 'changelog' label
  • If this includes an internal dependency change, a link to the diff is provided

Reviewer checklist

  • Automated test coverage is satisfactory
  • PR is fully functional
  • PR has been tested for accessibility regressions
  • External dependency files were updated if necessary (yarn and pip)
  • Documentation is updated
  • Contributor is in AUTHORS.md

@jredrejo jredrejo added the TODO: needs review Waiting for review label Oct 14, 2021
@jredrejo jredrejo added this to the 0.15.0 milestone Oct 14, 2021
WINDOWS = "Windows"

install_type_map = {
APK: "APK",
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a good way of constraining the values that end up in our analytics database - @jamalex any concerns with centralizing the possible values here?

Copy link
Member

Choose a reason for hiding this comment

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

It helps with having this centrally documented/enforced, so the various installers don't go and do their own things, yeah.

Main thing is that it'd need to be considered a template/prefix, rather than a simple equivalence match.

Copy link
Contributor

@indirectlylit indirectlylit left a comment

Choose a reason for hiding this comment

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

Slightly pedantic but possibly important: these are generally "runtime" types, not "installation" types.

Comment on lines 6 to 24
APK = "apk"
APT = "apt"
KOLIBRI_SERVER = "kolibri-server"
MACOS = "Mac"
PEX = "pex"
UWSGI = "uwsgi"
WHL = "whl"
WINDOWS = "Windows"

install_type_map = {
APK: "APK",
APT: "APT - Debian package",
KOLIBRI_SERVER: "kolibri(apt) with kolibri_server",
MACOS: "MacOS Installer",
PEX: "PEX file",
UWSGI: "UWSGI process",
WHL: "WHL Python package",
WINDOWS: "Windows Installer",
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused why there are two inconsistent variations of these strings.

Also, if these are permanent strings that cannot be changed we might want to tighten them a bit and make them a bit more consistent and correct:

  • package manager, file format, or operating system is the primary piece of info?
  • "apt" is spelled two different ways above
  • "MacOS" is actually spelled "macOS", and it's technically not an "installer", just an "app"
  • For "Windows" we might want to distinguish the current "server" version from a potential future "app" version more similar to mac
Suggested change
APK = "apk"
APT = "apt"
KOLIBRI_SERVER = "kolibri-server"
MACOS = "Mac"
PEX = "pex"
UWSGI = "uwsgi"
WHL = "whl"
WINDOWS = "Windows"
install_type_map = {
APK: "APK",
APT: "APT - Debian package",
KOLIBRI_SERVER: "kolibri(apt) with kolibri_server",
MACOS: "MacOS Installer",
PEX: "PEX file",
UWSGI: "UWSGI process",
WHL: "WHL Python package",
WINDOWS: "Windows Installer",
}
ANDROID = "Android APK"
DEBIAN = "Debian package"
DEBIAN_APT = "Debian APT-installed package"
DEBIAN_APT_SERVER = "Debian APT package with kolibri-server"
MACOS_APP = "macOS desktop app"
PEX = "PEX executable"
UWSGI = "UWSGI process"
WHL = "WHL Python package"
WINDOWS_BG = "Windows background process"
runtime_types = (
ANDROID,
DEBIAN,
DEBIAN_APT,
DEBIAN_APT_SERVER,
MACOS_APP,
PEX,
UWSGI,
WHL,
WINDOWS_BG,
)

Copy link
Member

Choose a reason for hiding this comment

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

The spec for this is here: #7960 this does need some updates to fit that spec (such as being able to insert the version number), but better to iterate there. Also, as there is already historic data in this format for some installers, updates may not be preferred for consistent analytics reporting.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, didn't realize there there was already data. At the least then there should only be one set of strings, not two? And we can still choose more consistent constant names even if the actual strings are a bit noisy.

Copy link
Member Author

@jredrejo jredrejo Oct 18, 2021

Choose a reason for hiding this comment

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

@rtibbles great, I was not aware of #7960 happy to fix these inconsistences after knowing the details.

@indirectlylit I agree with some of your changes (I didn't know we have an app for MacOs instead of an installer) but not with others, For Windows, for example installation type is clearly an installer, not a background process.
Also , there's not practical way to know if a Debian package has been installed using dpkg or apt, the current logic tries to find it out, but it can be easily cheated. In my opinion, we should just say "Deb package" removing the apt reference.

Copy link
Contributor

Choose a reason for hiding this comment

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

for what it's worth these comments are not critical or intended to be blocking.

For Windows, for example installation type is clearly an installer, not a background process.

Is it the "installation type" we care about or the runtime app? Sometimes it's both but often they are independent. This is like the Debian package which can be installed either with dpkg or apt.

The APK can be installed by sideloading or via the app store.

The current Windows repo contains three things:

  • an installer script which runs once
  • a background process (kolibri.exe) which runs Kolibri in the background, potentially on start-up
  • a small GUI which allows some basic config and control

Additionally at some point we'll also have a Windows "foreground app" similar to the Endless, Android, and macOS apps based on this repo. When this happens, it may also have its own installer.

In my opinion, we should just say "Deb package" removing the apt reference.

agreed!

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it the "installation type" we care about or the runtime app?

well, this is a part of a function called installation_type 😄 , probably knowing the runtime app is useful too, but when trying to get information from the user to solve issues, knowing how Kolibri was installed is important.

@jamalex jamalex self-requested a review October 28, 2021 17:25
@jamalex
Copy link
Member

jamalex commented Nov 17, 2021

Main thing here is updating to match the spec:
#7960 (comment)

(and, as noted in the comment, ensuring that the set of constants are treated as prefixes, rather than exact matches)

@jredrejo
Copy link
Member Author

@jamalex done according to the specs (I have updated the description of this PR accordingly).
Now it's on the respective installers to set the env var if we want to be exact, if not , the installation_type function tries to guess it. Issues for this are linked in #7957
For the version, I know how to get the version of the apk, deb and kolibri-server installers but not for the rest, so by now, the version is not returned.

Copy link
Member

@jamalex jamalex left a comment

Choose a reason for hiding this comment

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

This looks good to me overall, functionally!

I note that it seems the install_type variable is used to hold the keys from the constants, rather than the values, but we also store the value from the envvar in there. I had been imagining that the envvar passed in from the installer would be the full value (including the version, etc). Do you see any issues with that, either on the installer side (detecting version etc there, to put in the envvar) or here, with the codepaths (it seems like it would probably just skip over the other code and directly return the value from the envvar, so we'd be fine here)? It's nice having the fallback logic here just in case, too.

@jredrejo
Copy link
Member Author

jredrejo commented Nov 19, 2021

This looks good to me overall, functionally!

I note that it seems the install_type variable is used to hold the keys from the constants, rather than the values, but we also store the value from the envvar in there. I had been imagining that the envvar passed in from the installer would be the full value (including the version, etc). Do you see any issues with that, either on the installer side (detecting version etc there, to put in the envvar) or here, with the codepaths (it seems like it would probably just skip over the other code and directly return the value from the envvar, so we'd be fine here)? It's nice having the fallback logic here just in case, too.

My main concern is having envvars with spaces or other chars to separate version and installer type, I am not sure that will work correctly in the different combinations of OS/installers we have. If you prefer the installer to provide the version I'd go for one envvar for the installer type and another for the version.
I have added a KOLIBRI_INSTALLER_VERSION envvar that, if set by the installer, will be used by kolibri instead of guessing it out.

@jredrejo jredrejo merged commit f303529 into learningequality:release-v0.15.x Nov 19, 2021
@jredrejo jredrejo deleted the installation_type branch November 19, 2021 19:22
if hasattr(output, "decode"): # needed in python 2.x
output = output.decode("utf-8")
package_info = output.split("\n")
version_info = [output for output in package_info if "Version" in output]
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why this line didn't raise an issue before, but it's now causing a python 2 syntax check flake8 failure:

kolibri/utils/server.py:929:40: F812 list comprehension redefines 'output' from line 927

https://github.com/indirectlylit/kolibri/runs/4301449205?check_suite_focus=true

Perhaps this should be:

             version_info = [info for info in package_info if "Version" in info]

Weirdly, I see the linting error in my fork but not in the LE org repo.

cc @jredrejo @rtibbles

Copy link
Contributor

Choose a reason for hiding this comment

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

interesting, the check is skipped in LE but not in my repo:

https://github.com/learningequality/kolibri/runs/4301448839?check_suite_focus=true

image

Copy link
Member

Choose a reason for hiding this comment

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

Oh - probably because the path match check looks back through the history of runs (which are constrained to a specific fork) so because the learning equality repo had a test run that had previously passed for this set of files, it doesn't run again, whereas your fork didn't.

Copy link
Contributor

Choose a reason for hiding this comment

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

filed a follow-up here: #8772

Copy link
Member Author

@jredrejo jredrejo Nov 23, 2021

Choose a reason for hiding this comment

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

weird, that's not new code, it has been there since kolibri 0.11

Copy link
Member

Choose a reason for hiding this comment

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

I think it is more likely a floating linter version issue than an issue with the CI setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TODO: needs review Waiting for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update installation_type function to read from an environment variable
4 participants