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

Add filter-based rotation of aliases #22

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
22 changes: 22 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
name: CI

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Clojure
run: |
wget --quiet https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
chmod +x lein
- name: Run the test suite
run: ./lein test
2 changes: 2 additions & 0 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
[[cheshire "5.7.0"]
[org.clojure/clojure "1.8.0"]
[riemann "0.3.8"]
[com.fasterxml.jackson.core/jackson-core "2.10.0"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, I get:

romain@desktop-fln40kq ~/Projects/samplerr % ./lein test   
Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/exc/InputCoercionException, compiling:(riemann/plugin/samplerr.clj:1:1)
	at clojure.lang.Compiler.load(Compiler.java:7391)
	at clojure.lang.RT.loadResourceScript(RT.java:372)
	at clojure.lang.RT.loadResourceScript(RT.java:363)
	at clojure.lang.RT.load(RT.java:453)
	at clojure.lang.RT.load(RT.java:419)
	at clojure.core$load$fn__5677.invoke(core.clj:5893)
	at clojure.core$load.invokeStatic(core.clj:5892)
	at clojure.core$load.doInvoke(core.clj:5876)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5697)
	at clojure.core$load_one.invoke(core.clj:5692)
	at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
	at clojure.core$load_lib.invokeStatic(core.clj:5736)
	at clojure.core$load_lib.doInvoke(core.clj:5717)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$load_libs.invokeStatic(core.clj:5774)
	at clojure.core$load_libs.doInvoke(core.clj:5758)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$require.invokeStatic(core.clj:5796)
	at clojure.core$require.doInvoke(core.clj:5796)
	at clojure.lang.RestFn.invoke(RestFn.java:421)
	at riemann.plugin.samplerr_test$eval191$loading__5569__auto____192.invoke(samplerr_test.clj:1)
	at riemann.plugin.samplerr_test$eval191.invokeStatic(samplerr_test.clj:1)
	at riemann.plugin.samplerr_test$eval191.invoke(samplerr_test.clj:1)
	at clojure.lang.Compiler.eval(Compiler.java:6927)
	at clojure.lang.Compiler.eval(Compiler.java:6916)
	at clojure.lang.Compiler.load(Compiler.java:7379)
	at clojure.lang.RT.loadResourceScript(RT.java:372)
	at clojure.lang.RT.loadResourceScript(RT.java:363)
	at clojure.lang.RT.load(RT.java:453)
	at clojure.lang.RT.load(RT.java:419)
	at clojure.core$load$fn__5677.invoke(core.clj:5893)
	at clojure.core$load.invokeStatic(core.clj:5892)
	at clojure.core$load.doInvoke(core.clj:5876)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5697)
	at clojure.core$load_one.invoke(core.clj:5692)
	at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
	at clojure.core$load_lib.invokeStatic(core.clj:5736)
	at clojure.core$load_lib.doInvoke(core.clj:5717)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$load_libs.invokeStatic(core.clj:5774)
	at clojure.core$load_libs.doInvoke(core.clj:5758)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$require.invokeStatic(core.clj:5796)
	at clojure.core$require.doInvoke(core.clj:5796)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:646)
	at clojure.core$apply.invoke(core.clj:641)
	at user$eval85.invokeStatic(form-init4667977453765916564.clj:1)
	at user$eval85.invoke(form-init4667977453765916564.clj:1)
	at clojure.lang.Compiler.eval(Compiler.java:6927)
	at clojure.lang.Compiler.eval(Compiler.java:6917)
	at clojure.lang.Compiler.load(Compiler.java:7379)
	at clojure.lang.Compiler.loadFile(Compiler.java:7317)
	at clojure.main$load_script.invokeStatic(main.clj:275)
	at clojure.main$init_opt.invokeStatic(main.clj:277)
	at clojure.main$init_opt.invoke(main.clj:277)
	at clojure.main$initialize.invokeStatic(main.clj:308)
	at clojure.main$null_opt.invokeStatic(main.clj:342)
	at clojure.main$null_opt.invoke(main.clj:339)
	at clojure.main$main.invokeStatic(main.clj:421)
	at clojure.main$main.doInvoke(main.clj:384)
	at clojure.lang.RestFn.invoke(RestFn.java:421)
	at clojure.lang.Var.invoke(Var.java:383)
	at clojure.lang.AFn.applyToHelper(AFn.java:156)
	at clojure.lang.Var.applyTo(Var.java:700)
	at clojure.main.main(main.java:37)
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/exc/InputCoercionException
	at com.fasterxml.jackson.databind.deser.std.JdkDeserializers.<clinit>(JdkDeserializers.java:26)
	at com.fasterxml.jackson.databind.deser.BasicDeserializerFactory.findDefaultDeserializer(BasicDeserializerFactory.java:1852)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.findStdDeserializer(BeanDeserializerFactory.java:167)
	at com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:131)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:411)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:349)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:264)
	at com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:244)
	at com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
	at com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:476)
	at com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:4389)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4198)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3136)
	at com.amazonaws.internal.config.InternalConfig.loadfrom(InternalConfig.java:236)
	at com.amazonaws.internal.config.InternalConfig.load(InternalConfig.java:249)
	at com.amazonaws.internal.config.InternalConfig$Factory.<clinit>(InternalConfig.java:304)
	at com.amazonaws.util.VersionInfoUtils.userAgent(VersionInfoUtils.java:142)
	at com.amazonaws.util.VersionInfoUtils.initializeUserAgent(VersionInfoUtils.java:137)
	at com.amazonaws.util.VersionInfoUtils.getUserAgent(VersionInfoUtils.java:100)
	at com.amazonaws.ClientConfiguration.<clinit>(ClientConfiguration.java:64)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:398)
	at clojure.lang.RT.classForName(RT.java:2168)
	at clojure.lang.RT.classForName(RT.java:2177)
	at amazonica.core$get_client_configuration.<clinit>(core.clj:197)
	at amazonica.core__init.load(Unknown Source)
	at amazonica.core__init.<clinit>(Unknown Source)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:398)
	at clojure.lang.RT.classForName(RT.java:2168)
	at clojure.lang.RT.classForName(RT.java:2177)
	at clojure.lang.RT.loadClassForName(RT.java:2196)
	at clojure.lang.RT.load(RT.java:443)
	at clojure.lang.RT.load(RT.java:419)
	at clojure.core$load$fn__5677.invoke(core.clj:5893)
	at clojure.core$load.invokeStatic(core.clj:5892)
	at clojure.core$load.doInvoke(core.clj:5876)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5697)
	at clojure.core$load_one.invoke(core.clj:5692)
	at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
	at clojure.core$load_lib.invokeStatic(core.clj:5736)
	at clojure.core$load_lib.doInvoke(core.clj:5717)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$load_libs.invokeStatic(core.clj:5774)
	at clojure.core$load_libs.doInvoke(core.clj:5758)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$require.invokeStatic(core.clj:5796)
	at clojure.core$require.doInvoke(core.clj:5796)
	at clojure.lang.RestFn.invoke(RestFn.java:421)
	at riemann.cloudwatch$loading__6434__auto____3664.invoke(cloudwatch.clj:1)
	at riemann.cloudwatch__init.load(Unknown Source)
	at riemann.cloudwatch__init.<clinit>(Unknown Source)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:398)
	at clojure.lang.RT.classForName(RT.java:2168)
	at clojure.lang.RT.classForName(RT.java:2177)
	at clojure.lang.RT.loadClassForName(RT.java:2196)
	at clojure.lang.RT.load(RT.java:443)
	at clojure.lang.RT.load(RT.java:419)
	at clojure.core$load$fn__5677.invoke(core.clj:5893)
	at clojure.core$load.invokeStatic(core.clj:5892)
	at clojure.core$load.doInvoke(core.clj:5876)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5697)
	at clojure.core$load_one.invoke(core.clj:5692)
	at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
	at clojure.core$load_lib.invokeStatic(core.clj:5736)
	at clojure.core$load_lib.doInvoke(core.clj:5717)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$load_libs.invokeStatic(core.clj:5778)
	at clojure.core$load_libs.doInvoke(core.clj:5758)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$require.invokeStatic(core.clj:5796)
	at clojure.core$require.doInvoke(core.clj:5796)
	at clojure.lang.RestFn.invoke(RestFn.java:512)
	at riemann.config$loading__6434__auto____182.invoke(config.clj:1)
	at riemann.config__init.load(Unknown Source)
	at riemann.config__init.<clinit>(Unknown Source)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:398)
	at clojure.lang.RT.classForName(RT.java:2168)
	at clojure.lang.RT.classForName(RT.java:2177)
	at clojure.lang.RT.loadClassForName(RT.java:2196)
	at clojure.lang.RT.load(RT.java:443)
	at clojure.lang.RT.load(RT.java:419)
	at clojure.core$load$fn__5677.invoke(core.clj:5893)
	at clojure.core$load.invokeStatic(core.clj:5892)
	at clojure.core$load.doInvoke(core.clj:5876)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5697)
	at clojure.core$load_one.invoke(core.clj:5692)
	at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
	at clojure.core$load_lib.invokeStatic(core.clj:5736)
	at clojure.core$load_lib.doInvoke(core.clj:5717)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$load_libs.invokeStatic(core.clj:5774)
	at clojure.core$load_libs.doInvoke(core.clj:5758)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$require.invokeStatic(core.clj:5796)
	at clojure.core$require.doInvoke(core.clj:5796)
	at clojure.lang.RestFn.invoke(RestFn.java:930)
	at riemann.plugin.samplerr$eval199$loading__5569__auto____200.invoke(samplerr.clj:4)
	at riemann.plugin.samplerr$eval199.invokeStatic(samplerr.clj:4)
	at riemann.plugin.samplerr$eval199.invoke(samplerr.clj:4)
	at clojure.lang.Compiler.eval(Compiler.java:6927)
	at clojure.lang.Compiler.eval(Compiler.java:6916)
	at clojure.lang.Compiler.load(Compiler.java:7379)
	... 71 more
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.exc.InputCoercionException
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 185 more
Tests failed.

