Skip to content

Commit

Permalink
fix: labels and colors at logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jacovinus committed Apr 25, 2022
1 parent b885bad commit 0e80cbc
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 202 deletions.
29 changes: 17 additions & 12 deletions src/actions/loadLabels.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from "axios";
import { setLabels } from "./setLabels";
import setLoading from "./setLoading";
import { setApiError } from "./setApiError";
import { createAlert } from "./createAlert";

export default function loadLabels(apiUrl) {
const origin = window.location.origin;
Expand All @@ -26,30 +27,34 @@ export default function loadLabels(apiUrl) {
.get(`${url.trim()}/loki/api/v1/labels`, options)
?.then((response) => {
if (response) {
if (response?.data?.data === [])
if (response?.data?.data?.length > 0) {
const labels = response?.data?.data
.sort()
.map((label) => ({
let labels = response?.data?.data
?.sort()
?.map((label) => ({
name: label,
selected: false,
values: [],
}));
dispatch(setLabels(labels || []));

dispatch(setApiError(""));
if (labels) {
dispatch(setLabels(labels || []));
dispatch(setApiError(""));
dispatch(setLoading(false));
}
} else {
dispatch(createAlert({type:'info',message:'No labels available for this API'}))
}
} else {
dispatch(setLoading(false));
dispatch(
setApiError("")
);

dispatch(setApiError(""));
dispatch(setLabels([]));

}
})
.catch((error) => {
console.log(error);
dispatch(createAlert({
type:"error",
message:'API NOT FOUND'
}))
dispatch(setLoading(false));
dispatch(setLabels([]));
});
Expand Down
15 changes: 11 additions & 4 deletions src/actions/loadLogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,29 @@ export default function loadLogs() {
} = localStore;
let { start: startTs, stop: stopTs } = localStore;

function adjustForTimezone(date){

var timeOffsetInMS = date.getTimezoneOffset() * 60000;
date.setTime(date.getTime() + timeOffsetInMS);
return date
}

function getTimeParsed(time) {
return time.getTime() + "000000";
}

const timeZone = new Date().getTimezoneOffset()
const parsedStart = getTimeParsed(startTs);
const parsedStop = getTimeParsed(stopTs);

const parsedTime = "&start=" + (from || parsedStart) + "&end=" + (to || parsedStop);

if (findRangeByLabel(rangeLabel)) {
({ dateStart: startTs, dateEnd: stopTs } =
findRangeByLabel(rangeLabel));
}

store.dispatch(setStartTime(startTs));
store.dispatch(setStopTime(stopTs));

const origin = window.location.origin;
const url = apiUrl;
const queryStep = `&step=${step || 120}`;
Expand Down Expand Up @@ -113,13 +120,13 @@ export default function loadLogs() {
dispatch(setMatrixData(idResult || []));
dispatch(setLoading(false));
}
dispatch(setLoading(false));
// dispatch(setLoading(false));
} else {
dispatch(setLogs([]));
dispatch(setMatrixData([]));
dispatch(setLoading(false));
}
dispatch(setLoading(false));
// dispatch(setLoading(false));
})
.catch((error) => {

Expand Down
145 changes: 73 additions & 72 deletions src/components/DataView/DataView.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,73 @@
import React, { Component } from "react";
import { connect } from "react-redux";

import { DataViewCont, DataViewStyled, Loader } from "./styled";

import ClokiChart from "../../plugins/charts";
import QueryHistory from "../../plugins/queryhistory";
import LogsRow from "./LogsRow";
import EmptyView from "./EmptyView";

class DataView extends Component {
constructor(props) {
super(props);
this.state = {
limit: props.limit || 100,
messages: props.messages || [],
matrixData: props.matrixData || [],
loading: false,
};
}

getMatrixForChart = () => {
return this.props.matrixData;
};
getLimit = () => {
return this.props.limit;
};

render() {
return (
<DataViewStyled>
<DataViewCont>
{this.props.messages.length > 0 &&
this.getMatrixForChart().length < 1
? this.props.messages.map((message, key) => (
<LogsRow
message={message}
toggleTagsActive={this.toggleTagsActive}
key={key}
/>
))
: null}

{this.getMatrixForChart().length > 0 ? (
<ClokiChart
chartLimit={this.getLimit()}
matrixData={this.getMatrixForChart()}
/>
) : null}
{this.props.messages.length < 1 &&
this.getMatrixForChart().length < 1 &&
!this.props.loading && <EmptyView />}
<QueryHistory />
{this.props.loading && <Loader />}
</DataViewCont>
</DataViewStyled>
);
}
}

const mapStateToProps = (state) => {
return {
messages: state.logs,
start: state.start,
stop: state.stop,
limit: state.limit,
loading: state.loading,
matrixData: state.matrixData,
};
};

export default connect(mapStateToProps)(DataView);
import React, { Component } from "react";
import { connect } from "react-redux";

import { DataViewCont, DataViewStyled, Loader } from "./styled";
import ClokiChart from "../../plugins/charts";
import QueryHistory from "../../plugins/queryhistory";
import LogsRow from "./LogsRow";
import EmptyView from "./EmptyView";
// import Table from "../../plugins/tables/Table";

class DataView extends Component {
constructor(props) {
super(props);
this.state = {
limit: props.limit || 100,
messages: props.messages || [],
matrixData: props.matrixData || [],
loading: false,
};
}

getMatrixForChart = () => {
return this.props.matrixData;
};
getLimit = () => {
return this.props.limit;
};

render() {
return (
<DataViewStyled>
<DataViewCont>
{/* <Table/> */}
{this.props.messages.length > 0 &&
this.getMatrixForChart().length < 1
? this.props.messages.map((message, key) => (
<LogsRow
message={message}
toggleTagsActive={this.toggleTagsActive}
key={key}
/>
))
: null}

{this.getMatrixForChart().length > 0 ? (
<ClokiChart
chartLimit={this.getLimit()}
matrixData={this.getMatrixForChart()}
/>
) : null}
{this.props.messages.length < 1 &&
this.getMatrixForChart().length < 1 &&
!this.props.loading && <EmptyView />}
<QueryHistory />
{this.props.loading && <Loader />}
</DataViewCont>
</DataViewStyled>
);
}
}

const mapStateToProps = (state) => {
return {
messages: state.logs,
start: state.start,
stop: state.stop,
limit: state.limit,
loading: state.loading,
matrixData: state.matrixData,
};
};

export default connect(mapStateToProps)(DataView);
49 changes: 25 additions & 24 deletions src/components/DataView/helpers/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { LEVEL_COLORS as lColors } from "../theme/theme";
import { TAGS_LEVEL as tLevel } from "../consts/consts";
import * as moment from "moment";

export function getRowColor(tags) {
if (tags?.["level"]) {
const level = Object.keys(tLevel).find((level) =>
tLevel[level].includes(tags.level.toLowerCase())
);
return lColors[level];
} else {
return lColors["unknown"];
}
}

export function toggleActiveStyles(idx) {
return idx.showLabels
? "value-tags-container labelsActive"
: "value-tags-container labelsInactive";
}

export function formatDate(timestamp) {
return moment(parseInt(timestamp)).format("YYYY-MM-DD HH:mm:ss.SSS UTC");
}
import { LEVEL_COLORS as lColors } from "../theme/theme";
import { TAGS_LEVEL as tLevel } from "../consts/consts";
import * as moment from "moment";

export function getRowColor(tags) {
const type = tags?.severity || tags?.level;
if (type) {
const level = Object.keys(tLevel).find((level) =>
tLevel[level].includes(type.toLowerCase())
);
return lColors[level];
} else {
return lColors["unknown"];
}
}

export function toggleActiveStyles(idx) {
return idx.showLabels
? "value-tags-container labelsActive"
: "value-tags-container labelsInactive";
}

export function formatDate(timestamp) {
return moment(parseInt(timestamp)).format("YYYY-MM-DD HH:mm:ss.SSS UTC");
}
4 changes: 4 additions & 0 deletions src/components/LabelBrowser/QueryBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ export const QueryBar = () => {
const labels = useSelector(store => store.labels)
const queryHistory = useSelector((store) => store.queryHistory);
const saveUrl = localUrl();
// const loading = useSelector( store => store.loading)
useEffect(() => {
const dLog = debugLog(query);
debug && dLog.logicQueryBar();
const labels = sendLabels(apiUrl)

if (isEmbed) dispatch(loadLogs())
if (query.length > 0) {
debug && dLog.queryBarDispatch();
Expand Down Expand Up @@ -144,6 +146,7 @@ export const QueryBar = () => {
<ShowLogsButton
disabled={!queryValid}
onClick={onSubmit}

isMobile={true}
/>
</MobileTopQueryMenu>
Expand All @@ -165,6 +168,7 @@ export const QueryBar = () => {
/>
<ShowLogsButton
disabled={!queryValid}

onClick={onSubmit}
isMobile={false}
/>
Expand Down
Loading

0 comments on commit 0e80cbc

Please sign in to comment.