Coder Social home page Coder Social logo

apache / openwhisk-package-alarms Goto Github PK

View Code? Open in Web Editor NEW
24.0 39.0 49.0 443 KB

Apache OpenWhisk package that can be used to create periodic, time-based alarms.

Home Page: https://openwhisk.apache.org/

License: Apache License 2.0

JavaScript 60.20% Shell 5.65% Scala 33.55% Dockerfile 0.59%
openwhisk apache serverless faas functions-as-a-service cloud serverless-architectures serverless-functions

openwhisk-package-alarms's Introduction

Apache OpenWhisk Alarm Package

License Build Status

The /whisk.system/alarms package can be used to fire a trigger at a specified frequency. Alarms are useful for setting up recurring jobs or tasks, such as invoking a system backup action every hour.

The package includes the following feeds.

Entity Type Parameters Description
/whisk.system/alarms package - Alarms and periodic utility.
/whisk.system/alarms/interval feed minutes, trigger_payload, startDate, stopDate Fire Trigger event on an interval based schedule.
/whisk.system/alarms/once feed date, trigger_payload, deleteAfterFire Fire Trigger event once on a specific date.
/whisk.system/alarms/alarm feed cron, trigger_payload, startDate, stopDate Fire Trigger event on a time-based schedule using cron.

Firing a trigger event periodically on an interval based schedule

The /whisk.system/alarms/interval feed configures the Alarm service to fire a Trigger event on an interval based schedule. The parameters are as follows:

  • minutes (required): An integer representing the length of the interval (in minutes) between trigger fires.

  • trigger_payload (optional): The value of this parameter becomes the content of the Trigger every time the Trigger is fired.

  • startDate (optional): The date when the first trigger will be fired. Subsequent fires will occur based on the interval length specified by the minutes parameter.

  • stopDate (optional): The date when the Trigger will stop running. Triggers will no longer be fired once this date has been reached.

    Note: The startDate and stopDate parameters support an integer or string value. The integer value represents the number of milliseconds since 1 January 1970 00:00:00 UTC and the string value should be in the ISO 8601 format (http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15).

The following example creates a trigger that is fired once every 2 minutes. The Trigger fires as soon as possible, and will stop firing January 31, 2019, 23:59:00 UTC.

wsk trigger create interval \
  --feed /whisk.system/alarms/interval \
  --param minutes 2 \
  --param trigger_payload "{\"name\":\"Odin\",\"place\":\"Asgard\"}" \
  --param stopDate "2019-01-31T23:59:00.000Z"

Each generated event includes parameters, which are the properties that are specified by the trigger_payload value. In this case, each Trigger event has the parameters name=Odin and place=Asgard.

Firing a trigger event once

The /whisk.system/alarms/once feed configures the Alarm service to fire a trigger event on a specified date. The parameters are as follows:

  • date (required): The date when the Trigger will be fired. The Trigger will be fired just once at the given time.

    Note: The date parameter supports an integer or string value. The integer value represents the number of milliseconds since 1 January 1970 00:00:00 UTC and the string value should be in the ISO 8601 format (http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15).

  • trigger_payload (optional): The value of this parameter becomes the content of the Trigger when the Trigger is fired.

  • deleteAfterFire (optional, default: false): The value of this parameter determines whether the Trigger and potentially all of its associated rules will be deleted after the Trigger is fired.

    • false: No action will be taken after the Trigger fires.
    • true: The Trigger will be deleted after it fires.
    • rules: The Trigger and all of its associated rules will be deleted after it fires.

The following is an example of creating a trigger that will be fired once on December 25, 2019, 12:30:00 UTC. After the Trigger fires it will be deleted as well as all of its associated rules.

wsk trigger create fireOnce \
  --feed /whisk.system/alarms/once \
  --param trigger_payload "{\"name\":\"Odin\",\"place\":\"Asgard\"}" \
  --param date "2019-12-25T12:30:00.000Z" \
  --param deleteAfterFire "rules"

Firing a Trigger on a time-based schedule using cron

