-
Notifications
You must be signed in to change notification settings - Fork 24
Conversation
Should this be an ircbot plugin? I think it would be better to have a command line or web interface for this. Or perhaps it should be part of |
it's a database, so we can still easily build a command line or web interface for this should someone want to. I thought about putting it in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for actually taking initiative on this :)
However, I would have to agree with @dkess that ircbot is not the appropriate place to host a shorturl service. If anything, I would make this a separate service running on Kubernetes. This way:
- You can run more than one instance of this service
- If ircbot goes down, it doesn't take the shortlink service with it
Having a plugin to manipulate shorturls from IRC sounds fine to me though.
ircbot/plugin/shorturls.py
Outdated
|
||
|
||
def register(bot): | ||
# [!-~] is all printable ascii except spaces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want shorturls to be able to contain ?
, &
, or =
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...Well now this won't allow hyphens or underscores. Methinks those are still useful characters.
(Also I think you need to update the comment)
I'm not particularly a fan of the redirector living in ircbot either - certainly, in the long term, we are overloading ircbot with functionality that ought to live elsewhere. However, right now, here's the nice thing about this approach: transitioning to a dedicated shorturl redirect service is trivial. I'll write it myself when Kubernetes is ready. All we'd have to do is change the rule in puppet from redirect Considering the length of time over which we've repeatedly bikeshed the right way to engineer this dead simple system, if we ever want to actually implement this feature, I think we need to get something up that works and meets our needs and iterate on it to improve it rather than relegating it to development hell. We already have some services working in dev on k8s - templates, mastodon. keur even has a provisional ocfweb working on k8s. It shouldn't be long until we have prod services running on k8s, at which point I'll transition the redirector. I'm willing to live with suboptimal design for a short period of time in order to get the feature up so we can make use of it this semester rather than continuing to wait and invariably ending up with the feature once again not being implemented. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am also unsure about if this is the right approach but I'm up for giving it a shot since it is pretty minimal.
Is there a record of the DB schema anywhere? Is that something we do?
'UPDATE shorturls SET slug = %s WHERE slug = %s', | ||
(new_slug, old_slug), | ||
) | ||
msg.respond('shorturl `{}` has been renamed to `{}`'.format(old_slug, new_slug)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens when the old slug does not exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nothing, the where clause doesn't match anything so it's a no-op
'UPDATE shorturls SET target = %s WHERE slug = %s', | ||
(new_target, slug), | ||
) | ||
msg.respond('shorturl `{}` updated'.format(slug)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
likewise, what happens when the slug does not exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ibid
ircbot/plugin/help.py
Outdated
@@ -10,7 +10,8 @@ | |||
def register(bot): | |||
threading.Thread(target=help_server, args=(bot,), daemon=True).start() | |||
bot.listen(r'^help$', help, require_mention=True) | |||
bot.listen(r'^macros$', help_macro, require_mention=True) | |||
bot.listen(r'^macros?$', help_macro, require_mention=True) | |||
bot.listen(r'^shorturls?$', help_shorturls, require_mention=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we plan to have any authentication before deleting shorturls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, I would try to limit deletion to ops or half-ops (do we even have half-ops?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same with replacement and similar non-adding commands
@abizer if it were up to me I'd write the dedicated shortlink service now and run it on Marathon if Kubernetes isn't ready yet. My two cents... |
I gotta +1 everyone else, I think serving redirects from the ircbot is just a bit too crazy. What if you instead configure death to proxy the shorturls to some PHP script hosted in |
Or just put the redirects themselves in ocfweb, which has 3 instances and should be highly available, and have the getting/setting still added here. Wouldn't be too bad to implement since it'd only have to read/write from the db to make the redirects so the ocfweb part would be pretty minimal. Honestly I think it's the cleanest solution that fits with our current setup... |
putting the bouncer in ocfweb seems like a good idea |
ircbot/plugin/shorturls.py
Outdated
return | ||
|
||
if len(slug) > 255: | ||
msg.respond('shorturl slugs must be <= 255 characters') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this unfairly discriminates against all of those massive facebook URLs with a million query parameters! how else will Big ZUCC be able to do the machine learnings to see how people are clicking the links? /s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this only limits the size of the slug itself, not the target
I do love me some schematized data, we can at least store some random .sql file somewhere in git |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this lgtm assuming we don't serve from the ircbot. I also still think there should be other ways of adding shorturls, but this is fine for now.
ircbot/plugin/shorturls.py
Outdated
bot.listen(r'^!shorturl add ([\w/]+) (.+)$', add, require_privileged_oper=True) | ||
bot.listen(r'^!shorturl delete ([\w/]+)$', delete, require_privileged_oper=True) | ||
bot.listen(r'^!shorturl rename ([\w/]+) ([\w/]+)$', rename, require_privileged_oper=True) | ||
bot.listen(r'^!shorturl replace ([\w/]+) (.+)$', replace, require_privileged_oper=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace and rename aren't necessary IMO, if we want to change the shorturls we should just delete and re-add
ircbot/plugin/shorturls.py
Outdated
|
||
|
||
def retrieve(bot, slug): | ||
"""Reusable function to retrieve a shorturl by slug from the DB.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need the bot
param?
Thanks again for taking the initiative on this. I approve of the basic structure of this as it now stands; I still think there are minor points that still ought to be addressed, which I've commented on. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm assuming this is tested
let the bikeshedding begin
this basically does s/macro/shorturl/ on macros.py to build a database-backed, written-in-python, lives-on-marathon, accessible-through-ircbot, avoids-username-collisions simple redirect system for shorturls. as far as I remember, those conditions address every criticism of the previous approaches (ocf/puppet#253). this is designed to be used along with a formal puppet-based shorturl rule that looks something like
e.g. Apache on death returns a 302 to ircbot which returns a 302 to the real destination.
perhaps a new staffer can work on applying #56 to this along with the other plugins