From 46e96892bab4f4fd0e941ccd53a3d672db90f5a2 Mon Sep 17 00:00:00 2001 From: Diego Date: Sat, 18 Jul 2015 19:41:30 -0300 Subject: + play-examples: new play 2.4.x example --- .../kamon-play-2.4.x-example/app/Filters.scala | 7 + .../kamon-play-2.4.x-example/app/Global.scala | 26 + .../app/controllers/KamonPlayExample.scala | 93 + .../app/filters/TraceLocalFilter.scala | 56 + .../kamon-play-2.4.x-example/conf/application.conf | 62 + .../kamon-play-2.4.x-example/conf/logger.xml | 19 + .../kamon-play-2.4.x-example/conf/routes | 5 + .../kamon-play-2.4.x-example/project/Build.scala | 52 + .../project/build.properties | 1 + .../kamon-play-2.4.x-example/project/plugins.sbt | 9 + .../public/images/favicon.png | Bin 0 -> 687 bytes .../public/images/glyphicons-halflings-white.png | Bin 0 -> 8777 bytes .../public/images/glyphicons-halflings.png | Bin 0 -> 12799 bytes .../public/javascripts/jquery-1.9.0.min.js | 4 + .../public/stylesheets/bootstrap.css | 6158 ++++++++++++++++++++ .../public/stylesheets/main.css | 0 16 files changed, 6492 insertions(+) create mode 100644 kamon-examples/kamon-play-2.4.x-example/app/Filters.scala create mode 100644 kamon-examples/kamon-play-2.4.x-example/app/Global.scala create mode 100644 kamon-examples/kamon-play-2.4.x-example/app/controllers/KamonPlayExample.scala create mode 100644 kamon-examples/kamon-play-2.4.x-example/app/filters/TraceLocalFilter.scala create mode 100644 kamon-examples/kamon-play-2.4.x-example/conf/application.conf create mode 100644 kamon-examples/kamon-play-2.4.x-example/conf/logger.xml create mode 100644 kamon-examples/kamon-play-2.4.x-example/conf/routes create mode 100644 kamon-examples/kamon-play-2.4.x-example/project/Build.scala create mode 100644 kamon-examples/kamon-play-2.4.x-example/project/build.properties create mode 100644 kamon-examples/kamon-play-2.4.x-example/project/plugins.sbt create mode 100644 kamon-examples/kamon-play-2.4.x-example/public/images/favicon.png create mode 100644 kamon-examples/kamon-play-2.4.x-example/public/images/glyphicons-halflings-white.png create mode 100644 kamon-examples/kamon-play-2.4.x-example/public/images/glyphicons-halflings.png create mode 100644 kamon-examples/kamon-play-2.4.x-example/public/javascripts/jquery-1.9.0.min.js create mode 100644 kamon-examples/kamon-play-2.4.x-example/public/stylesheets/bootstrap.css create mode 100644 kamon-examples/kamon-play-2.4.x-example/public/stylesheets/main.css diff --git a/kamon-examples/kamon-play-2.4.x-example/app/Filters.scala b/kamon-examples/kamon-play-2.4.x-example/app/Filters.scala new file mode 100644 index 00000000..0ae2747a --- /dev/null +++ b/kamon-examples/kamon-play-2.4.x-example/app/Filters.scala @@ -0,0 +1,7 @@ +import javax.inject.Inject +import play.api.http.HttpFilters +import filters.TraceLocalFilter + +class Filters extends HttpFilters { + val filters = Seq(TraceLocalFilter) +} \ No newline at end of file diff --git a/kamon-examples/kamon-play-2.4.x-example/app/Global.scala b/kamon-examples/kamon-play-2.4.x-example/app/Global.scala new file mode 100644 index 00000000..8d43fbdc --- /dev/null +++ b/kamon-examples/kamon-play-2.4.x-example/app/Global.scala @@ -0,0 +1,26 @@ +/* =================================================== + * Copyright © 2013-2014 the kamon project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================================================== */ + +import filters.TraceLocalFilter +import play.api.mvc.WithFilters +import play.api.Application +import kamon.Kamon + +object Global extends WithFilters(TraceLocalFilter) { + override def onStart(app: Application) { + Kamon.start() + } +} diff --git a/kamon-examples/kamon-play-2.4.x-example/app/controllers/KamonPlayExample.scala b/kamon-examples/kamon-play-2.4.x-example/app/controllers/KamonPlayExample.scala new file mode 100644 index 00000000..d6b0f771 --- /dev/null +++ b/kamon-examples/kamon-play-2.4.x-example/app/controllers/KamonPlayExample.scala @@ -0,0 +1,93 @@ +/* =================================================== + * Copyright © 2013-2014 the kamon project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================================================== */ +package controllers + +import filters.{TraceLocalContainer, TraceLocalKey} +import kamon.Kamon +import kamon.play.action.TraceName +import kamon.trace.TraceLocal +import play.api.Logger +import play.api.libs.concurrent.Execution.Implicits.defaultContext +import play.api.mvc.{Action, Controller} +import play.libs.Akka +import javax.inject._ + +import scala.concurrent._ + +/** + * In order to run the example we need set the -javaagent option to the JVM, but Play have some limitations when trying to set an + * java agent in Play dev mode (ie, play run) -> https://github.com/playframework/playframework/issues/1372, so we have others options: + * + * The first option is set -javaagent: path-to-aspectj-weaver in your IDE or + * + * Run the following commands from console: + * + * 1- play stage + * 2- cd target/universal/stage + * 3- java -cp ".:lib/*" -javaagent:lib/org.aspectj.aspectjweaver-1.8.1.jar play.core.server.NettyServer + * + * and finally for test: + * + * curl -i -H 'X-Trace-Token:kamon-test' -H 'MyTraceLocalStorageKey:extra-header' -X GET "http://localhost:9000/helloKamon" + * + * we should get: + * HTTP/1.1 200 OK + * Content-Type: text/plain; charset=utf-8 + * MyTraceLocalStorageKey: extra-header -> Extra Information + * X-Trace-Token: kamon-test -> default Trace-Token + * + * Say hello to Kamon + */*/ + + +class KamonPlayExample extends Controller { + + val logger = Logger(this.getClass) + val counter = Kamon.metrics.counter("my-counter") + + def sayHello = Action.async { + Future { + logger.info("Say hello to Kamon") + Ok("Say hello to Kamon") + } + } + + //using the Kamon TraceName Action to rename the trace name in metrics + def sayHelloWithTraceName = TraceName("my-trace-name") { + Action.async { + Future { + logger.info("Say hello to Kamon with trace name") + Ok("Say hello to Kamon with trace name") + } + } + } + + def incrementCounter = Action.async { + Future { + logger.info("increment") + counter.increment() + Ok("increment") + } + } + + def updateTraceLocal = Action.async { + Future { + TraceLocal.store(TraceLocalKey)(TraceLocalContainer("MyTraceToken","MyImportantHeader")) + logger.info("storeInTraceLocal") + Ok("storeInTraceLocal") + } + } +} diff --git a/kamon-examples/kamon-play-2.4.x-example/app/filters/TraceLocalFilter.scala b/kamon-examples/kamon-play-2.4.x-example/app/filters/TraceLocalFilter.scala new file mode 100644 index 00000000..8a92aa66 --- /dev/null +++ b/kamon-examples/kamon-play-2.4.x-example/app/filters/TraceLocalFilter.scala @@ -0,0 +1,56 @@ +/* =================================================== + * Copyright © 2013-2014 the kamon project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ========================================================== */ + +package filters + +import kamon.trace.TraceLocal +import play.api.Logger +import play.api.mvc.{Result, RequestHeader, Filter} +import play.api.libs.concurrent.Execution.Implicits.defaultContext +import scala.concurrent.Future + +case class TraceLocalContainer(traceToken:String, importantHeader:String) + +object TraceLocalKey extends TraceLocal.TraceLocalKey { + type ValueType = TraceLocalContainer +} + +/* + By default kamon spreads the trace-token-header-name, but sometimes is necessary pass through the application requests with some information like + extra headers, with kamon it's possible using the TraceLocalStorage, in Play applications we can do an Action Filter or using Action Composition, + in this example we are using a simple filter where given a Header store the value and then put the value in the result headers.. + + More detailed usage of TraceLocalStorage: https://github.com/kamon-io/Kamon/blob/b17539d231da923ea854c01d2c69eb02ef1e85b1/kamon-core/src/test/scala/kamon/trace/TraceLocalSpec.scala + */ +object TraceLocalFilter extends Filter { + val logger = Logger(this.getClass) + val TraceLocalStorageKey = "MyTraceLocalStorageKey" + + override def apply(next: (RequestHeader) ⇒ Future[Result])(header: RequestHeader): Future[Result] = { + + def onResult(result:Result) = { + val traceLocalContainer = TraceLocal.retrieve(TraceLocalKey).getOrElse(TraceLocalContainer("unknown","unknown")) + logger.info(s"traceTokenValue: ${traceLocalContainer.traceToken}") + result.withHeaders((TraceLocalStorageKey -> traceLocalContainer.traceToken)) + } + + //update the TraceLocalStorage + TraceLocal.store(TraceLocalKey)(TraceLocalContainer(header.headers.get(TraceLocalStorageKey).getOrElse("unknown"), "unknown")) + + //call the action + next(header).map(onResult) + } +} diff --git a/kamon-examples/kamon-play-2.4.x-example/conf/application.conf b/kamon-examples/kamon-play-2.4.x-example/conf/application.conf new file mode 100644 index 00000000..75a80d8c --- /dev/null +++ b/kamon-examples/kamon-play-2.4.x-example/conf/application.conf @@ -0,0 +1,62 @@ +#kamon related configuration +akka { + extensions = ["kamon.statsd.StatsD", "kamon.system.SystemMetrics", "kamon.logreporter.LogReporter"] +} + +kamon { + + metric { + tick-interval = 1 second + } + + statsd { + # Hostname and port in which your StatsD is running. Remember that StatsD packets are sent using UDP and + # setting unreachable hosts and/or not open ports wont be warned by the Kamon, your data wont go anywhere. + hostname = "127.0.0.1" + port = 8125 + + # Interval between metrics data flushes to StatsD. It's value must be equal or greater than the + # kamon.metrics.tick-interval setting. + flush-interval = 1 second + + # Max packet size for UDP metrics data sent to StatsD. + max-packet-size = 1024 bytes + + # Subscription patterns used to select which metrics will be pushed to StatsD. Note that first, metrics + # collection for your desired entities must be activated under the kamon.metrics.filters settings. + includes { + actor = [ "*" ] + trace = [ "*" ] + dispatcher = [ "*" ] + } + + simple-metric-key-generator { + # Application prefix for all metrics pushed to StatsD. The default namespacing scheme for metrics follows + # this pattern: + # application.host.entity.entity-name.metric-name + application = "activator-akka-kamon-statsd" + } + } + + play { + include-trace-token-header = true + trace-token-header-name = "X-Trace-Token" + } +} + +# This is the main configuration file for the application. +# ~~~~~ + +# Secret key +# ~~~~~ +# The secret key is used to secure cryptographics functions. +# If you deploy your application to several instances be sure to use the same key! +application.secret = "3BLM`AZE9EOphrmf;;6JsAN" + +# The application languages +# ~~~~~ +play.i18n.langs = [ "en"] + +# HttpRequestHandler +play.http.requestHandler = "play.http.DefaultHttpRequestHandler" + diff --git a/kamon-examples/kamon-play-2.4.x-example/conf/logger.xml b/kamon-examples/kamon-play-2.4.x-example/conf/logger.xml new file mode 100644 index 00000000..56b3c33e --- /dev/null +++ b/kamon-examples/kamon-play-2.4.x-example/conf/logger.xml @@ -0,0 +1,19 @@ + + + + %date{HH:mm:ss.SSS} %-5level [%X{traceToken}][%X{importantHeader}] [%thread] %logger{55} - %msg%n + + + + + + + + + + + + + + + diff --git a/kamon-examples/kamon-play-2.4.x-example/conf/routes b/kamon-examples/kamon-play-2.4.x-example/conf/routes new file mode 100644 index 00000000..6aae1d8e --- /dev/null +++ b/kamon-examples/kamon-play-2.4.x-example/conf/routes @@ -0,0 +1,5 @@ +# Routes +GET /helloKamon @controllers.KamonPlayExample.sayHello +GET /helloKamonWithTraceName @controllers.KamonPlayExample.sayHelloWithTraceName +GET /incrementCounter @controllers.KamonPlayExample.incrementCounter +GET /updateTraceLocal @controllers.KamonPlayExample.updateTraceLocal \ No newline at end of file diff --git a/kamon-examples/kamon-play-2.4.x-example/project/Build.scala b/kamon-examples/kamon-play-2.4.x-example/project/Build.scala new file mode 100644 index 00000000..a2d65d64 --- /dev/null +++ b/kamon-examples/kamon-play-2.4.x-example/project/Build.scala @@ -0,0 +1,52 @@ +import java.io.File +import sbt._ +import Keys._ +import play.Play.autoImport._ +import sbt.Keys._ +import sbt._ +import com.typesafe.sbt.web.SbtWeb + + +object ApplicationBuild extends Build { + + val appName = "Kamon-Play-Example" + val appVersion = "1.0-SNAPSHOT" + + val resolutionRepos = Seq( + "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/", + "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots", + "Sonatype Releases" at "https://oss.sonatype.org/content/repositories/releases", + "Kamon Repository Snapshots" at "http://snapshots.kamon.io" + ) + + val defaultSettings = Seq( + scalaVersion := "2.11.7", + resolvers ++= resolutionRepos, + scalacOptions := Seq( + "-encoding", + "utf8", + "-g:vars", + "-feature", + "-unchecked", + "-deprecation", + "-target:jvm-1.6", + "-language:postfixOps", + "-language:implicitConversions", + "-Xlog-reflective-calls" + )) + + val kamonVersion = "0.4.0" + + val dependencies = Seq( + "io.kamon" %% "kamon-core" % kamonVersion, + "io.kamon" %% "kamon-play" % kamonVersion, + "io.kamon" %% "kamon-statsd" % kamonVersion, + "io.kamon" %% "kamon-log-reporter" % kamonVersion, + "io.kamon" %% "kamon-system-metrics" % kamonVersion, + "org.aspectj" % "aspectjweaver" % "1.8.6" + ) + + val main = Project(appName, file(".")).enablePlugins(play.PlayScala, SbtWeb) + .settings(libraryDependencies ++= dependencies) + .settings(defaultSettings: _*) +} diff --git a/kamon-examples/kamon-play-2.4.x-example/project/build.properties b/kamon-examples/kamon-play-2.4.x-example/project/build.properties new file mode 100644 index 00000000..a6e117b6 --- /dev/null +++ b/kamon-examples/kamon-play-2.4.x-example/project/build.properties @@ -0,0 +1 @@ +sbt.version=0.13.8 diff --git a/kamon-examples/kamon-play-2.4.x-example/project/plugins.sbt b/kamon-examples/kamon-play-2.4.x-example/project/plugins.sbt new file mode 100644 index 00000000..f0037325 --- /dev/null +++ b/kamon-examples/kamon-play-2.4.x-example/project/plugins.sbt @@ -0,0 +1,9 @@ +// Comment to get more information during initialization +logLevel := Level.Warn + +// The Typesafe repository +resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/" + +// Use the Play sbt plugin for Play projects +addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.2") + diff --git a/kamon-examples/kamon-play-2.4.x-example/public/images/favicon.png b/kamon-examples/kamon-play-2.4.x-example/public/images/favicon.png new file mode 100644 index 00000000..c7d92d2a Binary files /dev/null and b/kamon-examples/kamon-play-2.4.x-example/public/images/favicon.png differ diff --git a/kamon-examples/kamon-play-2.4.x-example/public/images/glyphicons-halflings-white.png b/kamon-examples/kamon-play-2.4.x-example/public/images/glyphicons-halflings-white.png new file mode 100644 index 00000000..3bf6484a Binary files /dev/null and b/kamon-examples/kamon-play-2.4.x-example/public/images/glyphicons-halflings-white.png differ diff --git a/kamon-examples/kamon-play-2.4.x-example/public/images/glyphicons-halflings.png b/kamon-examples/kamon-play-2.4.x-example/public/images/glyphicons-halflings.png new file mode 100644 index 00000000..a9969993 Binary files /dev/null and b/kamon-examples/kamon-play-2.4.x-example/public/images/glyphicons-halflings.png differ diff --git a/kamon-examples/kamon-play-2.4.x-example/public/javascripts/jquery-1.9.0.min.js b/kamon-examples/kamon-play-2.4.x-example/public/javascripts/jquery-1.9.0.min.js new file mode 100644 index 00000000..50d1b22f --- /dev/null +++ b/kamon-examples/kamon-play-2.4.x-example/public/javascripts/jquery-1.9.0.min.js @@ -0,0 +1,4 @@ +/*! jQuery v1.9.0 | (c) 2005, 2012 jQuery Foundation, Inc. | jquery.org/license */(function(e,t){"use strict";function n(e){var t=e.length,n=st.type(e);return st.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||"function"!==n&&(0===t||"number"==typeof t&&t>0&&t-1 in e)}function r(e){var t=Tt[e]={};return st.each(e.match(lt)||[],function(e,n){t[n]=!0}),t}function i(e,n,r,i){if(st.acceptData(e)){var o,a,s=st.expando,u="string"==typeof n,l=e.nodeType,c=l?st.cache:e,f=l?e[s]:e[s]&&s;if(f&&c[f]&&(i||c[f].data)||!u||r!==t)return f||(l?e[s]=f=K.pop()||st.guid++:f=s),c[f]||(c[f]={},l||(c[f].toJSON=st.noop)),("object"==typeof n||"function"==typeof n)&&(i?c[f]=st.extend(c[f],n):c[f].data=st.extend(c[f].data,n)),o=c[f],i||(o.data||(o.data={}),o=o.data),r!==t&&(o[st.camelCase(n)]=r),u?(a=o[n],null==a&&(a=o[st.camelCase(n)])):a=o,a}}function o(e,t,n){if(st.acceptData(e)){var r,i,o,a=e.nodeType,u=a?st.cache:e,l=a?e[st.expando]:st.expando;if(u[l]){if(t&&(r=n?u[l]:u[l].data)){st.isArray(t)?t=t.concat(st.map(t,st.camelCase)):t in r?t=[t]:(t=st.camelCase(t),t=t in r?[t]:t.split(" "));for(i=0,o=t.length;o>i;i++)delete r[t[i]];if(!(n?s:st.isEmptyObject)(r))return}(n||(delete u[l].data,s(u[l])))&&(a?st.cleanData([e],!0):st.support.deleteExpando||u!=u.window?delete u[l]:u[l]=null)}}}function a(e,n,r){if(r===t&&1===e.nodeType){var i="data-"+n.replace(Nt,"-$1").toLowerCase();if(r=e.getAttribute(i),"string"==typeof r){try{r="true"===r?!0:"false"===r?!1:"null"===r?null:+r+""===r?+r:wt.test(r)?st.parseJSON(r):r}catch(o){}st.data(e,n,r)}else r=t}return r}function s(e){var t;for(t in e)if(("data"!==t||!st.isEmptyObject(e[t]))&&"toJSON"!==t)return!1;return!0}function u(){return!0}function l(){return!1}function c(e,t){do e=e[t];while(e&&1!==e.nodeType);return e}function f(e,t,n){if(t=t||0,st.isFunction(t))return st.grep(e,function(e,r){var i=!!t.call(e,r,e);return i===n});if(t.nodeType)return st.grep(e,function(e){return e===t===n});if("string"==typeof t){var r=st.grep(e,function(e){return 1===e.nodeType});if(Wt.test(t))return st.filter(t,r,!n);t=st.filter(t,r)}return st.grep(e,function(e){return st.inArray(e,t)>=0===n})}function p(e){var t=zt.split("|"),n=e.createDocumentFragment();if(n.createElement)for(;t.length;)n.createElement(t.pop());return n}function d(e,t){return e.getElementsByTagName(t)[0]||e.appendChild(e.ownerDocument.createElement(t))}function h(e){var t=e.getAttributeNode("type");return e.type=(t&&t.specified)+"/"+e.type,e}function g(e){var t=nn.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function m(e,t){for(var n,r=0;null!=(n=e[r]);r++)st._data(n,"globalEval",!t||st._data(t[r],"globalEval"))}function y(e,t){if(1===t.nodeType&&st.hasData(e)){var n,r,i,o=st._data(e),a=st._data(t,o),s=o.events;if(s){delete a.handle,a.events={};for(n in s)for(r=0,i=s[n].length;i>r;r++)st.event.add(t,n,s[n][r])}a.data&&(a.data=st.extend({},a.data))}}function v(e,t){var n,r,i;if(1===t.nodeType){if(n=t.nodeName.toLowerCase(),!st.support.noCloneEvent&&t[st.expando]){r=st._data(t);for(i in r.events)st.removeEvent(t,i,r.handle);t.removeAttribute(st.expando)}"script"===n&&t.text!==e.text?(h(t).text=e.text,g(t)):"object"===n?(t.parentNode&&(t.outerHTML=e.outerHTML),st.support.html5Clone&&e.innerHTML&&!st.trim(t.innerHTML)&&(t.innerHTML=e.innerHTML)):"input"===n&&Zt.test(e.type)?(t.defaultChecked=t.checked=e.checked,t.value!==e.value&&(t.value=e.value)):"option"===n?t.defaultSelected=t.selected=e.defaultSelected:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}}function b(e,n){var r,i,o=0,a=e.getElementsByTagName!==t?e.getElementsByTagName(n||"*"):e.querySelectorAll!==t?e.querySelectorAll(n||"*"):t;if(!a)for(a=[],r=e.childNodes||e;null!=(i=r[o]);o++)!n||st.nodeName(i,n)?a.push(i):st.merge(a,b(i,n));return n===t||n&&st.nodeName(e,n)?st.merge([e],a):a}function x(e){Zt.test(e.type)&&(e.defaultChecked=e.checked)}function T(e,t){if(t in e)return t;for(var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=Nn.length;i--;)if(t=Nn[i]+n,t in e)return t;return r}function w(e,t){return e=t||e,"none"===st.css(e,"display")||!st.contains(e.ownerDocument,e)}function N(e,t){for(var n,r=[],i=0,o=e.length;o>i;i++)n=e[i],n.style&&(r[i]=st._data(n,"olddisplay"),t?(r[i]||"none"!==n.style.display||(n.style.display=""),""===n.style.display&&w(n)&&(r[i]=st._data(n,"olddisplay",S(n.nodeName)))):r[i]||w(n)||st._data(n,"olddisplay",st.css(n,"display")));for(i=0;o>i;i++)n=e[i],n.style&&(t&&"none"!==n.style.display&&""!==n.style.display||(n.style.display=t?r[i]||"":"none"));return e}function C(e,t,n){var r=mn.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function k(e,t,n,r,i){for(var o=n===(r?"border":"content")?4:"width"===t?1:0,a=0;4>o;o+=2)"margin"===n&&(a+=st.css(e,n+wn[o],!0,i)),r?("content"===n&&(a-=st.css(e,"padding"+wn[o],!0,i)),"margin"!==n&&(a-=st.css(e,"border"+wn[o]+"Width",!0,i))):(a+=st.css(e,"padding"+wn[o],!0,i),"padding"!==n&&(a+=st.css(e,"border"+wn[o]+"Width",!0,i)));return a}function E(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,o=ln(e),a=st.support.boxSizing&&"border-box"===st.css(e,"boxSizing",!1,o);if(0>=i||null==i){if(i=un(e,t,o),(0>i||null==i)&&(i=e.style[t]),yn.test(i))return i;r=a&&(st.support.boxSizingReliable||i===e.style[t]),i=parseFloat(i)||0}return i+k(e,t,n||(a?"border":"content"),r,o)+"px"}function S(e){var t=V,n=bn[e];return n||(n=A(e,t),"none"!==n&&n||(cn=(cn||st("