Repository navigation
Account for new EU region - #901
Conversation
Deploying logfire-docs with
|
| Latest commit: |
9749707
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://005d3841.logfire-docs.pages.dev |
| Branch Preview URL: | https://regions.logfire-docs.pages.dev |
|
I changed the logic related to regions and tokens in the last commit. The implementation in
|
alexmojaki
left a comment
There was a problem hiding this comment.
I think that deriving the base URL from the write token is still entirely separate from dealing with user tokens, in which case this should be split into two PRs
b751aed to
4a93a76
Compare
| logfire_url = args.logfire_url | ||
| logfire_url = _get_logfire_url(args.logfire_url, args.region) | ||
| if logfire_url is None: | ||
| _, logfire_url = LogfireCredentials._get_token_data() # type: ignore |
There was a problem hiding this comment.
Perhaps _get_token_data() should be made "public".
There was a problem hiding this comment.
LogfireCredentials.create_new_project already calls _get_token_data, which makes sense, so you shouldn't need this.
There was a problem hiding this comment.
The issue is I need the URL to then call _write_credentials() 😕 :
logfire/logfire/_internal/cli.py
Lines 305 to 318 in 4a93a76
There was a problem hiding this comment.
ok that doesn't need to be fixed here but this is a sign of messy logic that doesn't need to be this way, the other place where create_new_project gets called ends up following a similar path including write_creds_file
There was a problem hiding this comment.
Yes I mentioned this in #901 (comment), after the region launch we can revisit
There was a problem hiding this comment.
yes but what i'm saying is that unlike what you said there this logic is not necessary
I'm not sure this is possible as changes seems to be tied up and inter-dependent. I'll note that the logic is starting to be quite confusing, lots of indirection is happening especially on logic related to base URL creation (for instance in some CLI commands such as |
| data_dir = Path(args.data_dir) | ||
| param_manager = ParamManager.create(data_dir) | ||
| base_url = param_manager.load_param('base_url', args.logfire_url) | ||
| base_url = param_manager.load_param('base_url', _get_logfire_url(args.logfire_url, args.region)) |
There was a problem hiding this comment.
Not for this PR, but load_param should probably be used for all commands, so that the env var LOGFIRE_BASE_URL always works.
| logfire_url = args.logfire_url | ||
| logfire_url = _get_logfire_url(args.logfire_url, args.region) | ||
| if logfire_url is None: | ||
| _, logfire_url = LogfireCredentials._get_token_data() # type: ignore |
There was a problem hiding this comment.
LogfireCredentials.create_new_project already calls _get_token_data, which makes sense, so you shouldn't need this.
| global_opts.add_argument('--logfire-url', default=LOGFIRE_BASE_URL, help=argparse.SUPPRESS) | ||
| url_or_region_grp = global_opts.add_mutually_exclusive_group() | ||
| url_or_region_grp.add_argument('--logfire-url', help=argparse.SUPPRESS) | ||
| url_or_region_grp.add_argument('--region', choices=REGIONS, help='the region to use') |
There was a problem hiding this comment.
logfire auth -h doesn't show --region
There was a problem hiding this comment.
--region is attached to the global parser, it will show up when doing logfire --help (and should be specified as logfire --region eu/us auth).
There was a problem hiding this comment.
Can we not improve this?
There was a problem hiding this comment.
anyway i guess we leave it for another PR
There was a problem hiding this comment.
Can we not improve this?
I can relatively easily move the two mutually exclusive --logfire-url and --region options for each command.
| cmd_info.set_defaults(func=parse_info) | ||
|
|
||
| namespace = parser.parse_args(args) | ||
| namespace.logfire_url = _get_logfire_url(namespace.logfire_url, namespace.region) |
There was a problem hiding this comment.
ok this might have been a mistake, e.g. logfire whoami now asks me which region i want, when i want it to tell me based on the write token
There was a problem hiding this comment.
It seems to me that something is inconsistent here: the ParamManager instance created in the whoami command (that then load_param the token) is reading from a pyproject.toml file. Is it expected for a token to be present in pyproject.toml files? Should we then also call LogfireCredentials.load_creds_file()?
There was a problem hiding this comment.
the token can't be in pyproject, but everything else can, and the token can be in env vars. and yes we also want load_creds_file.
There was a problem hiding this comment.
Hum so as it stands whoami will try to read token from the pyproject. I looked and it is the only place where param_manager.load_param('token') is used, so I can easily replace the logic with load_creds_file().
|
|
||
|
|
||
| @pytest.fixture | ||
| def multiple_credentials(tmp_path: Path) -> Path: |
There was a problem hiding this comment.
These two new fixtures should be used in both test_cli and test_configure
There was a problem hiding this comment.
test_cli monkeypatches _get_user_token_data() everywhere as _get_user_token_data() is unit tested in test_configure (and these fixtures are relevant to test it). Not ideal, but this would have introduced more changes to this PR.
There was a problem hiding this comment.
ok but at least we should test that logfire whoami doesn't ask the user for a region when there are multiple credentials.
This goes hand in hand with a backend PR (private) that adds a region prefix to tokens.