Added 2nd and 3th steps of tutorial
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
What we've done?
|
||||
================
|
||||
|
||||
**Senior**
|
||||
|
||||
Ey, I come from seeing our project team mates. They're delighted with their
|
||||
new toy, but they miss something.
|
||||
|
||||
I forgot to tell you that after the backup run they need to review the log
|
||||
file to check that all went ok.
|
||||
|
||||
**Junior**
|
||||
|
||||
Makes sense. Do you think that Kapow! can help with this? I feel that this is
|
||||
the way to do it.
|
||||
|
||||
**Senior**
|
||||
|
||||
Sure! Lets take a look at the documentation to see how can we tweak with the
|
||||
logic of the request.
|
||||
|
||||
**Junior**
|
||||
|
||||
Got it! There're a
|
||||
`lot of resources to work with </theory/resource_tree.rst>`_, I see that we
|
||||
can write to the response, do you think this will work for us?
|
||||
|
||||
**Senior**
|
||||
|
||||
Yeah, they used to cat the log file contents to see what happened in the
|
||||
last execution:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ cat /tmp/backup_db.log
|
||||
|
||||
I've make it easy for you, do you dare to do it?
|
||||
|
||||
**Junior**
|
||||
|
||||
Let me try add this to our ``POW`` file:
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
kapow route add /db/backup_logs -e cat /tmp/backup_db.log | kapow set /response/body
|
||||
|
||||
**Senior**
|
||||
|
||||
Looks good to me, clean and simple, and it is a very good idea to use ``GET``
|
||||
this as it wont change anything in the server. Restart Kapow! and try it.
|
||||
|
||||
**Junior**
|
||||
|
||||
Wooow! I get back the content of the file. If they liked the first one they're
|
||||
going to love this.
|
||||
|
||||
**Senior**
|
||||
|
||||
Agree. we've done the day with this...
|
||||
@@ -0,0 +1,70 @@
|
||||
What we've done?
|
||||
================
|
||||
|
||||
**Senior**
|
||||
|
||||
Hi guy! How're you doing this morning? I've got a new challenge from our
|
||||
grateful mates.
|
||||
|
||||
As time goes on from the last rotation the size of the log file gets bigger.
|
||||
Furthermore, they want to limit the output of the file to pick only some
|
||||
records and only from the end of the file. We need to do something to help
|
||||
them as they waste a lot of time reviewing the output.
|
||||
|
||||
**Junior**
|
||||
|
||||
My two cents is that this time is going to be more of a deep bash knowledge.
|
||||
Do you agree?
|
||||
|
||||
**Senior**
|
||||
|
||||
By sure, but in addition to some good shell plumbing we're going to squeeze
|
||||
Kapow!'s superpowers a litle bit more to get a really good solution.
|
||||
|
||||
Can you take a look at Kapow!'s documentation to see if something can be done?
|
||||
|
||||
**Junior**
|
||||
|
||||
I've seen in the documentation and there is a way to get access to the data
|
||||
comming in the request. Do you think we can use this to let them choose how
|
||||
to do the filtering?
|
||||
|
||||
**Senior**
|
||||
|
||||
Sounds great! How could we live without Kapow! all this time?
|
||||
|
||||
As they requested, we can offer them with a parameter to filter the registers
|
||||
they want to pick and another parameter to limit the output size in lines.
|
||||
|
||||
**Junior**
|
||||
|
||||
Sounds that will be enough. Now we have to make some modifications to our
|
||||
last endpoint definition to add this new feature. Let's start working...
|
||||
|
||||
**Senior**
|
||||
|
||||
Well, we got it again, this is exactly what they need:
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
kapow route add /db/backup_logs -e grep "$(kapow get /request/params/filter)" /var/log/backup_db.log \
|
||||
| tail -n "$(kapow get /request/params/lines)" \
|
||||
| kapow set /response/body
|
||||
|
||||
It looks a bit weird but we'll have time to re-styling later. Please make
|
||||
some tests on your laptop before to publish on the *Corporate Server*.
|
||||
Remember to send them an example URL with the parameters the can use to
|
||||
filter.
|
||||
|
||||
**Junior**
|
||||
|
||||
Ok, Should look like this, isn't it?
|
||||
|
||||
.. code-block:: console
|
||||
|
||||
$ curl http://localhost:8080/db/backup_logs?filter=rows%20inserted&lines=200
|
||||
|
||||
**Senior**
|
||||
|
||||
Exactly. Another great day helping the company to advance. Let's go for a
|
||||
beer for celebrating!
|
||||
Reference in New Issue
Block a user