-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added influxdata/influxdb-client-php and deps * Moved InfluxDB::getNanosecondTimestamp to trait * Added InfluxDB2 support * Fixed env variable name * Added MetricsManager::createInfluxdb2Driver * Removed unused namespaces * Fix createInfluxDB2Driver * Fix namespace * Add default write precision * Add InfluxDB2 to provides list * Add default value for $points * Removed configurability of WritePrecision * Add InfluxDB adapters * Convert InfluxDB driver to use adapter * Remove InfluxDB2 driver * Add IDB_VERSION env variable * Create adapters inside Service Provider * Force legacy tests to use Version 1 adapter * Changed tests to match adapter pattern * Remove AbstractInfluxDBAdapter::__construct * Change default signature for writePoints * Fix ternary if statement * Call write points on adapter * Construct with UDP flag when necessary * Add missing configuration values * Set org default to empty string * Set InfluxDB Adapter V1 as default * Updated README * README pass 2 * fix typed point --------- Co-authored-by: David Frailey <[email protected]> Co-authored-by: Joseph Szobody <[email protected]>
- Loading branch information
1 parent
d6a59f5
commit 4e5b02d
Showing
13 changed files
with
404 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
namespace STS\Metrics\Adapters; | ||
|
||
use InfluxDB\Database; | ||
use InfluxDB2\QueryApi; | ||
use InfluxDB2\UdpWriter; | ||
use InfluxDB2\WriteApi; | ||
use STS\Metrics\Traits\ComputesNanosecondTimestamps; | ||
|
||
abstract class AbstractInfluxDBAdapter | ||
{ | ||
use ComputesNanosecondTimestamps; | ||
|
||
protected Database|QueryApi $readConnection; | ||
|
||
protected Database|WriteApi|UdpWriter $writeConnection; | ||
|
||
public function getReadConnection(): Database|QueryApi | ||
{ | ||
return $this->readConnection; | ||
} | ||
|
||
public function setReadConnection(Database|QueryApi $connection): static | ||
{ | ||
$this->readConnection = $connection; | ||
|
||
return $this; | ||
} | ||
|
||
public function getWriteConnection(): Database|WriteApi|UdpWriter | ||
{ | ||
return $this->writeConnection; | ||
} | ||
|
||
public function setWriteConnection(Database|WriteApi|UdpWriter $connection): static | ||
{ | ||
$this->writeConnection = $connection; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Pass through to the Influx client anything we don't handle. | ||
*/ | ||
public function __call($method, $parameters): mixed | ||
{ | ||
if (strpos($method, 'write') === 0) { | ||
return $this->getWriteConnection()->$method(...$parameters); | ||
} | ||
|
||
return $this->getReadConnection()->$method(...$parameters); | ||
} | ||
|
||
abstract public function point( | ||
string $measurement, | ||
mixed $value = null, | ||
array $tags = [], | ||
array $fields = [], | ||
mixed $timestamp = null | ||
); | ||
|
||
abstract public function writePoints(array $points, $precision = null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace STS\Metrics\Adapters; | ||
|
||
use InfluxDB\Database; | ||
use InfluxDB\Database\Exception; | ||
use InfluxDB\Point; | ||
|
||
class InfluxDB1Adapter extends AbstractInfluxDBAdapter | ||
{ | ||
public function __construct(Database $tcpConnection, ?Database $udpConnection = null) | ||
{ | ||
$this->readConnection = $tcpConnection; | ||
|
||
$this->writeConnection = is_null($udpConnection) | ||
? $tcpConnection | ||
: $udpConnection; | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function point( | ||
string $measurement, | ||
mixed $value = null, | ||
array $tags = [], | ||
array $fields = [], | ||
mixed $timestamp = null | ||
): Point | ||
{ | ||
return new Point( | ||
$measurement, | ||
$value, | ||
$tags, | ||
$fields, | ||
$this->getNanoSecondTimestamp($timestamp) | ||
); | ||
} | ||
|
||
/** | ||
* @throws \InfluxDB\Exception | ||
*/ | ||
public function writePoints(array $points, $precision = Database::PRECISION_NANOSECONDS) | ||
{ | ||
return $this->getWriteConnection()->writePoints($points, $precision); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace STS\Metrics\Adapters; | ||
|
||
use InfluxDB2\Client; | ||
use InfluxDB2\Point; | ||
use Throwable; | ||
|
||
class InfluxDB2Adapter extends AbstractInfluxDBAdapter | ||
{ | ||
public function __construct( | ||
Client $client, | ||
bool $useUdp = false | ||
) | ||
{ | ||
$this->readConnection = $client->createQueryApi(); | ||
$this->writeConnection = $useUdp | ||
? $client->createUdpWriter() | ||
: $client->createWriteApi(); | ||
} | ||
|
||
public function point( | ||
string $measurement, | ||
mixed $value = null, | ||
array $tags = [], | ||
array $fields = [], | ||
mixed $timestamp = null | ||
): Point | ||
{ | ||
return new Point( | ||
$measurement, | ||
$tags, | ||
array_merge(compact('value'), $fields), | ||
$this->getNanoSecondTimestamp($timestamp) | ||
); | ||
} | ||
|
||
/** | ||
* @throws Throwable | ||
*/ | ||
public function writePoints(array $points, $precision = Point::DEFAULT_WRITE_PRECISION) | ||
{ | ||
$this->getWriteConnection()->write($points, $precision); | ||
return true; | ||
} | ||
|
||
} |
Oops, something went wrong.