The /whisk.system/alarms/alarm feed configures the Alarm service to fire a Trigger event at a specified frequency. The parameters are as follows:

  • cron (required): A string, based on the UNIX crontab syntax that indicates when to fire the Trigger in Coordinated Universal Time (UTC). The string is a sequence of five fields that are separated by spaces: X X X X X. For more information, see: http://crontab.org. The following strings are examples that use varying duration's of frequency.

    • * * * * *: The Trigger fires at the top of every minute.
    • 0 * * * *: The Trigger fires at the top of every hour.
    • 0 */2 * * *: The Trigger fires every 2 hours (that is, 02:00:00, 04:00:00, ...).
    • 0 9 8 * *: The Trigger fires at 9:00:00AM (UTC) on the eighth day of every month.

    Note: The parameter cron supports five or six fields. Not all OpenWhisk vendors may support 6 fields so please check their documentation for support. For more details about using this custom cron syntax, see: https://github.com/ncb000gt/node-cron. Here is an example using six fields notation:

    • */30 * * * * *: every thirty seconds.
  • trigger_payload (optional): The value of this parameter becomes the content of the Trigger every time the Trigger is fired.

  • timezone (optional): This will modify the actual time relative to the specified timezone. If the timezone is invalid, an error is thrown. You can check all timezones available at the Moment Timezone Website (http://momentjs.com/timezone/docs/#/data-loading/getting-zone-names/).

  • startDate (optional): The date when the Trigger will start running. The Trigger fires based on the schedule specified by the cron parameter.

  • stopDate (optional): The date when the Trigger will stop running. Triggers are no longer fired once this date is reached.

    Note: The startDate and stopDate parameters support an integer or string value. The integer value represents the number of milliseconds since 1 January 1970 00:00:00 UTC, and the string value should be in the ISO 8601 format (http://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.15).

The following is an example of creating a trigger that fires once every 2 minutes with name and place values in the trigger event. The Trigger will not start firing until January 1, 2019, 00:00:00 UTC and will stop firing January 31, 2019, 23:59:00 UTC.

wsk trigger create periodic \
  --feed /whisk.system/alarms/alarm \
  --param cron "*/2 * * * *" \
  --param trigger_payload "{\"name\":\"Odin\",\"place\":\"Asgard\"}" \
  --param startDate "2019-01-01T00:00:00.000Z" \
  --param stopDate "2019-01-31T23:59:00.000Z"

Note: The parameter maxTriggers is deprecated and will be removed soon. To stop the Trigger, use the stopDate parameter.

  • strict (optional): A boolean value that decides to add a few seconds to the Trigger. This work with only five-field cron alarms.

    • If it's true, the Trigger will fire at the top of the hour/minute (**:**:00).
    • Otherwise, the Trigger will fire after the specific seconds (**:**:00-59).
    • If you do not set this value, it is set to the default chosen by the operator.
    • Optionally, string values, "true" and "false" are also recognized as boolean values.

The delay is determined by the hash value of the Trigger's name, so it keeps the same interval before and after the (re)deployment.

Note This option can be helpful to avoid thundering herds when the second-unit errors are not critical.

Building from Source

To build this package from source, execute the command ./gradlew distDocker

openwhisk-package-alarms's People

Contributors

abaruni avatar anthonyamanse avatar cbickel avatar chetanmeh avatar csantanapr avatar dgrove-oss avatar dubee avatar jasonpet avatar jbampton avatar jiangpengcheng avatar johnsolm avatar keonhee avatar machenity avatar markusthoemmes avatar mhenke1 avatar moritzraho avatar mrutkows avatar nikolaystarodubtsev avatar ningyougang avatar rabbah avatar style95 avatar upgle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

openwhisk-package-alarms's Issues

increase default trigger fire limit

As previously discussed, we intend to bump the default limit for alarm triggers to 1 million.
Marking critical as users are being affected and we should do this ASAP.

ENOTFOUND when creating an alarm trigger

I'm trying to create a cron trigger using this command:
wsk trigger create mytrigger --feed /whisk.system/alarms/alarm --param cron '0 * * * *'

However I get what seems to be a DNS related error:

{
    "activationId": "1d2cf4e1d23b4699acf4e1d23ba69952",
    "annotations": [
        {
            "key": "path",
            "value": "whisk.system/alarms/alarm"
        },
        {
            "key": "waitTime",
            "value": 114
        },
        {
            "key": "kind",
            "value": "nodejs:6"
        },
        {
            "key": "timeout",
            "value": false
        },
        {
            "key": "limits",
            "value": {
                "concurrency": 1,
                "logs": 10,
                "memory": 256,
                "timeout": 60000
            }
        }
    ],
    "duration": 12,
    "end": 1602630229302,
    "logs": [],
    "name": "alarm",
    "namespace": "whisk.system",
    "publish": false,
    "response": {
        "result": {
            "error": {
                "code": "ENOTFOUND",
                "errno": "ENOTFOUND",
                "host": "https",
                "hostname": "https",
                "message": "getaddrinfo ENOTFOUND https https:443",
                "name": "Error",
                "port": 443,
                "stack": "Error: getaddrinfo ENOTFOUND https https:443\n    at errnoException (dns.js:28:10)\n    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)",
                "syscall": "getaddrinfo"
            }
        },
        "size": 344,
        "status": "application error",
        "success": false
    },
    "start": 1602630229290,
    "subject": "whisk.system",
    "version": "0.0.1"
}
{
    "activationId": "438b0b2ac7ec4c3a8b0b2ac7ecbc3a46",
    "annotations": [
        {
            "key": "path",
            "value": "whisk.system/alarms/alarm"
        },
        {
            "key": "waitTime",
            "value": 26
        },
        {
            "key": "kind",
            "value": "nodejs:6"
        },
        {
            "key": "timeout",
            "value": false
        },
        {
            "key": "limits",
            "value": {
                "concurrency": 1,
                "logs": 10,
                "memory": 256,
                "timeout": 60000
            }
        }
    ],
    "duration": 17,
    "end": 1602630229380,
    "logs": [],
    "name": "alarm",
    "namespace": "whisk.system",
    "publish": false,
    "response": {
        "result": {
            "error": {
                "code": "ENOTFOUND",
                "errno": "ENOTFOUND",
                "host": "https",
                "hostname": "https",
                "message": "getaddrinfo ENOTFOUND https https:443",
                "name": "Error",
                "port": 443,
                "stack": "Error: getaddrinfo ENOTFOUND https https:443\n    at errnoException (dns.js:28:10)\n    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)",
                "syscall": "getaddrinfo"
            }
        },
        "size": 344,
        "status": "application error",
        "success": false
    },
    "start": 1602630229363,
    "subject": "whisk.system",
    "version": "0.0.1"
}
ok: deleted trigger mytrigger

The host parameter looked off so I checked the environment configuration, but it looks ok.

root@openwhisk-alarmprovider-fccf54c4f-vxwzf:/# echo $ENDPOINT_AUTH
openwhisk.mydomain.org:443
root@openwhisk-alarmprovider-fccf54c4f-vxwzf:/# echo $ROUTER_HOST
openwhisk.mydomain.org:443

I also verified that DNS does work.

root@openwhisk-alarmprovider-fccf54c4f-dhgll:/# node
> dns.resolve('www.google.com', (error, addresses) => { console.error(error); console.log(addresses); });
QueryReqWrap {
  bindingName: 'queryA',
  callback: [Function],
  hostname: 'www.google.com',
  oncomplete: [Function: onresolve],
  ttl: false,
  domain:
   Domain {
     domain: null,
     _events:
      [Object: null prototype] {
        removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [],
     [Symbol(kWeak)]: WeakReference {} },
  channel:
   ChannelWrap {
     domain:
      Domain {
        domain: null,
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        members: [],
        [Symbol(kWeak)]: WeakReference {} } } }
> null
[ '216.58.195.68' ]

I'm running this on Openwhisk installed on Kubernetes using the Helm chart, and configured to use the openwhisk/alarmprovider:2.2.0 image. Here is my Helm config (I changed some variables, including the domain, for security reasons):

whisk:
  ingress:
    domain: openwhisk.mydomain.org
    apiHostName: openwhisk.mydomain.org
    apiHostPort: 443
    apiHostProto: https
    type: Standard
    # annotations:
    #   traefik.ingress.kubernetes.io/router.entrypoints: websecure
    #   traefik.ingress.kubernetes.io/router.tls: "true"
  auth:
    system: "mysystemtoken"
    guest: "myguesttoken"
  containerPool:
    userMemory: "10240m"
  limits:
    actionsInvokesConcurrent: 200
    actionsInvokesPerminute: 200
    triggersFiresPerminute: 200
    actions:
      time:
        max: "60m"
      memory:
        max: "8192m"
      concurrency:
        max: 4
k8s:
  dns: kube-dns.kube-system
docker:
  registry:
    name: "myregistry"
    username: "myusername"
    password: "mypassword"
zookeeper:
  replicaCount: 3
kafka:
  replicaCount: 3
db:
  external: true
  wipeAndInit: true
  protocol: "http"
  host: "couchdb-svc-couchdb.couchdb.svc.cluster.local"
  port: 5984
  auth:
    username: "myusername"
    password: "mypassword"
nginx:
  httpsNodePort: 443
  replicaCount: 3
controller:
  replicaCount: 3
invoker:
  jvmHeapMB: "2048"
  containerFactory:
    impl: "docker"
    enableConcurrency: true

Any help would be appreciated.

Alarms package documentation refers to node-cron rather than cron

@hassenius commented on Fri Jan 27 2017

The documentation for the alarms package refers to the format of node-cron (for example second field is optional)
https://github.com/openwhisk/openwhisk/blob/master/docs/catalog.md#firing-a-trigger-event-periodically

However, looking at the source, alarms uses the cron package:
https://github.com/openwhisk/openwhisk-package-alarms/blob/master/package.json
Which seems to require 6 fields, etc

Cron package documentation
https://www.npmjs.com/package/cron


@rabbah commented on Fri Feb 24 2017

@csantanapr @jasonpet move?

Hardcoded HTTPS used on uriHost causing SSL error

The Utils.js has a hardcoded https as the prefix for this.uriHost:

this.uriHost ='https://' + this.routerHost;

This means that when using an internal routerHost within k8S, the trigger fails with a:

SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332:\n","stack":"Error: write EPROTO 139863444719424:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:../deps/openssl/openssl/ssl/record/ssl3_record.c:332

Use standard output for alarm logs

The image built based on Dockerfile in the root folder is not runnable now because /logs/alarmsTrigger_logs.log is not exist.

Below changes are an option to fix this issue.

--- a/Dockerfile
+++ b/Dockerfile
@@ -16,10 +16,11 @@ RUN apt-get update --fix-missing && \
 # only package.json
 ADD package.json /alarmsTrigger/
 RUN cd /alarmsTrigger; npm install
+RUN touch ~/alarmsTrigger_logs.log

 # App
 ADD provider/. /alarmsTrigger/

 EXPOSE 8080

-CMD ["/bin/bash", "-c", "node /alarmsTrigger/app.js >> /logs/alarmsTrigger_logs.log 2>&1"]
+CMD ["/bin/bash", "-c", "node /alarmsTrigger/app.js >> ~/alarmsTrigger_logs.log 2>&1"]

Triggers should not be deleted on timeout

If the backend returns a 408 (request timed out) when attempting to fire a trigger the provider should not be so eager to delete. Currently, it retries 5 times (should be more) and if it still can't it will delete the trigger. We should not delete on a 408 since there may be a cloudant/couchdb outage. The code needs to be tightened up to only delete when appropriate.

how to get this into my current install of openwhisk

I tried to use the installCatalog.sh to install this package but I'm not sure what to put for the alarm trigger host and port. I tried using the same ip as my api host and tried a bunch of values for the ports (whatever I found running as a tcp port with docker-proxy) but it's not working. How can I get this package to work for me? The README.md doesn't explain how to install this package. I also tried ./gradlew distDocker which did installs the docker image but doesn't have instructions on how to get the container running.

[Question] How to switch active hosts?

Currently, A provider consists of two replications, host0 and host1.
and I understand that only active hosts can fire trigger.

but, I wonder how to switch active hosts when the active host is dead.

For example, if host0 is dead, how to transfer active status to host1?
Although /active exists, there is no client for this.

How do you operate it?

Add unit tests

We need at least a set of unit tests for a minimum sanity check.

can not compile successfully

  • when I run CLI "./gradlew distDocker", it can not run successfully, the error is as below:

  • ./gradlew distDocker

The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
at docker_7r8ejptnt4f4tnx46yncyk4ag.run(/home/zhy/iot/incubator-openwhisk-package-alarms/gradle/docker.gradle:43)

FAILURE: Build failed with an exception.

  • Where:
    Build file '/home/zhy/iot/incubator-openwhisk-package-alarms/tests/build.gradle' line: 28

  • What went wrong:
    A problem occurred evaluating project ':tests'.

Could not get unknown property 'sourceSets' for project ':whisktests' of type org.gradle.api.Project.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 1.51 secs

No alarm when openwhisk runs on different port

When the openwhisk API runs on a different port than 443 it seems that periodic alarms don't work anymore. From the log you can see that the alarm action connects to the default port:

[ERROR] [??] [alarmsTrigger] [postTrigger] there was an error invoking xxxxxxxx/guest/test_alarm {"message":"connect ECONNREFUSED 172.17.0.1:443","stack":"Error: connect ECONNREFUSED 172.17.0.1:443\n at Object._errnoException (util.js:1022:11)\n at _exceptionWithHostPort (util.js:1044:20)\n at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)","code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","address":"172.17.0.1","port":443}

To adjust the port on install I changed the following:

  • environment variable ROUTER_HOST in the alarmtrigger container
  • EDGE_HOST and API_HOST provided to ./installCatalog.sh

The installation finished without errors and except from the different port openwhisk runs in default local deployment. Firing a trigger manually works but the cron jobs don't. Any ideas which configuration is missing?

Cron is fired after trigger deletion

Hi,

I was searching for an existing issue, could not find any.
The problem is that we periodically see that Alarms package is firing the triggers that were deleted. Here is an example:

[2017-09-11T00:45:02.501Z] [INFO] [??] [alarmsTrigger] [deleteTrigger] trigger xxxxxxxx/[email protected]/dummyAlarmsTrigger-1505090685500 successfully deleted from memory

[2017-09-11T00:45:11.357Z] [INFO] [??] [alarmsTrigger] [fireTrigger] Trigger xxxxxxxx/[email protected]/dummyAlarmsTrigger-1505090685500 was successfully fired

I have quickly scanned the code, could not find any obvious reason. Hopefully you could help to shed light here.

Thats the alarmsFeedTests.scala in blue.

Thanks,
Vadim.

[Suggestion] Add delays of a few seconds before firing triggers

I ran 600 alarms with cron */1 * * * * on the provider and the thundering herd arised:

스크린샷 2019-08-09 오후 2 11 50

All triggers were fired every minute on the minute, so CPU usage of the provider peaked every minutes. I think it could result in harm on management. To deal with the problem, it is necessary to distribute the firings within every minutes.

I suggest adding a few seconds delay before firing.

In my suggestion, two alterations will be needed in part of parameter and scheduler.

In part of parameter, a new paramter strict that takes boolean value is added.

  • If strict is true, the alarm will be fired at the reserved time sharp (**:**:00). (same as ever)
  • If false, the alarm will be scheduled with distribution (**:**:00-59).

In part of scheduler, It needs a hash function that takes a name as a key and returns an integer in the range of 0 to 59. When the alarm trigger is created, scheduler injects the value that the hash function returns to newTrigger.cron. For example, if the hash function returns 30 and the cron of the trigger is */10 * * * *, the cron will be converted like this: 30 */10 * * * * . It works because the library node-cron which we used supports sixth field for second.

Using hash function can bring some benefits. Because of the characteristics of hash, we can keep the same delay time among hosts or before and after redeployment of providers without using DB or consensus.

I think the level of peaks decreased if the suggestion is implemented, that leads to keep better condition on the machine running providers. Google uses the similar way to distribute Cron jobs in their systems.

strict option does not work

I created alarm trigger with strict=true

wsk trigger create periodic28 \
    --feed /whisk.system/alarms/alarm \
    --param cron "*/1 * * * *" \
    --param trigger_payload "{\"name\":\"Odin\",\"place\":\"Asgard\"}" \
    -p strict true
ok: invoked /whisk.system/alarms/alarm with id deb8f8316cbd4be9b8f8316cbd7be9eb
ok: created trigger periodic28

If the strict = true is given, the cron job should run in 0 seconds, which is actually created with a value of 13 * / 1 * * * *.

[2020-03-06T04:09:25.695Z] [INFO] [worker1] [lambda-alarm-worker1-test-76cc465994-xsh7j] [alarmsTrigger] [setupFollow] got change for trigger xxxxxxxx/geonhui/periodic28
[2020-03-06T04:09:25.696Z] [INFO] [worker1] [lambda-alarm-worker1-test-76cc465994-xsh7j] [alarmsTrigger] [distributeCronAlarm] xxxxxxxx/geonhui/periodic28 is converted to "13 */1 * * * *"
[2020-03-06T04:09:25.696Z] [INFO] [worker1] [lambda-alarm-worker1-test-76cc465994-xsh7j] [alarmsTrigger] [scheduleCronAlarm] xxxxxxxx/geonhui/periodic28 starting cron job
[2020-03-06T04:09:25.697Z] [INFO] [worker1] [lambda-alarm-worker1-test-76cc465994-xsh7j] [alarmsTrigger] [setupFollow] xxxxxxxx/geonhui/periodic28 created successfully

Could not get unknown property 'sourceSets' for project ':whisktests' of type org.gradle.api.Project.

Whilw running the following command for building
./gradlew :distDocker
getting below error
The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.
at docker_eaj445q4b51jflwc79mnh75jr.run(/home/nokia/openwhisk/pkg-alarm-mk/incubator-openwhisk-package-alarms/gradle/docker.gradle:43)

FAILURE: Build failed with an exception.

  • Where:
    Build file '/home/nokia/openwhisk/pkg-alarm-mk/incubator-openwhisk-package-alarms/tests/build.gradle' line: 28

  • What went wrong:
    A problem occurred evaluating project ':tests'.

Could not get unknown property 'sourceSets' for project ':whisktests' of type org.gradle.api.Project.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Enhance once trigger to delete trigger and rules for user

The new trigger should accept two new optional parameters.

  1. A boolean parameter to indicate to delete the trigger some time after the trigger fire
    potential name for parameter: deleteAfterFire
    this can be default to true
  2. A an array of strings with rules to delete some time after the trigger fire
    potential name for parameter: rulesToDelete
    this parameter is invalid if deleteAfterFire is false

log message should have trigger name on trigger not found in DB

User reported on a lifecycle DELETE for /whisk.system/alarms/once
He inspecting logs after the facts and see a few of these but logs don't have good info for debugging like the trigger name.

"2018-01-21T17:09:13.091227454Z stdout: alarm: Error invoking whisk action: 404 { error: 'could not find the trigger in the database' }"

This message is printed in getTrigger function which is called after verifying auth that user owns the trigger, so I think is sane to add the trigger name to the error message
https://github.com/apache/incubator-openwhisk-package-alarms/blob/master/action/lib/Database.js#L79

document update conflict (409) when deleting trigger

I am seeing some alarms tests fail with a 409 error when attempting to delete an alarm trigger. This is because the alarm is being disabled at the same time as it is being deleted. The delete code needs to do some retries when receiving a 409 during deletion from the database.

Default trigger limit still 1000 in alarm feed action

@johnsolm - looks like the default trigger limit was updated in the provider code, but that is only relevant if the the alarm feed action does not set maxTriggers. However, the current feed action always sets maxTriggers to 1000 if user did not specify it.

Why is the body of web action response base64 string, not object?

In action/lib/common.js and action/alarmWebAction.js, there are web action responses which the body is bas64 string of JSON. I wonder why the body is base64 string, not the response or error object.

// https://github.com/apache/incubator-openwhisk-package-alarms/blob/master/action/lib/common.js#L100-L104
return {
    statusCode: statusCode,
    headers: { 'Content-Type': 'application/json' },
    body: new Buffer(JSON.stringify(params)).toString('base64')
};

I think the following return statement is more simple:

return {
    statusCode: statusCode,
    headers: { 'Content-Type': 'application/json' },
    body: params
};

After testing with a simple web action, I found the difference between the base64-encoded JSON string body and object body:

  • with base64 body, I get one-line JSON response like:
    {"__ow_method":"get","__ow_headers":{"host":"controllers","user-agent":"curl/7.54.0","accept":"*/*"},"__ow_path":""}
    
  • with object body, I get multi-line pretty JSON response like:
    {
      "__ow_method": "get",
      "__ow_headers": {
        "host": "controllers",
        "user-agent": "curl/7.54.0",
        "accept": "*/*"
      },
      "__ow_path": ""
    }

Is there any intent using base64-encoded JSON string body?

Change log message for disable trigger when reach maxTriggers from ERROR to WARN

When doing operations.
I see the following message

[2017-09-01T14:44:00.507Z] [ERROR] [??] [alarmsTrigger] [fireTrigger] no more triggers left, disabled xxxxxxxx/carlos_dev/trigger2_412345

I was searching for log_level ERROR and there are too many messages, I believe this is not an error, maybe it should be WARN or INFO but not ERROR.

It allows to filter down to real error messages in the provider

Add "random in range" option to alarms cron format

@paulcastro commented on Mon Nov 21 2016

There may exist use cases where scheduling an alarm to fire periodically and randomly in a range of time is useful. For example, we may want to trigger lengthy backups of several images each day, but have these backups happen at different times. In a operational environment it may be difficult to keep track of "different times." Rather than hard-code a time, it would be useful to specify fire the alarm "at a random time each day/month etc.".

Jenkins allows a job to be scheduled by a hash of the job's name (which isn't random but handles the above use case). Explanation below:


The H symbol can be used with a range. For example, H H(0-7) * * * means some time between 12:00 AM (midnight) to 7:59 AM. You can also use step intervals with H, with or without ranges.

The H symbol can be thought of as a random value over a range, but it actually is a hash of the job name, not a random function, so that the value remains stable for any given project.```


Replace the binary Wsk with REST interface WskRest

All the non-CLI related tests should sunset the wsk, and re-implement them with wskrest.

import common.wsk 
val wsk = new Wsk

need to be changed to

import common.rest.WskRest
val wsk = new WskRest

plus there may be changes to the rest of the tests as well, since the response result may have been changed.

Invoking action gives 403: Trigger authentication request failed

I have openwhisk deployed on a kubernetes cluster. I created a trigger called once-per-minute using this swagger ui,
The curl request: -

curl -X PUT "https://localhost:4430/api/v1/namespaces/_/triggers/once-per-min?overwrite=false" -H "accept: application/json" -H "authorization: Basic Nzg5YzQ2YjEtNzFmNi00ZWQ1LThjNTQtODE2YWE0ZjhjNTAyOmFiY3pPM3haQ0xyTU42djJCS0sxZFhZRnBYbFBrY2NPRnFtMTJDZEFzTWdSVTRWck5aOWx5R1ZDR3VNREdJd1A=" -H "Content-Type: application/json" -d "{\"name\":\"once-per-min\",\"annotations\":[{\"key\":\"feed\",\"value\":\"/whisk.system/alarms/alarm\"}]}"

Got Response 200

{
  "annotations": [
    {
      "key": "feed",
      "value": "/whisk.system/alarms/alarm"
    }
  ],
  "limits": {},
  "name": "once-per-min",
  "namespace": "whisk.system",
  "parameters": [],
  "publish": false,
  "updated": 1703607489753,
  "version": "0.0.1"
}

Now, I tried to create a cron job for the alarm action in whisk.system

curl -X POST "https://localhost:4430/api/v1/namespaces/whisk.system%2Falarms/actions/alarm?blocking=true&result=false" -H "accept: application/json" -H "authorization: Basic Nzg5YzQ2YjEtNzFmNi00ZWQ1LThjNTQtODE2YWE0ZjhjNTAyOmFiY3pPM3haQ0xyTU42djJCS0sxZFhZRnBYbFBrY2NPRnFtMTJDZEFzTWdSVTRWck5aOWx5R1ZDR3VNREdJd1A=" -H "Content-Type: application/json" -d "{\"authKey\":\"23bc46b1-71f6-4ed5-8c54-816aa4f8c502:123zO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP\",\"cron\":\"*/1 * * * *\",\"lifecycleEvent\":\"CREATE\",\"triggerName\":\"/_/once-per-min\"}"

Got a 502 bad gateway

{
  "activationId": "260396828cb84c158396828cb82c15b7",
  "annotations": [
    {
      "key": "path",
      "value": "whisk.system/alarms/alarm"
    },
    {
      "key": "waitTime",
      "value": 13
    },
    {
      "key": "kind",
      "value": "nodejs:10"
    },
    {
      "key": "timeout",
      "value": false
    },
    {
      "key": "limits",
      "value": {
        "concurrency": 1,
        "logs": 10,
        "memory": 256,
        "timeout": 60000
      }
    }
  ],
  "duration": 38,
  "end": 1703607625061,
  "logs": [],
  "name": "alarm",
  "namespace": "whisk.system",
  "publish": false,
  "response": {
    "result": {
      "error": {
        "error": "Trigger authentication request failed."
      }
    },
    "size": 60,
    "status": "application error",
    "success": false
  },
  "start": 1703607625023,
  "subject": "whisk.system",
  "version": "0.0.1"
}

Tried to read the activation

{
  "activationId": "260396828cb84c158396828cb82c15b7",
  "annotations": [
    {
      "key": "path",
      "value": "whisk.system/alarms/alarm"
    },
    {
      "key": "waitTime",
      "value": 13
    },
    {
      "key": "kind",
      "value": "nodejs:10"
    },
    {
      "key": "timeout",
      "value": false
    },
    {
      "key": "limits",
      "value": {
        "concurrency": 1,
        "logs": 10,
        "memory": 256,
        "timeout": 60000
      }
    }
  ],
  "duration": 38,
  "end": 1703607625061,
  "logs": [
    "2023-12-26T16:20:25.061306357Z stdout: alarm: Error invoking whisk action: 403 { error: 'Trigger authentication request failed.' }"
  ],
  "name": "alarm",
  "namespace": "whisk.system",
  "publish": false,
  "response": {
    "result": {
      "error": {
        "error": "Trigger authentication request failed."
      }
    },
    "size": 60,
    "status": "application error",
    "success": false
  },
  "start": 1703607625023,
  "subject": "whisk.system",
  "version": "0.0.1"
}

Cannot create alarms trigger

I get an openssl error when trying to create an alarms trigger. I installed the alarms package as follows (this is on a new vagrant openwhisk install):

$ ./installCatalog.sh $AUTH_KEY 172.17.0.1 $COUCHDB_HOST:$COUCHDB_PORT test $API_HOST
...
ok: updated action alarmsWeb/alarmWebAction
$ wsk package list /whisk.system
packages
/whisk.system/alarms                                                   shared
/whisk.system/watson-speechToText                                      shared
...
$ wsk action get --summary /whisk.system/alarms/alarm
action /whisk.system/alarms/alarm: Fire trigger when alarm occurs
$ wsk trigger create everyEightSeconds --feed /whisk.system/alarms/alarm -p cron "*/8 * * * * *" -p trigger_payload "{\"name\":\"Mork\", \"place\":\"Ork\"}"
ok: invoked /whisk.system/alarms/alarm with id 184b0aa219564013b4885b659f883908
{
    "activationId": "184b0aa219564013b4885b659f883908",
    "annotations": [
        {
            "key": "limits",
            "value": {
                "logs": 10,
                "memory": 256,
                "timeout": 60000
            }
        },
        {
            "key": "path",
            "value": "whisk.system/alarms/alarm"
        }
    ],
    "duration": 268,
    "end": 1499885736936,
    "logs": [],
    "name": "alarm",
    "namespace": "guest",
    "publish": false,
    "response": {
        "result": {
            "error": {
                "code": "EPROTO",
                "errno": "EPROTO",
                "syscall": "write"
            }
        },
        "status": "application error",
        "success": false
    },
    "start": 1499885736668,
    "subject": "guest",
    "version": "0.0.3"
}
ok: invoked /whisk.system/alarms/alarm with id 257f96bef7a94236a1c3eae1496b21bd
{
    "activationId": "257f96bef7a94236a1c3eae1496b21bd",
    "annotations": [
        {
            "key": "limits",
            "value": {
                "logs": 10,
                "memory": 256,
                "timeout": 60000
            }
        },
        {
            "key": "path",
            "value": "whisk.system/alarms/alarm"
        }
    ],
    "duration": 179,
    "end": 1499885737144,
    "logs": [],
    "name": "alarm",
    "namespace": "guest",
    "publish": false,
    "response": {
        "result": {
            "error": {
                "code": "EPROTO",
                "errno": "EPROTO",
                "syscall": "write"
            }
        },
        "status": "application error",
        "success": false
    },
    "start": 1499885736965,
    "subject": "guest",
    "version": "0.0.3"
}
ok: deleted trigger everyEightSeconds
$ wsk activation logs 257f96bef7a94236a1c3eae1496b21bd
2017-07-12T18:55:37.142606606Z stdout: alarm: Error invoking whisk action: { Error: write EPROTO 139767976155008:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:../deps/openssl/openssl/ssl/s23_clnt.c:794:
2017-07-12T18:55:37.142654856Z stdout:
2017-07-12T18:55:37.142659802Z stdout: at exports._errnoException (util.js:1026:11)
2017-07-12T18:55:37.142664127Z stdout: at WriteWrap.afterWrite (net.js:799:14) code: 'EPROTO', errno: 'EPROTO', syscall: 'write' }

Not sure if this has to do with my openwhisk install or this package.

Cannot create a trigger with alarm feed

I am trying to use openwhisk and the alarms package on ubuntu 14 (on one AWS EC2 instance). openwhisk is running well.

I cannot create a trigger with this alarm package, with command

wsk trigger create -i --auth ${auth.whisk.system} perMinute --feed /whisk.system/alarms/alarm --param cron "* * * * *"

with the error code saying

"code": 12268,
"error": "There was an error processing your request."

which doesn't really helpful.

Please let me know if you have any ideas about it.


Here is my settings

Step 1: Install alarm package with installCatalog.sh

WSK_HOME="$HOME/openwhisk"

SYS_AUTH=`cat $WSK_HOME/ansible/files/auth.whisk.system`

DB_HOST=`awk -F "=" '/db_host/ {print $2}' $WSK_HOME/ansible/db_local.ini`
DB_PORT=`awk -F "=" '/db_port/ {print $2}' $WSK_HOME/ansible/db_local.ini`
DB_PREFIX=`awk -F "=" '/db.prefix/ {print $2}' $WSK_HOME/whisk.properties`
EDGE_HOST=`awk -F "=" '/APIHOST/ {print $2}' $HOME/.wskprops`
API_HOST=`awk -F "=" '/APIHOST/ {print $2}' $HOME/.wskprops`

export OPENWHISK_HOME=$WSK_HOME
./installCatalog.sh $SYS_AUTH $EDGE_HOST $DB_HOST:$DB_PORT $DB_PREFIX $API_HOST

It is verified when I use wsk package to list them

 $ wsk package -i --auth ${auth.whisk.system} list
packages
/whisk.system/alarmsWeb                                                private
/whisk.system/alarms                                                   shared
...
$ wsk action -i --auth 789c46b1-71f6-4ed5-8c54-816aa4f8c502:abczO3xZCLrMN6v2BKK1dXYFpXlPkccOFqm12CdAsMgRU4VrNZ9lyGVCGuMDGIwP list
actions
/whisk.system/alarmsWeb/alarmWebAction                                 private nodejs:6
/whisk.system/alarms/alarm                                             private nodejs:6
....

Step 2: Build the alarm provider docker image

./gradlew :distDocker

Step 3: Run the alarm provider docker

set -e
set -x
WSK_HOME=$HOME/openwhisk
DB_PROTOCOL=`awk -F "=" '/db_protocol/ {print $2}' $WSK_HOME/ansible/db_local.ini`
DB_HOST=`awk -F "=" '/db_host/ {print $2}' $WSK_HOME/ansible/db_local.ini`
DB_PORT=`awk -F "=" '/db_port/ {print $2}' $WSK_HOME/ansible/db_local.ini`
DB_USER=`awk -F "=" '/db_username/ {print $2}' $WSK_HOME/ansible/db_local.ini`
DB_PWD=`awk -F "=" '/db_password/ {print $2}' $WSK_HOME/ansible/db_local.ini`
DB_PREFIX=`awk -F "=" '/db.prefix/ {print $2}' $WSK_HOME/whisk.properties`

docker run -d -p 11001:8080 -v $HOME/wsklogs/alarms:/logs \
-e PORT=8080 -e ROUTER_HOST=172.17.0.1 \
-e DB_PREFIX=${DB_PREFIX} -e DB_USERNAME=${DB_USER} \
-e DB_PASSWORD=${DB_PWD} -e DB_HOST=${DB_HOST}:${DB_PORT} \
-e DB_PROTOCOL=${DB_PROTOCOL} whisk/catalog_alarms

The docker is running locally on port 11001, which is verified from docker ps

CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                                                                                                                                                  NAMES
....
3b178d6cc3e3        whisk/catalog_alarms         "/bin/bash -c 'node /"   15 minutes ago      Up 15 minutes       0.0.0.0:11001->8080/tcp                                                                                                                                infallible_bohr
....

I also have the log, seems pretty good

$ cat wsklogs/alarms/alarmsTrigger_logs.log 
[2017-07-27T18:55:12.723Z] [INFO] [??] [alarmsTrigger] [createDatabase] creating the trigger database
[2017-07-27T18:55:12.733Z] [INFO] [??] [alarmsTrigger] [server.listen] Express server listening on port 8080
[2017-07-27T18:55:12.757Z] [INFO] [??] [alarmsTrigger] [createDatabase] created trigger database: ubuntu_ip-10-0-0-42_alarmservice
[2017-07-27T18:55:12.776Z] [INFO] [??] [alarmsTrigger] [initAllTriggers] resetting system from last state

edited:

Add the missed triggerName, which is a editing mistake

Enhancements for startDate, stopDate, fire once, interval

This issue is an Epic to capture some enhancements for the alarms package

Feature requests:

  • Allow to specify startDate and stopDate
  • Allow to specify fire once Date
  • Allow to specify more granular interval

Allow to specify startDate and stopDate

Example configuration

wsk trigger create periodic \ 
--feed /whisk.system/alarms/alarm \
--param cron "*/2 * * * *" \
--param startDate “2017-10-27T14:00”
--param stopDate “2017-10-27T14:00”

The trigger will start to fire after startDate, and no longer fire after stopDate
The time is UTC, or user can provide time zone

Adding this feature will allow us to deprecate and remove the parameter 'maxTriggers`
(today the default is infinite)

Things to consider when using stopDate to clean up.

  • allow user to specify entities (trigger and/or set of rules) if trigger should be deleted when the alarm is suppose to fire, but the current time is past the stopDate.

Allow to specify fire once Date

User wants to fire a trigger only once at the specified time/date
Example configuration

wsk trigger create doOnce \ 
--feed /whisk.system/alarms/once \
--param date "2017-10-27T14:00"

Allow to specify more granular interval

Today the cron syntax doesn't allow to specify intervals, only at the hour mark, and then repeat on the next hour. User have requests that they want more control over the internal of the fires for example every 16, or 12 minutes.
Example configuration

wsk trigger create interval \ 
--feed /whisk.system/alarms/interval \
--param minutes ”16" \
--param startDate “2017-10-27T14:02”
--param stopDate “2017-10-28T14:00”

Future/Open

Provide in CLI and Feed Abstraction for runOnce Action
Example configuration

wsk invoke myaction --once --date “2017-10-28T14:00”

Under the hood create feed alarm Fire Once, and instead of fire trigger, we invoke the action myAction.
But we also need a way to list and identified actions to be fire in the future, maybe we create a trigger and a rule with a naming convention to allow for this management.

Improve error handling on trigger fire, do not delete trigger mark it paused instead

Currently the trigger is being deleted from the DB on certain error scenarios

We need to improve how do we handle each use case, I think there are 3 use cases when firing

  1. Trigger has being removed from OpenWhisk, Controller is reachable and returns Not Found (404)
  2. Errors that are not recoverable (wrong auth 403, etc..), then delete trigger from db
  3. Errors that with a retry can be succesfully fire on a retry, but never delete the trigger from db, and instead mark the trigger doc in db "paused: true"
  4. others?
    paused state for triggers is something that could be use when redudancy providers is implemented

Provide once trigger

Feature request:

A user would like for a trigger to be fire once at a specific time and date, and optionally delete the trigger after the fire.

One idea for UX could be: (at is UTC based)

wsk trigger create onshot --feed /whisk.system/alarm/once --param at `December 24, 2017 23:30:00`

current stat is to set a cron trigger with maxTrigger of 1, which would cause a lot of problems in terms of cleaning up "dead" triggers and trying to guesstimate when is going to actual fire.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.