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

Allow to get activation list by a binding package name #4919

Merged
merged 5 commits into from
Jul 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"_id": "_design/whisks-filters.v2.1.1",
"language": "javascript",
"views": {
"activations": {
"map": "function (doc) {\n var PATHSEP = \"/\";\n var isActivation = function (doc) { return (doc.activationId !== undefined) };\n var summarize = function (doc) {\n var endtime = doc.end !== 0 ? doc.end : undefined;\n return {\n namespace: doc.namespace,\n name: doc.name,\n version: doc.version,\n publish: doc.publish,\n annotations: doc.annotations,\n activationId: doc.activationId,\n start: doc.start,\n end: endtime,\n duration: endtime !== undefined ? endtime - doc.start : undefined,\n cause: doc.cause,\n statusCode: (endtime !== undefined && doc.response !== undefined && doc.response.statusCode !== undefined) ? doc.response.statusCode : undefined\n }\n };\n \n var pathFilter = function(doc) {\n var path = undefined;\n var binding = undefined;\n for (i = 0; i < doc.annotations.length; i++) {\n var a = doc.annotations[i];\n if (a.key == \"path\") {\n path = a.value;\n }\n if (a.key == \"binding\") {\n binding = a.value;\n }\n }\n try {\n if (binding) {\n var b = binding.split(PATHSEP)\n return b[1] + PATHSEP + doc.name;\n }\n if (path) {\n var p = path.split(PATHSEP);\n if (p.length == 3) {\n return p[1] + PATHSEP + doc.name;\n } else return doc.name; \n }\n } catch (e) {\n return doc.name;\n }\n return doc.name;\n }\n\n if (isActivation(doc)) try {\n var value = summarize(doc)\n emit([doc.namespace+PATHSEP+pathFilter(doc), doc.start], value);\n } catch (e) {}\n}\n",
"reduce": "_count"
}
}
}
2 changes: 1 addition & 1 deletion ansible/tasks/recreateViews.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
doc: "{{ lookup('file', '{{ item }}') }}"
with_items:
- "{{ openwhisk_home }}/ansible/files/whisks_design_document_for_activations_db_v2.1.0.json"
- "{{ openwhisk_home }}/ansible/files/whisks_design_document_for_activations_db_filters_v2.1.0.json"
- "{{ openwhisk_home }}/ansible/files/whisks_design_document_for_activations_db_filters_v2.1.1.json"
- "{{ openwhisk_home }}/ansible/files/filter_design_document.json"
- "{{ openwhisk_home }}/ansible/files/activations_design_document_for_activations_db.json"
- "{{ openwhisk_home }}/ansible/files/logCleanup_design_document_for_activations_db.json"
2 changes: 1 addition & 1 deletion common/scala/src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ whisk {
subjects-ddoc = "subjects.v2.0.0"
actions-ddoc = "whisks.v2.1.0"
activations-ddoc = "whisks.v2.1.0"
activations-filter-ddoc = "whisks-filters.v2.1.0"
activations-filter-ddoc = "whisks-filters.v2.1.1"

# Size limit for inlined attachments. Attachments having size less than this would
# be inlined with there content encoded in attachmentName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ object ActivationHandler extends SimpleHandler {
private val fieldsForView = commonFields ++ Seq("end", "response.statusCode")

protected val supportedTables =
Set("activations/byDate", "whisks-filters.v2.1.0/activations", "whisks.v2.1.0/activations")
Set("activations/byDate", "whisks-filters.v2.1.1/activations", "whisks.v2.1.0/activations")

override def computedFields(js: JsObject): JsObject = {
val path = js.fields.get("namespace") match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,16 @@ class ElasticSearchActivationStore(
val start =
transid.started(this, LoggingMarkers.DATABASE_SAVE, s"[PUT] 'activations' document: '${activation.docid}'")

val path = activation.annotations
.getAs[String](WhiskActivation.pathAnnotation)
.getOrElse(s"${activation.namespace}/${activation.name}")
val bindingPath = activation.annotations
.getAs[String](WhiskActivation.bindingAnnotation)
.toOption
.map(binding => s"$binding/${activation.name}")

val path = bindingPath.getOrElse(
activation.annotations
.getAs[String](WhiskActivation.pathAnnotation)
.getOrElse(s"${activation.namespace}/${activation.name}"))

// Escape `_id` field as it's not permitted in ElasticSearch, add `path` field for search, and
// convert annotations to JsObject as ElasticSearch doesn't support array with mixed types
// response.result can be any type ElasticSearch also doesn't support that, so convert it to a string
Expand Down
2 changes: 1 addition & 1 deletion core/standalone/src/main/resources/standalone.conf
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ whisk {
]
activation-views = [
"whisks_design_document_for_activations_db_v2.1.0.json",
"whisks_design_document_for_activations_db_filters_v2.1.0.json",
"whisks_design_document_for_activations_db_filters_v2.1.1.json",
"filter_design_document.json",
"activations_design_document_for_activations_db.json",
"logCleanup_design_document_for_activations_db.json"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ trait ActivationStoreBehaviorBase
Instant.ofEpochMilli(start + 1000))
}

protected def newBindingActivation(ns: String, actionName: String, binding: String, start: Long): WhiskActivation = {
WhiskActivation(
EntityPath(ns),
EntityName(actionName),
Subject(),
ActivationId.generate(),
Instant.ofEpochMilli(start),
Instant.ofEpochMilli(start + 1000),
annotations = Parameters(WhiskActivation.bindingAnnotation, binding))
}

/**
* Deletes all documents added to gc queue.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,23 @@ trait ActivationStoreQueryBehaviors extends ActivationStoreBehaviorBase {
checkQueryActivations(namespace, Some(action1), context = context, expected = activations)
}

it should "find all binding entities matching name" in {
implicit val tid: TransactionId = transId()
val namespace = s"ns_${Random.alphanumeric.take(4).mkString}"
val package1 = s"package1_${Random.alphanumeric.take(4).mkString}"
val action1 = s"action1_${Random.alphanumeric.take(4).mkString}"

val binding = s"$namespace/$package1"

val activations = (1000 until 1100 by 10).map(newBindingActivation(namespace, action1, binding, _))
activations foreach (store(_, context))

val activations2 = (1000 until 1100 by 10).map(newActivation(namespace, action1, _))
activations2 foreach (store(_, context))

checkQueryActivations(namespace, Some(s"$package1/$action1"), context = context, expected = activations)
}

it should "support since and upto filters" in {
implicit val tid: TransactionId = transId()
val namespace = s"ns_${Random.alphanumeric.take(4).mkString}"
Expand Down
4 changes: 2 additions & 2 deletions tools/dev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ Sample output
- logCleanup-byDateWithLogs.js
Processing whisks_design_document_for_all_entities_db_v2.1.0.json
- all-whisks.v2.1.0-all.js
Processing whisks_design_document_for_activations_db_filters_v2.1.0.json
- whisks-filters.v2.1.0-activations.js
Processing whisks_design_document_for_activations_db_filters_v2.1.1.json
- whisks-filters.v2.1.1-activations.js
Generated view json files in /path/too/tools/build/views

## IntelliJ Run Config Generator
Expand Down