[clj-time "0.13.0"]
[cc.qbits/commons "0.5.1"]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, I get:

romain@desktop-fln40kq ~/Projects/samplerr % ./lein test
Exception in thread "main" java.lang.ExceptionInInitializerError, compiling:(qbits/commons/enum.clj:1:1)
	at clojure.lang.Compiler.load(Compiler.java:7391)
	at clojure.lang.RT.loadResourceScript(RT.java:372)
	at clojure.lang.RT.loadResourceScript(RT.java:363)
	at clojure.lang.RT.load(RT.java:453)
	at clojure.lang.RT.load(RT.java:419)
	at clojure.core$load$fn__5677.invoke(core.clj:5893)
	at clojure.core$load.invokeStatic(core.clj:5892)
	at clojure.core$load.doInvoke(core.clj:5876)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5697)
	at clojure.core$load_one.invoke(core.clj:5692)
	at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
	at clojure.core$load_lib.invokeStatic(core.clj:5736)
	at clojure.core$load_lib.doInvoke(core.clj:5717)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$load_libs.invokeStatic(core.clj:5774)
	at clojure.core$load_libs.doInvoke(core.clj:5758)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$require.invokeStatic(core.clj:5796)
	at clojure.core$require.doInvoke(core.clj:5796)
	at clojure.lang.RestFn.invoke(RestFn.java:619)
	at qbits.spandex$eval221$loading__5569__auto____222.invoke(spandex.clj:1)
	at qbits.spandex$eval221.invokeStatic(spandex.clj:1)
	at qbits.spandex$eval221.invoke(spandex.clj:1)
	at clojure.lang.Compiler.eval(Compiler.java:6927)
	at clojure.lang.Compiler.eval(Compiler.java:6916)
	at clojure.lang.Compiler.load(Compiler.java:7379)
	at clojure.lang.RT.loadResourceScript(RT.java:372)
	at clojure.lang.RT.loadResourceScript(RT.java:363)
	at clojure.lang.RT.load(RT.java:453)
	at clojure.lang.RT.load(RT.java:419)
	at clojure.core$load$fn__5677.invoke(core.clj:5893)
	at clojure.core$load.invokeStatic(core.clj:5892)
	at clojure.core$load.doInvoke(core.clj:5876)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5697)
	at clojure.core$load_one.invoke(core.clj:5692)
	at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
	at clojure.core$load_lib.invokeStatic(core.clj:5736)
	at clojure.core$load_lib.doInvoke(core.clj:5717)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$load_libs.invokeStatic(core.clj:5774)
	at clojure.core$load_libs.doInvoke(core.clj:5758)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$require.invokeStatic(core.clj:5796)
	at clojure.core$require.doInvoke(core.clj:5796)
	at clojure.lang.RestFn.invoke(RestFn.java:930)
	at riemann.plugin.samplerr$eval199$loading__5569__auto____200.invoke(samplerr.clj:4)
	at riemann.plugin.samplerr$eval199.invokeStatic(samplerr.clj:4)
	at riemann.plugin.samplerr$eval199.invoke(samplerr.clj:4)
	at clojure.lang.Compiler.eval(Compiler.java:6927)
	at clojure.lang.Compiler.eval(Compiler.java:6916)
	at clojure.lang.Compiler.load(Compiler.java:7379)
	at clojure.lang.RT.loadResourceScript(RT.java:372)
	at clojure.lang.RT.loadResourceScript(RT.java:363)
	at clojure.lang.RT.load(RT.java:453)
	at clojure.lang.RT.load(RT.java:419)
	at clojure.core$load$fn__5677.invoke(core.clj:5893)
	at clojure.core$load.invokeStatic(core.clj:5892)
	at clojure.core$load.doInvoke(core.clj:5876)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5697)
	at clojure.core$load_one.invoke(core.clj:5692)
	at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
	at clojure.core$load_lib.invokeStatic(core.clj:5736)
	at clojure.core$load_lib.doInvoke(core.clj:5717)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$load_libs.invokeStatic(core.clj:5774)
	at clojure.core$load_libs.doInvoke(core.clj:5758)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$require.invokeStatic(core.clj:5796)
	at clojure.core$require.doInvoke(core.clj:5796)
	at clojure.lang.RestFn.invoke(RestFn.java:421)
	at riemann.plugin.samplerr_test$eval191$loading__5569__auto____192.invoke(samplerr_test.clj:1)
	at riemann.plugin.samplerr_test$eval191.invokeStatic(samplerr_test.clj:1)
	at riemann.plugin.samplerr_test$eval191.invoke(samplerr_test.clj:1)
	at clojure.lang.Compiler.eval(Compiler.java:6927)
	at clojure.lang.Compiler.eval(Compiler.java:6916)
	at clojure.lang.Compiler.load(Compiler.java:7379)
	at clojure.lang.RT.loadResourceScript(RT.java:372)
	at clojure.lang.RT.loadResourceScript(RT.java:363)
	at clojure.lang.RT.load(RT.java:453)
	at clojure.lang.RT.load(RT.java:419)
	at clojure.core$load$fn__5677.invoke(core.clj:5893)
	at clojure.core$load.invokeStatic(core.clj:5892)
	at clojure.core$load.doInvoke(core.clj:5876)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5697)
	at clojure.core$load_one.invoke(core.clj:5692)
	at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
	at clojure.core$load_lib.invokeStatic(core.clj:5736)
	at clojure.core$load_lib.doInvoke(core.clj:5717)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$load_libs.invokeStatic(core.clj:5774)
	at clojure.core$load_libs.doInvoke(core.clj:5758)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$require.invokeStatic(core.clj:5796)
	at clojure.core$require.doInvoke(core.clj:5796)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:646)
	at clojure.core$apply.invoke(core.clj:641)
	at user$eval85.invokeStatic(form-init11657523158905542061.clj:1)
	at user$eval85.invoke(form-init11657523158905542061.clj:1)
	at clojure.lang.Compiler.eval(Compiler.java:6927)
	at clojure.lang.Compiler.eval(Compiler.java:6917)
	at clojure.lang.Compiler.load(Compiler.java:7379)
	at clojure.lang.Compiler.loadFile(Compiler.java:7317)
	at clojure.main$load_script.invokeStatic(main.clj:275)
	at clojure.main$init_opt.invokeStatic(main.clj:277)
	at clojure.main$init_opt.invoke(main.clj:277)
	at clojure.main$initialize.invokeStatic(main.clj:308)
	at clojure.main$null_opt.invokeStatic(main.clj:342)
	at clojure.main$null_opt.invoke(main.clj:339)
	at clojure.main$main.invokeStatic(main.clj:421)
	at clojure.main$main.doInvoke(main.clj:384)
	at clojure.lang.RestFn.invoke(RestFn.java:421)
	at clojure.lang.Var.invoke(Var.java:383)
	at clojure.lang.AFn.applyToHelper(AFn.java:156)
	at clojure.lang.Var.applyTo(Var.java:700)
	at clojure.main.main(main.java:37)
