def getQueryParams(args): print("Obtaining query params from the database.") client = tsquery.createQueryClient(args.endpoint, profile=args.profile) ## Use the following query to get the query parameters from the data ## by picking attributes each type of time series to initialize the dimensions. ## Introduces some randomization to enable multiple executions to pick different parameters. queryStr = """ WITH selectedTaskCompleted AS ( SELECT * FROM "{0}"."{1}" WHERE measure_name = 'task_completed' AND time BETWEEN {2} - 2h AND {2} LIMIT 100 ), selectedCpu AS ( SELECT t.* FROM "{0}"."{1}" t INNER JOIN selectedTaskCompleted c ON c.instance_name = t.instance_name WHERE t.measure_name = 'cpu_user' AND t.time BETWEEN {2} - 2h AND {2} ORDER BY random() LIMIT 1 ) SELECT * FROM( ( SELECT * FROM selectedCpu ) UNION ( SELECT * FROM selectedTaskCompleted ) ) ORDER BY measure_name """.format(args.databaseName, args.tableName, args.queryEndTime) print(queryStr) result = tsquery.executeQueryAndReturnAsDataframe(client, queryStr, True) params = Params(args.databaseName, args.tableName, result['region'][0], result['availability_zone'][0], result['cell'][0], result['silo'][0], result['microservice_name'][0], result['instance_type'][0], result['os_version'][0], result['instance_name'][0], result['process_name'][1], result['jdk_version'][1]) return params
def __init__(self, threadId, args, startTime, queryProvider, tableName=None): threading.Thread.__init__(self) self.threadId = threadId self.args = args self.startTime = startTime self.config = configparser.ConfigParser() self.config.read(args.config) retries = int( self.config.get(configDefaultSection, configRetries, fallback=0)) self.client = tsquery.createQueryClient(region=args.region, profile=args.profile, retries=retries, endpoint=args.endpoint) self.output = () self.tps = 0.0 self.queryCount = 0 self.tableName = tableName ## Query parameters if self.args.fixedParams: ## Use fixed query parameters self.params = Params( self.args.databaseName, self.args.tableName, 'eu-west-1', 'eu-west-1-1', 'eu-west-1-cell-8', 'eu-west-1-cell-8-silo-1', 'apollo', 'r5.4xlarge', 'AL2', 'i-ojtoEEXU-apollo-eu-west-1-cell-8-silo-1-00000033.amazonaws.com', 'host_manager', 'JDK_8') else: ## Read the query parameters from the database and table. self.params = getQueryParams(self.args) print(self.params) queryInstances = queryProvider(self.params, args.queryEndTime, args.wide) ## Initialize the query mode. self.queryMode = self.config.get(configDefaultSection, configQueryMode, fallback=configQueryModeRegular) if self.queryMode not in [ configQueryModeRegular, configQueryModeRowCount ]: raise Exception('Unknown query mode: {}'.format(self.queryMode)) if self.queryMode == configQueryModeRegular: self.queries = getQueryStrings(queryInstances, self.params) else: queriesRowCount = createQueryInstancesRowCount( queryInstances, args.queryEndTime) self.queries = getQueryStrings(queriesRowCount, self.params) ## Initialize the query distributions. if configQueryDistributionSection not in self.config: raise Exception('Query distribution section missing') queryDistributions = self.config[configQueryDistributionSection] distributions = dict() for query in queryDistributions: if query not in self.queries: raise Exception('Unknown query: {}'.format(query)) if query in distributions: distributions[query] += float(queryDistributions[query]) / 100 else: distributions[query] = float(queryDistributions[query]) / 100 self.queriesSelected = list() self.queryWeights = list() sum = 0 for query in distributions.keys(): print('{} : {}'.format(query, distributions[query])) self.queriesSelected.append(query) self.queryWeights.append(distributions[query]) sum += distributions[query] print("Sum of probabilities: ", sum)