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

support OTP-26 #43

Closed
wants to merge 8 commits into from
Closed
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
27 changes: 27 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repository:
name: beetrix
description: |
High-performance and reliable InfluxDB writer for Elixir.
private: true
has_issues: true
has_wiki: false
has_downloads: true
default_branch: master
allow_squash_merge: true
allow_merge_commit: true
allow_rebase_merge: true
topics: library

branches:
- name: master
protection:
required_pull_request_reviews:
required_approving_review_count: 1
dismiss_stale_reviews: false
require_code_owner_reviews: true
dismissal_restrictions: {}
required_status_checks:
strict: true
contexts: ["Bless"]
enforce_admins: false
restrictions: null
178 changes: 138 additions & 40 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,158 @@
name: CI
name: Actions CI

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

jobs:
format:
name: Code linting
runs-on: ubuntu-20.04
bless:
name: Bless
runs-on: ubuntu-latest
env:
MIX_ENV: test

steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3

- name: Determine the elixir version
run: echo "ELIXIR_VERSION=$(grep -h elixir .tool-versions | awk '{ print $2 }' | awk -F - '{print $1}')" >> $GITHUB_ENV

- name: Determine the otp version
run: echo "OTP_VERSION=$(grep -h erlang .tool-versions | awk '{ print $2 }')" >> $GITHUB_ENV

- name: Set up Elixir environment
uses: erlef/setup-elixir@v1
- name: Setup Elixir and Erlang versions
uses: erlef/setup-beam@v1
with:
otp-version: 23
elixir-version: 1.11
elixir-version: ${{ env.ELIXIR_VERSION }}
otp-version: ${{ env.OTP_VERSION }}

- name: Check unused dependencies
run: mix deps.get && mix deps.unlock --check-unused
- name: Restore the deps cache
uses: actions/cache@v3
id: deps-cache
with:
path: deps
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-

- name: Check format
run: mix format --check-formatted
- name: Restore the _build cache
uses: actions/cache@v3
id: build-cache
with:
path: _build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-build-mixlockhash-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-build-

- name: Check compilation warnings
run: mix compile --warnings-as-errors
- name: Fetch mix dependencies
if: steps.deps-cache.outputs.cache-hit != 'true'
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get

test:
name: Test suite
runs-on: ubuntu-20.04
- name: Compile dependencies
if: steps.deps-cache.outputs.cache-hit != 'true'
run: mix deps.compile

strategy:
matrix:
versions:
- otp: 20
elixir: 1.5
- otp: 23
elixir: 1.11
- name: Compile
run: mix compile --warnings-as-errors --force

- name: Check coverage
run: mix test

- name: Check formatting
run: mix format --check-formatted

build-github-release:
name: Build Github release ⬆️☁️
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
env:
MIX_ENV: test
MIX_ENV: dev
needs:
- bless

steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3

- name: Determine the elixir version
run: echo "ELIXIR_VERSION=$(grep -h elixir .tool-versions | awk '{ print $2 }' | awk -F - '{print $1}')" >> $GITHUB_ENV

- name: Determine the otp version
run: echo "OTP_VERSION=$(grep -h erlang .tool-versions | awk '{ print $2 }')" >> $GITHUB_ENV

- name: Set up Elixir environment
uses: erlef/setup-elixir@v1
- name: Setup Elixir and Erlang versions
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.versions.elixir }}
otp-version: ${{ matrix.versions.otp }}
elixir-version: ${{ env.ELIXIR_VERSION }}
otp-version: ${{ env.OTP_VERSION }}

- name: Install dependencies
run: mix deps.get --only test
- name: Restore the deps cache
uses: actions/cache@v3
id: deps-cache
with:
path: deps
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-

- name: Run tests
run: mix test
- name: Restore the _build cache
uses: actions/cache@v3
id: build-cache
with:
path: _build
key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-build-mixlockhash-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }}
restore-keys: |
${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-build-

- name: Fetch mix dependencies
if: steps.deps-cache.outputs.cache-hit != 'true'
run: |
mix local.rebar --force
mix local.hex --force
mix deps.get

- name: Compile dependencies
if: steps.deps-cache.outputs.cache-hit != 'true'
run: mix deps.compile

- name: Generate documentation
run: mix docs

- name: Determine the tag version
env:
GITHUB_REF: ${{ github.ref }}
run: echo "TAG=$(echo "$GITHUB_REF" | awk -F / '{print $3}')" >> $GITHUB_ENV

- name: Write the tag version to .library_version
run: echo $TAG > .library_version

- name: Determine the repository name
run: echo "REPOSITORY=$(echo $GITHUB_REPOSITORY | awk -F / '{print $2}')" >> $GITHUB_ENV

- name: Create a GitHub Release
id: create_release
uses: NFIBrokerage/create-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.TAG }}
name: Release ${{ env.TAG }}
draft: false
prerelease: false

- name: Publish library
run: mix hex.publish --yes --organization cuatro
env:
HEX_API_KEY: ${{ secrets.HEX_PUBLISH_KEY }}

- name: Notify ops channel of build success
run: >
curl
-X POST
-H 'Content-type:application/json'
-d "{\"text\":\":github: release published $REPOSITORY $(git tag -ln $TAG)\"}"
$SLACK_WEBHOOK
env:
SLACK_WEBHOOK: ${{ secrets.OPS_CHANNEL_SLACK_WEBHOOK }}
6 changes: 6 additions & 0 deletions .library_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
v0.0.0