Caused by: java.lang.ExceptionInInitializerError
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:398)
	at clojure.lang.RT.classForName(RT.java:2168)
	at clojure.lang.RT.classForName(RT.java:2177)
	at clojure.lang.RT.loadClassForName(RT.java:2196)
	at clojure.lang.RT.load(RT.java:443)
	at clojure.lang.RT.load(RT.java:419)
	at clojure.core$load$fn__5677.invoke(core.clj:5893)
	at clojure.core$load.invokeStatic(core.clj:5892)
	at clojure.core$load.doInvoke(core.clj:5876)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5697)
	at clojure.core$load_one.invoke(core.clj:5692)
	at clojure.core$load_lib$fn__5626.invoke(core.clj:5737)
	at clojure.core$load_lib.invokeStatic(core.clj:5736)
	at clojure.core$load_lib.doInvoke(core.clj:5717)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$load_libs.invokeStatic(core.clj:5774)
	at clojure.core$load_libs.doInvoke(core.clj:5758)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:648)
	at clojure.core$require.invokeStatic(core.clj:5796)
	at clojure.core$require.doInvoke(core.clj:5796)
	at clojure.lang.RestFn.invoke(RestFn.java:436)
	at qbits.commons.enum$eval7527$loading__5569__auto____7528.invoke(enum.clj:1)
	at qbits.commons.enum$eval7527.invokeStatic(enum.clj:1)
	at qbits.commons.enum$eval7527.invoke(enum.clj:1)
	at clojure.lang.Compiler.eval(Compiler.java:6927)
	at clojure.lang.Compiler.eval(Compiler.java:6916)
	at clojure.lang.Compiler.load(Compiler.java:7379)
	... 127 more
