Search in sources :

Example 1 with ClientTableEntityPrefixNameWrapper

use of io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper in project datarouter by hotpads.

the class NodeBuilder method build.

public <N extends NodeOps<PK, D>> N build() {
    String databeanName = databeanSupplier.get().getDatabeanName();
    String entityName = databeanName + "Entity";
    String entityNodePrefix = null;
    String nodeTableName = tableName != null ? tableName : databeanName;
    NodewatchConfiguration tableConfig = null;
    if (nodewatchConfigurationBuilder != null) {
        tableConfig = nodewatchConfigurationBuilder.create(new ClientTableEntityPrefixNameWrapper(clientId.getName(), nodeTableName, entityNodePrefix));
    }
    NodeParams<PK, D, F> params = new NodeParamsBuilder<>(databeanSupplier, fielderSupplier).withClientId(clientId).withDiagnostics(enableDiagnosticsSupplier).withEntity(entityName, entityNodePrefix).withParentName(entityName).withTableName(nodeTableName).withSchemaVersion(schemaVersion).withTableConfiguration(tableConfig).withDisableForcePrimary(disableForcePrimary).withTag(tag).withDisableIntroducer(disableIntroducer).build();
    EntityNodeParams<EK, DefaultEntity<EK>> entityNodeParams = new EntityNodeParams<>(clientId.getName() + "." + entityName, entityKeySupplier, DefaultEntity.supplier(entityKeySupplier), partitionerSupplier, entityName);
    return nodeFactory.create(entityNodeParams, params);
}
Also used : DefaultEntity(io.datarouter.storage.node.entity.DefaultEntity) NodewatchConfiguration(io.datarouter.storage.node.tableconfig.NodewatchConfiguration) ClientTableEntityPrefixNameWrapper(io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper) EntityNodeParams(io.datarouter.storage.node.entity.EntityNodeParams)

Example 2 with ClientTableEntityPrefixNameWrapper

use of io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper in project datarouter by hotpads.

the class TableSizeMonitoringService method getAboveThresholdLists.

public Twin<List<CountStat>> getAboveThresholdLists() {
    List<CountStat> aboveThresholdList = new ArrayList<>();
    List<CountStat> abovePercentageList = new ArrayList<>();
    for (PhysicalNode<?, ?, ?> node : datarouterNodes.getWritableNodes(clients.getClientIds())) {
        ClientTableEntityPrefixNameWrapper nodeNames = new ClientTableEntityPrefixNameWrapper(node);
        String tableName = nodeNames.getTableName();
        String clientName = nodeNames.getClientName();
        NodewatchConfiguration nodeConfig = null;
        Long threshold = null;
        boolean enablePercentChangeAlert = true;
        boolean enableThresholdAlert = true;
        nodeConfig = tableConfigurationService.getTableConfigMap().get(nodeNames);
        if (nodeConfig != null) {
            threshold = nodeConfig.maxThreshold;
            enablePercentChangeAlert = nodeConfig.enablePercentageAlert;
            enableThresholdAlert = nodeConfig.enableThresholdAlert;
        }
        // continue if the nodeConfig isCountable is set to false
        if (nodeConfig != null && !nodeConfig.isCountable) {
            continue;
        }
        List<TableCount> tableCountRecords = tableCountDao.getForTable(clientName, tableName);
        if (tableCountRecords.size() < 2) {
            continue;
        }
        Collections.sort(tableCountRecords, new TableCount.TableCountLatestEntryComparator());
        TableCount latest = tableCountRecords.get(0);
        TableCount previous = tableCountRecords.get(1);
        if (previous.getNumRows() == 0) {
            continue;
        }
        // skip if the table has records less than the count_threshold
        if (smallEnoughToIgnore(latest.getNumRows()) && smallEnoughToIgnore(previous.getNumRows())) {
            continue;
        }
        if (enableThresholdAlert) {
            Optional<TableSizeAlertThreshold> thresholdEntry = tableSizeAlertThresholdDao.find(new TableSizeAlertThresholdKey(clientName, tableName));
            // override manual thresholdEntry if exists
            if (thresholdEntry.isPresent() && thresholdEntry.get().getMaxRows() > 0) {
                threshold = thresholdEntry.get().getMaxRows();
            }
            // check if node numRows exceeds threshold
            if (threshold != null && latest.getNumRows() >= threshold) {
                aboveThresholdList.add(calculateStats(latest, threshold));
            }
        }
        if (enablePercentChangeAlert) {
            // check % growth if no absolute threshold set & !enablePercentChangeAlert
            CountStat growthIncrease = calculateStats(latest, previous.getNumRows());
            if (growthIncrease == null) {
                continue;
            }
            if (Math.abs(growthIncrease.percentageIncrease) > PERCENTAGE_THRESHOLD) {
                abovePercentageList.add(growthIncrease);
            }
        }
    }
    return new Twin<>(aboveThresholdList, abovePercentageList);
}
Also used : NodewatchConfiguration(io.datarouter.storage.node.tableconfig.NodewatchConfiguration) ArrayList(java.util.ArrayList) Twin(io.datarouter.util.tuple.Twin) TableSizeAlertThreshold(io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThreshold) LatestTableCount(io.datarouter.nodewatch.storage.latesttablecount.LatestTableCount) TableCount(io.datarouter.nodewatch.storage.tablecount.TableCount) TableSizeAlertThresholdKey(io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThresholdKey) ClientTableEntityPrefixNameWrapper(io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper)