# this file will be clobbered by github actions.
# to version bump, only create new tag in git, with v + semver.
#
# example tag would be: v0.1.5
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
elixir 1.15.5-otp-26
erlang 26.1
52 changes: 39 additions & 13 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,43 +1,69 @@
# Changelog

## v0.11.6

- Remove leading underscores in tag and field keys.

## v0.11.5

- Default `empty` value in fields must be quoted to be valid string field value.

## v0.11.4

- Handle empty strings in tag/field values

## v0.11.3

- Handle nils, atoms, lists and maps in tag/field keys/values

## v0.11.2

- Fix `no cond clause evaluated to a truthy value` in `Fluxter.Packet.encode_value/1`

## v0.11.1

- Make lib releasable on private hex.

### Before fork:

## v0.10.0

* Dropped support for Elixir versions older than 1.5.
- Dropped support for Elixir versions older than 1.5.

## v0.9.1

* Fixed the order when building prefix.
- Fixed the order when building prefix.

## v0.9.0

* Fixed prefix building when start options provided.
* Dropped support for Elixir v1.2.
- Fixed prefix building when start options provided.
- Dropped support for Elixir v1.2.

## v0.8.1

* Fixed port command for OTP versions that support ancillary data sending.
- Fixed port command for OTP versions that support ancillary data sending.

## v0.8.0

* Added support for module, function, arguments tuple in `measure/4`.
- Added support for module, function, arguments tuple in `measure/4`.

## v0.7.1

* Fixed Elixir v1.6 warnings.
- Fixed Elixir v1.6 warnings.

## v0.7.0

* Added the `c:Fluxter.start_link/1` callback to support runtime configuration.
- Added the `c:Fluxter.start_link/1` callback to support runtime configuration.

__Deprecations:__
**Deprecations:**

* Passing child specification options to `child_spec/1` is deprecated.
- Passing child specification options to `child_spec/1` is deprecated.

## v0.6.1

* Fixed a bug in the `c:Fluxter.child_spec/1` callback.
- Fixed a bug in the `c:Fluxter.child_spec/1` callback.

## v0.6.0

* Added the `c:Fluxter.child_spec/1` callback.
* Started flushing counters synchronously when calling `Fluxter.flush_counter/1`.
- Added the `c:Fluxter.child_spec/1` callback.
- Started flushing counters synchronously when calling `Fluxter.flush_counter/1`.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Fluxter

![CI Status](https://github.com/lexmag/fluxter/workflows/CI/badge.svg)
[![Hex Version](https://img.shields.io/hexpm/v/fluxter.svg "Hex Version")](https://hex.pm/packages/fluxter)
[![Hex Version](https://img.shields.io/hexpm/v/fluxter.svg "Original Hex Version")](https://hex.pm/packages/fluxter)

Fluxter is an [InfluxDB](https://www.influxdata.com/) writer for Elixir. It uses the InfluxDB line protocol over UDP.

Expand All @@ -11,7 +11,7 @@ Add Fluxter as a dependency to your `mix.exs` file:

```elixir
defp deps() do
[{:fluxter, "~> 0.8"}]
[{:fluxter, "~> 0.11"}]
end
```

Expand Down
23 changes: 10 additions & 13 deletions lib/fluxter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ defmodule Fluxter do
@doc """
Should be the same as `measure(measurement, [], [], fun_or_mfa)`.
"""
@callback measure(measurement, (() -> result) | mfa()) :: result when result: var
@callback measure(measurement, (-> result) | mfa()) :: result when result: var

@doc """
Should be the same as `measure(measurement, tags, [], fun_or_mfa)`.
"""
@callback measure(measurement, tags, (() -> result) | mfa()) :: result when result: var
@callback measure(measurement, tags, (-> result) | mfa()) :: result when result: var

@doc """
Measures the execution time of `fun_or_mfa` and writes it as a metric.
Expand Down Expand Up @@ -195,7 +195,7 @@ defmodule Fluxter do
2

"""
@callback measure(measurement, tags, fields, (() -> result) | mfa()) :: result when result: var
@callback measure(measurement, tags, fields, (-> result) | mfa()) :: result when result: var

@doc """
Should be the same as `start_counter(measurement, [], [])`.
Expand Down Expand Up @@ -312,10 +312,7 @@ defmodule Fluxter do

config = Fluxter.get_config(__MODULE__, options)

conn =
config.host
|> Fluxter.Conn.new(config.port)
|> Map.update!(:header, &[&1 | config.prefix])
conn = Fluxter.Conn.new(config.host, config.port, config.prefix)

@worker_names
|> Enum.map(fn name ->
Expand All @@ -333,19 +330,19 @@ defmodule Fluxter do

def write(measurement, tags \\ [], fields)

def write(measurement, tags, fields) when is_list(fields) do
def write(measurement, tags, [{_, _} | _] = fields) do
[:positive]
|> System.unique_integer()
|> rem(@pool_size)
|> worker_name()
|> Fluxter.Conn.write(measurement, tags, fields)
end

def write(measurement, tags, value)
when is_float(value) or is_integer(value)
when is_boolean(value) or is_binary(value) do
write(measurement, tags, value: value)
end
def write(measurement, tags, value) when is_list(value) or is_map(value),
do: write(measurement, tags, value: inspect(value))

def write(measurement, tags, value),
do: write(measurement, tags, value: value)

def measure(measurement, tags \\ [], fields \\ [], fun_or_mfa) do
{elapsed_time, result} =
Expand Down
Loading