Caused by: java.lang.IllegalStateException: Attempting to call unbound fn: #'clojure.core/ident?
	at clojure.lang.Var$Unbound.throwArity(Var.java:43)
	at clojure.lang.AFn.invoke(AFn.java:32)
	at clojure.spec.alpha$spec_impl.invokeStatic(alpha.clj:915)
	at clojure.spec.alpha$spec_impl.invoke(alpha.clj:908)
	at clojure.spec.alpha__init.load(Unknown Source)
	at clojure.spec.alpha__init.<clinit>(Unknown Source)
	... 158 more
Tests failed.

[org.clojure/tools.logging "0.3.1"]]}}
:plugins [[lein-rpm "0.0.5"
:exclusions [org.apache.maven/maven-plugin-api
Expand Down
128 changes: 128 additions & 0 deletions src/riemann/plugin/samplerr.clj
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,131 @@
(let [service (apply rotation-service opts)]
(swap! riemann.config/next-core core/conj-service service :force)))

(defn index-parts
"Match the year, month and day out of an index name"
[index]
(let [index-name (:index index)]
(rest (re-find #"(\d{4})(?:\.(\d{2})(?:\.(\d{2}))?)?$" index-name))))

(defn index-year
"Return the year of an index as an Integer"
[index]
(Integer. (first (index-parts index))))

(defn index-month
"Return the month of an index as an Integer"
[index]
(Integer. (or (second (index-parts index)) "1")))

(defn index-day
"Return the day of an index as an Integer"
[index]
(Integer. (or (nth (index-parts index) 2) "1")))

(defn yearly-index?
"Return true if an index has yearly data"
[index]
(= nil (second (index-parts index))))

(defn monthly-index?
"Return true if an index has monthly data"
[index]
(and
(not (yearly-index? index))
(= nil (nth (index-parts index) 2))))

(defn daily-index?
"Return true if an index has daily data"
[index]
(and
(not (yearly-index? index))
(not (monthly-index? index))))

(defn index-start-timestamp
"Return an ISO timestamp of the time the index starts at"
[index]
(format "%02d-%02d-%02dT00:00:00Z" (index-year index) (index-month index) (index-day index)))

(defn compact
"Remove nil items from a collection"
[coll]
(remove nil? coll))

(defn remove-existing-aliases-query
"Return a query to remove all the passed aliases"
[aliases]
{:url "_aliases" :method :post :body {:actions (map #(if true {:remove {:index (:index %) :alias (:alias %)}}) aliases)}})

(defn create-aliases-query
"Return a query to create the aliases to query all passed indices"
[indices index-prefix alias-prefix]
(let [yearly-indices (filter #(re-find #"\d{4}$" (:index %)) indices)
monthly-indices (filter #(re-find #"\d{4}\.\d{2}$" (:index %)) indices)
daily-indices (filter #(re-find #"\d{4}\.\d{2}\.\d{2}$" (:index %)) indices)
first-monthly-index (first monthly-indices)
first-daily-index (first daily-indices)
yearly-aliases (compact
(map #(if (< (index-year %) (index-year first-monthly-index))
{:add {:index (:index %) :alias (clojure.string/replace (:index %) index-prefix alias-prefix)}}
(if (= (index-year %) (index-year first-monthly-index))
{:add {:index (:index %) :alias (clojure.string/replace (:index %) index-prefix alias-prefix) :filter {:range {"@timestamp" {:lt (index-start-timestamp first-monthly-index)}}}}})
) yearly-indices))
monthly-aliases (compact
(map #(if (or (< (index-year %) (index-year first-daily-index))
(and (= (index-year %) (index-year first-daily-index))
(< (index-month %) (index-month first-daily-index))))
{:add {:index (:index %) :alias (clojure.string/replace (:index %) index-prefix alias-prefix)}}
(if (and (= (index-year %) (index-year first-daily-index))
(= (index-month %) (index-month first-daily-index)))
{:add {:index (:index %) :alias (clojure.string/replace (:index %) index-prefix alias-prefix) :filter {:range {"@timestamp" {:lt (index-start-timestamp first-daily-index)}}}}})
) monthly-indices))
daily-aliases (map #(if true {:add {:index (:index %) :alias (clojure.string/replace (:index %) index-prefix alias-prefix)}}) daily-indices)]
{:url "_aliases" :method :post :body {:actions (concat yearly-aliases monthly-aliases daily-aliases)}}))

(defn update-aliases
"Maintain samplerr aliases"
[{:keys [conn index-prefix alias-prefix] :or {alias-prefix "samplerr-" index-prefix ".samplerr-"}}]
(let [response (es/request conn {:url (str "_cat/aliases/" alias-prefix "*?format=json&s=alias") :method :get})
aliases (:body response)]
(if (seq aliases)
(do
(info "Removing samplerr aliases")
(es/request conn (remove-existing-aliases-query aliases)))))
(let [response (es/request conn {:url (str "_cat/indices/" index-prefix "*?format=json&s=index") :method :get})
indices (:body response)]
(if (seq indices)
(do
(info "Creating samplerr aliases")
(es/request conn (create-aliases-query indices index-prefix alias-prefix))))))

(defn maintain
"Perform samplerr maintenance"
[{:keys [conn alias-prefix index-prefix archives purge? update-aliases?]
:or {alias-prefix "samplerr-"
index-prefix ".samplerr-"
purge? false
update-aliases? true}}]
(if purge?
(purge {:conn conn :index-prefix index-prefix :archives archives}))
(if update-aliases?
(update-aliases {:conn conn :index-prefix index-prefix :alias-prefix alias-prefix})))

(defn periodically-maintain
"Periodically perform samplerr maintenance"
[{:keys [conn archives alias-prefix index-prefix purge? update-aliases?]
:or {alias-prefix "samplerr-"
index-prefix ".samplerr-"
purge? false
update-aliases? true}}]
(let [rotation-interval 86400
rotation-delay 60
beginning-of-last-rotation-interval (* (quot (unix-time) rotation-interval) rotation-interval)
beginning-of-next-rotation-interval (riemann.time/next-tick beginning-of-last-rotation-interval rotation-interval)
daily-rotation-delay (+ beginning-of-next-rotation-interval rotation-delay)
do-maintain (fn [] (maintain {:conn conn :alias-prefix alias-prefix :index-prefix index-prefix :archives archives :purge? purge? :update-aliases? update-aliases?}))]
(info (str "Scheduling startup samplerr maintenance in " rotation-delay " seconds"))
(riemann.time/after! rotation-delay do-maintain)
(info (str "Scheduling daily samplerr maintenance at " (.format (java.text.SimpleDateFormat. "yyyy-MM-dd'T'HH:mm:ssXXX") (* 1000 daily-rotation-delay))))
(riemann.time/once!
daily-rotation-delay
(fn [] (riemann.time/every! rotation-interval do-maintain)))))
91 changes: 91 additions & 0 deletions test/riemann/plugin/samplerr_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
(ns riemann.plugin.samplerr-test
(:require [clojure.test :refer :all]
[riemann.plugin.samplerr :refer :all]
))

(deftest identify-index-date
(let [index {:index "samplerr-2020"}]
(is (= true (yearly-index? index)))
(is (= false (monthly-index? index)))
(is (= false (daily-index? index)))
(is (= '("2020" nil nil) (index-parts index)))
(is (= 1 (index-day index)))
(is (= 1 (index-month index)))
(is (= 2020 (index-year index)))
(is (= "2020-01-01T00:00:00Z" (index-start-timestamp index))))
(let [index {:index "samplerr-2020.04"}]
(is (= false (yearly-index? index)))
(is (= true (monthly-index? index)))
(is (= false (daily-index? index)))
(is (= '("2020" "04" nil) (index-parts index)))
(is (= 1 (index-day index)))
(is (= 4 (index-month index)))
(is (= 2020 (index-year index)))
(is (= "2020-04-01T00:00:00Z" (index-start-timestamp index))))
(let [index {:index "samplerr-2020.04.22"}]
(is (= false (yearly-index? index)))
(is (= false (monthly-index? index)))
(is (= true (daily-index? index)))
(is (= '("2020" "04" "22") (index-parts index)))
(is (= 22 (index-day index)))
(is (= 4 (index-month index)))
(is (= 2020 (index-year index)))
(is (= "2020-04-22T00:00:00Z" (index-start-timestamp index)))))

(deftest test-remove-existing-aliases-query
(let [aliases '({:index ".samplerr-2021" :alias "samplerr-2021"}
{:index ".samplerr-2022" :alias "samplerr-2022"}
{:index ".samplerr-2022.12" :alias "samplerr-2022.12"}
{:index ".samplerr-2022.12.04" :alias "samplerr-2022.12.04"})]
(is (= {:url "_aliases"
:method :post
:body {:actions '({:remove {:index ".samplerr-2021" :alias "samplerr-2021"}}
{:remove {:index ".samplerr-2022" :alias "samplerr-2022"}}
{:remove {:index ".samplerr-2022.12" :alias "samplerr-2022.12"}}
{:remove {:index ".samplerr-2022.12.04" :alias "samplerr-2022.12.04"}})}}
(remove-existing-aliases-query aliases)))))
(deftest test-create-aliases-query
(let [indices '({:index ".samplerr-2021"}
{:index ".samplerr-2022"}
{:index ".samplerr-2022.10"}
{:index ".samplerr-2022.11"}
{:index ".samplerr-2022.12"}
{:index ".samplerr-2023"}
{:index ".samplerr-2023.01"}
{:index ".samplerr-2023.01.23"}
{:index ".samplerr-2023.01.24"}
{:index ".samplerr-2023.01.25"}
{:index ".samplerr-2023.01.26"}
{:index ".samplerr-2023.01.27"}
{:index ".samplerr-2023.01.28"}
{:index ".samplerr-2023.01.29"}
{:index ".samplerr-2023.01.30"}
{:index ".samplerr-2023.01.31"}
{:index ".samplerr-2023.02"}
{:index ".samplerr-2023.02.01"}
{:index ".samplerr-2023.02.02"}
{:index ".samplerr-2023.02.03"}
{:index ".samplerr-2023.02.04"})]
(is (= {:url "_aliases"
:method :post
:body {:actions '({:add {:index ".samplerr-2021" :alias "samplerr-2021"}}
{:add {:index ".samplerr-2022" :alias "samplerr-2022" :filter {:range {"@timestamp" {:lt "2022-10-01T00:00:00Z"}}}}}
{:add {:index ".samplerr-2022.10" :alias "samplerr-2022.10"}}
{:add {:index ".samplerr-2022.11" :alias "samplerr-2022.11"}}
{:add {:index ".samplerr-2022.12" :alias "samplerr-2022.12"}}
{:add {:index ".samplerr-2023.01" :alias "samplerr-2023.01" :filter {:range {"@timestamp" {:lt "2023-01-23T00:00:00Z"}}}}}
{:add {:index ".samplerr-2023.01.23" :alias "samplerr-2023.01.23"}}
{:add {:index ".samplerr-2023.01.24" :alias "samplerr-2023.01.24"}}
{:add {:index ".samplerr-2023.01.25" :alias "samplerr-2023.01.25"}}
{:add {:index ".samplerr-2023.01.26" :alias "samplerr-2023.01.26"}}
{:add {:index ".samplerr-2023.01.27" :alias "samplerr-2023.01.27"}}
{:add {:index ".samplerr-2023.01.28" :alias "samplerr-2023.01.28"}}
{:add {:index ".samplerr-2023.01.29" :alias "samplerr-2023.01.29"}}
{:add {:index ".samplerr-2023.01.30" :alias "samplerr-2023.01.30"}}
{:add {:index ".samplerr-2023.01.31" :alias "samplerr-2023.01.31"}}
{:add {:index ".samplerr-2023.02.01" :alias "samplerr-2023.02.01"}}
{:add {:index ".samplerr-2023.02.02" :alias "samplerr-2023.02.02"}}
{:add {:index ".samplerr-2023.02.03" :alias "samplerr-2023.02.03"}}
{:add {:index ".samplerr-2023.02.04" :alias "samplerr-2023.02.04"}}
)}}
(create-aliases-query indices ".samplerr-" "samplerr-")))))