Example 3 with ClientTableEntityPrefixNameWrapper

use of io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper in project datarouter by hotpads.

the class TableCountJob method run.

@Override
public void run(TaskTracker tracker) {
    tableSamplerService.scanCountableNodes().advanceUntil($ -> tracker.shouldStop()).each($ -> tracker.increment()).map(ClientTableEntityPrefixNameWrapper::new).each(item -> tracker.setLastItemProcessed(item.toString())).map(nodeNames -> tableSamplerService.getCurrentTableCountFromSamples(nodeNames.getClientName(), nodeNames.getTableName())).forEach(tableCount -> {
        tableCountDao.put(tableCount);
        latestTableCountDao.put(new LatestTableCount(tableCount));
    });
}
Also used : Inject(javax.inject.Inject) DatarouterTableCountDao(io.datarouter.nodewatch.storage.tablecount.DatarouterTableCountDao) DatarouterLatestTableCountDao(io.datarouter.nodewatch.storage.latesttablecount.DatarouterLatestTableCountDao) LatestTableCount(io.datarouter.nodewatch.storage.latesttablecount.LatestTableCount) TableSamplerService(io.datarouter.nodewatch.service.TableSamplerService) BaseJob(io.datarouter.job.BaseJob) TaskTracker(io.datarouter.instrumentation.task.TaskTracker) ClientTableEntityPrefixNameWrapper(io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper) LatestTableCount(io.datarouter.nodewatch.storage.latesttablecount.LatestTableCount)

Example 4 with ClientTableEntityPrefixNameWrapper

use of io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper in project datarouter by hotpads.

the class TableSamplerService method isCountableNode.

public boolean isCountableNode(PhysicalNode<?, ?, ?> physicalNode) {
    boolean isCountableTable = isCountableTable(new ClientTableEntityPrefixNameWrapper(physicalNode));
    if (!isCountableTable) {
        return false;
    }
    boolean isCountableClient = nodewatchClientConfiguration.isCountableClient(physicalNode.getFieldInfo().getClientId());
    boolean isSortedStorageWriter = physicalNode instanceof SortedStorageWriter;
    boolean hasStringKeyFields = physicalNode.getFieldInfo().getPrimaryKeyFields().stream().anyMatch(field -> field instanceof StringField || field instanceof StringEnumField);
    boolean hasBinaryCollation = MysqlTableOptions.make(physicalNode.getFieldInfo().getSampleFielder()).getCollation().isBinary();
    return isCountableClient && isSortedStorageWriter && (!hasStringKeyFields || hasBinaryCollation);
}
Also used : SortedStorageWriter(io.datarouter.storage.node.op.raw.write.SortedStorageWriter) StringField(io.datarouter.model.field.imp.StringField) StringEnumField(io.datarouter.model.field.imp.enums.StringEnumField) ClientTableEntityPrefixNameWrapper(io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper)

Example 5 with ClientTableEntityPrefixNameWrapper

use of io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper in project datarouter by hotpads.

the class TableSizeMonitoringService method getStaleTableEntries.

public List<LatestTableCount> getStaleTableEntries() {
    return datarouterLatestTableCountDao.scan().exclude(latestTableCount -> {
        ClientTableEntityPrefixNameWrapper nodeName = new ClientTableEntityPrefixNameWrapper(latestTableCount.getKey().getClientName(), latestTableCount.getKey().getTableName(), null);
        NodewatchConfiguration nodeConfig = tableConfigurationService.getTableConfigMap().get(nodeName);
        return nodeConfig != null && !nodeConfig.isCountable;
    }).include(this::checkStaleEntries).list();
}
Also used : NodewatchConfiguration(io.datarouter.storage.node.tableconfig.NodewatchConfiguration) ClientTableEntityPrefixNameWrapper(io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper)

Aggregations

ClientTableEntityPrefixNameWrapper (io.datarouter.storage.node.tableconfig.ClientTableEntityPrefixNameWrapper)5 NodewatchConfiguration (io.datarouter.storage.node.tableconfig.NodewatchConfiguration)3 LatestTableCount (io.datarouter.nodewatch.storage.latesttablecount.LatestTableCount)2 TaskTracker (io.datarouter.instrumentation.task.TaskTracker)1 BaseJob (io.datarouter.job.BaseJob)1 StringField (io.datarouter.model.field.imp.StringField)1 StringEnumField (io.datarouter.model.field.imp.enums.StringEnumField)1 TableSamplerService (io.datarouter.nodewatch.service.TableSamplerService)1 TableSizeAlertThreshold (io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThreshold)1 TableSizeAlertThresholdKey (io.datarouter.nodewatch.storage.alertthreshold.TableSizeAlertThresholdKey)1 DatarouterLatestTableCountDao (io.datarouter.nodewatch.storage.latesttablecount.DatarouterLatestTableCountDao)1 DatarouterTableCountDao (io.datarouter.nodewatch.storage.tablecount.DatarouterTableCountDao)1 TableCount (io.datarouter.nodewatch.storage.tablecount.TableCount)1 DefaultEntity (io.datarouter.storage.node.entity.DefaultEntity)1 EntityNodeParams (io.datarouter.storage.node.entity.EntityNodeParams)1 SortedStorageWriter (io.datarouter.storage.node.op.raw.write.SortedStorageWriter)1 Twin (io.datarouter.util.tuple.Twin)1 ArrayList (java.util.ArrayList)1 Inject (javax.inject.Inject)1